Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proposition] code adaptation #9

Merged
merged 10 commits into from
Aug 12, 2015
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ert-runner
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-L .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/TODO.org
.cask
20 changes: 20 additions & 0 deletions Cask
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(source gnu)
(source melpa)

(package-file "org-sync.el")

(files "omd.el"
"org-sync.el"
"org-sync-bb.el"
"org-sync-github.el"
"org-sync-redmine.el"
"org-sync-rtm.el")

(development
(depends-on "dash")
(depends-on "dash-functional")
(depends-on "undercover")
(depends-on "ert-runner")
(depends-on "ert")
(depends-on "ert-expectations")
(depends-on "el-mock"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a Cask file is obviously a big plus!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also permits to make package.
I use it to make the package and send them to marmalade https://marmalade-repo.org/ (another package repository)

36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
MODE_NAME=org-sync
VERSION=$$(grep "^;; Version: " $(MODE_NAME).el | cut -f3 -d' ')
PACKAGE_FOLDER=$(MODE_NAME)-$(VERSION)
ARCHIVE=$(PACKAGE_FOLDER).tar
EMACS=emacs

.PHONY: clean

deps:
cask

build:
cask build

clean-dist:
rm -rf dist/

clean: clean-dist
rm -rf *.tar
cask clean-elc

install:
cask install

test: clean
cask exec ert-runner

pkg-el:
cask package

package: clean pkg-el
cp dist/$(ARCHIVE) .
make clean-dist

info:
cask info
80 changes: 44 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ on Worg. You can find the official git repo and contact informations there.

## Installation

### melpa

```
M-x package-install RET org-sync RET
```

### from source

Put the org-sync directory in your load-path and load the org-sync backend you
need. You can add this to your .emacs:

``` emacs-lisp
(add-to-list 'load-path "path/to/org-sync")
(mapc 'load
'("os" "os-bb" "os-github" "os-rmine"))
'("org-sync" "org-sync-bb" "org-sync-github" "org-sync-rmine"))
```

Make sure you have `org-element.el` (it's part of recent org-mode >=). If you
Expand All @@ -30,75 +38,75 @@ wget -O org-element.el 'http://orgmode.org/w/?p=org-mode.git;a=blob_plain;f=lisp

## Tutorial

Next, open a new org-mode buffer and run `M-x os-import`. It prompts you for
Next, open a new org-mode buffer and run `M-x org-sync-import`. It prompts you for
an URL. You can try my Github test repo: `github.com/arbox/org-sync-test`.
Org-sync should import the issues from the repo. *Note*: This is just
a test repo, do not use it to report actual bugs.

Now, let's try to add a new issue. First you have to set a
user/password to be able to modify the issue remotely.

Set the variable os-github-auth to like so:
`(setq os-github-auth '("ostesting" . "thisisostesting42"))`
Set the variable org-sync-github-auth to like so:
`(setq org-sync-github-auth '("ostesting" . "thisisostesting42"))`

Try to add another issue e.g. insert `** OPEN my test issue`. You can
type a description under it if you want.

The next step is simple, just run `M-x os-sync`. It synchronize all
The next step is simple, just run `M-x org-sync`. It synchronizes all
the buglists in the document.

## How to write a new backend

Writing a new backend is easy. If something is not clear, try to read
the header in `os.el` or one of the existing backend.
the header in `org-sync.el` or one of the existing backend.

``` emacs-lisp
;; backend symbol/name: demo
;; the symbol is used to find and call your backend functions (for now)

;; what kind of urls does you backend handle?
;; add it to os-backend-alist in os.el:
;; add it to org-sync-backend-alist in org-sync.el:

(defvar os-backend-alist
'(("github.com/\\(?:repos/\\)?[^/]+/[^/]+" . os-github-backend)
("bitbucket.org/[^/]+/[^/]+" . os-bb-backend)
("demo.com" . os-demo-backend)))
(defvar org-sync-backend-alist
'(("github.com/\\(?:repos/\\)?[^/]+/[^/]+" . org-sync-github-backend)
("bitbucket.org/[^/]+/[^/]+" . org-sync-bb-backend)
("demo.com" . org-sync-demo-backend)))

;; if you have already loaded os.el, you'll have to add it
;; if you have already loaded org-sync.el, you'll have to add it
;; manually in that case just eval this in *scratch*
(add-to-list 'os-backend-alist (cons "demo.com" 'os-demo-backend))
(add-to-list 'org-sync-backend-alist (cons "demo.com" 'org-sync-demo-backend))

;; now, in its own file os-demo.el:
;; now, in its own file org-sync-demo.el:

(require 'os)
(require 'org-sync)

;; this is the variable used in os-backend-alist
(defvar os-demo-backend
'((base-url . os-demo-base-url)
(fetch-buglist . os-demo-fetch-buglist)
(send-buglist . os-demo-send-buglist))
;; this is the variable used in org-sync-backend-alist
(defvar org-sync-demo-backend
'((base-url . org-sync-demo-base-url)
(fetch-buglist . org-sync-demo-fetch-buglist)
(send-buglist . org-sync-demo-send-buglist))
"Demo backend.")


;; this overrides os--base-url.
;; this overrides org-sync--base-url.
;; the argument is the url the user gave.
;; it must return a cannonical version of the url that will be
;; available to your backend function in the os-base-url variable.
;; available to your backend function in the org-sync-base-url variable.

;; In the github backend, it returns API base url
;; ie. https://api.github/reposa/<user>/<repo>

(defun os-demo-base-url (url)
(defun org-sync-demo-base-url (url)
"Return proper URL."
"http://api.demo.com/foo")

;; this overrides os--fetch-buglist
;; you can use the variable os-base-url
(defun os-demo-fetch-buglist (last-update)
;; this overrides org-sync--fetch-buglist
;; you can use the variable org-sync-base-url
(defun org-sync-demo-fetch-buglist (last-update)
"Fetch buglist from demo.com (anything that happened after LAST-UPDATE)"
;; a buglist is just a plist
`(:title "Stuff at demo.com"
:url ,os-base-url
:url ,org-sync-base-url

;; add a :since property set to last-update if you return
;; only the bugs updated since it. omit it or set it to
Expand All @@ -109,29 +117,29 @@ the header in `os.el` or one of the existing backend.
;; a bug is a plist too
:bugs ((:id 1 :title "Foo" :status open :desc "bar."))))

;; this overrides os--send-buglist
(defun os-demo-send-buglist (buglist)
;; this overrides org-sync--send-buglist
(defun org-sync-demo-send-buglist (buglist)
"Send BUGLIST to demo.com and return updated buglist"
;; here you should loop over :bugs in buglist
(dolist (b (os-get-prop :bugs buglist))
(dolist (b (org-sync-get-prop :bugs buglist))
(cond
;; new bug (no id)
((null (os-get-prop :id b)
((null (org-sync-get-prop :id b)
'(do-stuff)))

;; delete bug
((os-get-prop :delete b)
((org-sync-get-prop :delete b)
'(do-stuff))

;; else, modified bug
(t
'(do-stuff))))

;; return any bug that has changed (modification date, new bugs,
;; etc). they will overwrite/be added in the buglist in os.el
;; etc). they will overwrite/be added in the buglist in org-sync.el

;; we return the same thing for the demo.
;; :bugs is the only property used from this function in os.el
;; :bugs is the only property used from this function in org-sync.el
`(:bugs ((:id 1 :title "Foo" :status open :desc "bar."))))
```

Expand All @@ -140,10 +148,10 @@ Other recognized but optionnal properties are `:date-deadline`,
`:date-creation`, `:date-modification`, `:desc`. Any other properties are
automatically added in the `PROPERTIES` block of the bug via `prin1-to-string`
and are `read` back by org-sync. All the dates are regular emacs time object.
For more details you can look at the github backend in `os-github.el`.
For more details you can look at the github backend in `org-sync-github.el`.

## More information

You can find more in the `os.el` commentary headers.
You can find more in the `org-sync.el` commentary headers.

[badge-license]: https://img.shields.io/badge/license-GPL_3-green.svg
Loading