PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/org-contrib/gsoc2012/student-projects/org-sync/tutorial/index.org

https://gitlab.com/yuvallanger/worg-mirror-unofficial
Org | 219 lines | 154 code | 65 blank | 0 comment | 8 complexity | 976e3ddc86ccc92a5a7f1e2afcfbc9b3 MD5 | raw file
  1. #+OPTIONS: H:3 num:nil toc:2 \n:nil ::t |:t ^:{} -:t f:t *:t tex:t d:(HIDE) tags:not-in-toc
  2. #+STARTUP: align fold nodlcheck hidestars oddeven lognotestate hideblocks
  3. #+SEQ_TODO: TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
  4. #+TAGS: Write(w) Update(u) Fix(f) Check(c) noexport(n)
  5. #+TITLE: Org-sync tutorial
  6. #+AUTHOR: Aurélien Aptel
  7. #+EMAIL: aurelien.aptel@gmail.com
  8. #+LANGUAGE: en
  9. #+HTML_HEAD: <style type="text/css">#outline-container-introduction{ clear:both; }</style>
  10. #+LINK_UP: ../index.html
  11. #+LINK_HOME: http://orgmode.org/worg/
  12. #+EXCLUDE_TAGS: noexport
  13. /An Org-sync tutorial/
  14. * Introduction
  15. Org-sync is a tool to synchronize online bugtrackers with org
  16. documents.
  17. * Installation
  18. ** Check out Org-sync
  19. Make sure to checkout the same revision this tutorial was written with.
  20. #+begin_src sh
  21. git clone git://orgmode.org/org-sync.git
  22. git checkout 8222ec31f
  23. #+end_src
  24. ** Org-element
  25. Org-sync uses Nicolas Goaziou's new parser, org-element. It's in the
  26. contrib directory of Org-mode which is not included in vanilla Emacs.
  27. If you don't have it you can download a recent version from the
  28. Org-mode repo and move it to your Org-sync directory.
  29. #+begin_src sh
  30. wget -O org-element.el 'http://orgmode.org/w/?p=org-mode.git;a=blob_plain;f=contrib/lisp/org-element.el;hb=5057ae0fc2c0d551a83d3c3e9bd621b751db9f09'
  31. #+end_src
  32. ** Loading
  33. Add Org-sync directory to your load-path and load the backend you
  34. want.
  35. #+begin_src emacs-lisp
  36. (add-to-list 'load-path "path/to/org-sync")
  37. (mapc 'load
  38. '("org-element" "os" "os-bb" "os-github" "os-rmine"))
  39. #+end_src
  40. Phew! Still there? Good because it's starting to get interesting...
  41. * Tutorial
  42. There is a [[https://www.youtube.com/watch?v=kbj6-j0teCY][demo video on youtube]] that covers the Bitbucket backend and
  43. conflicts handling. Check it out.
  44. In this tutorial we will sync some bugs from [[http://github.com/ostesting/test][this github repo]].
  45. There are 3 interactive command in Org-sync:
  46. - =os-import= to import a document in the current buffer at point.
  47. - =os-sync= to sync all the imported documents in the buffer.
  48. - =os= which does both depending on the buffer content. It calls
  49. =os-import= if there is nothing to sync in the buffer, =os-sync=
  50. otherwise.
  51. Open a new buffer, switch to org-mode (=M-x org-mode=).
  52. To import a document in a new buffer you can just run =M-x os=. It
  53. prompts you for an URL.
  54. [[file:import.png]]
  55. Org-sync should import the issues from the repo.
  56. [[file:import-ok.png]]
  57. Now, let's try to change an issue. First you have to set a
  58. user/password to be able to modify the issue remotely.
  59. Set the variable =os-github-auth= to like so:
  60. =(setq os-github-auth (cons "ostesting" "thisisostesting42"))=.
  61. Here I have just typed it in my org-buffer, put the cursor after the
  62. last closing paren and hit =C-x C-e=.
  63. [[file:auth-setup.png]]
  64. I've made some change in the first issue. Let's sync with =M-x os=.
  65. [[file:first-sync.png]]
  66. Once it's done you should see a message indicating it.
  67. [[file:sync-ok.png]]
  68. You can check on github to make sure it worked:
  69. [[file:on-github.png]]
  70. Now, let's try to add a new issue. Insert something like =** OPEN my
  71. test issue=. You can type a description under it if you want.
  72. [[file:try-new.png]]
  73. The next step is simple, just run =M-x os=. It will sync all issues
  74. in the buffer. If you don't see the new issue, it was probably added
  75. at the bottom of the list, just scroll down you buffer.
  76. [[file:new-ok.png]]
  77. * How to write a new backend
  78. Writing a new backend is easy. If something is not clear, try to read
  79. the header in =os.el= or one of the existing backend.
  80. #+begin_src emacs-lisp
  81. ;; backend symbol/name: demo
  82. ;; the symbol is used to find and call your backend functions (for now)
  83. ;; what kind of urls does you backend handle?
  84. ;; add it to os-backend-alist in os.el:
  85. (defvar os-backend-alist
  86. '(("github.com/\\(?:repos/\\)?[^/]+/[^/]+" . os-github-backend)
  87. ("bitbucket.org/[^/]+/[^/]+" . os-bb-backend)
  88. ("demo.com" . os-demo-backend)))
  89. ;; if you have already loaded os.el, you'll have to add it
  90. ;; manually in that case just eval this in *scratch*
  91. (add-to-list 'os-backend-alist (cons "demo.com" 'os-demo-backend))
  92. ;; now, in its own file os-demo.el:
  93. (require 'org-sync)
  94. ;; this is the variable used in os-backend-alist
  95. (defvar os-demo-backend
  96. '((base-url . os-demo-base-url)
  97. (fetch-buglist . os-demo-fetch-buglist)
  98. (send-buglist . os-demo-send-buglist))
  99. "Demo backend.")
  100. ;; this overrides os--base-url.
  101. ;; the argument is the url the user gave.
  102. ;; it must return a cannonical version of the url that will be
  103. ;; available to your backend function in the os-base-url variable.
  104. ;; In the github backend, it returns API base url
  105. ;; ie. https://api.github/reposa/<user>/<repo>
  106. (defun os-demo-base-url (url)
  107. "Return proper URL."
  108. "http://api.demo.com/foo")
  109. ;; this overrides os--fetch-buglist
  110. ;; you can use the variable os-base-url
  111. (defun os-demo-fetch-buglist (last-update)
  112. "Fetch buglist from demo.com (anything that happened after LAST-UPDATE)"
  113. ;; a buglist is just a plist
  114. `(:title "Stuff at demo.com"
  115. :url ,os-base-url
  116. ;; add a :since property set to last-update if you return
  117. ;; only the bugs updated since it. omit it or set it to
  118. ;; nil if you ignore last-update and fetch all the bugs of
  119. ;; the repo.
  120. ;; bugs contains a list of bugs
  121. ;; a bug is a plist too
  122. :bugs ((:id 1 :title "Foo" :status open :desc "bar."))))
  123. ;; this overrides os--send-buglist
  124. (defun os-demo-send-buglist (buglist)
  125. "Send BUGLIST to demo.com and return updated buglist"
  126. ;; here you should loop over :bugs in buglist
  127. (dolist (b (os-get-prop :bugs buglist))
  128. (cond
  129. ;; new bug (no id)
  130. ((null (os-get-prop :id b)
  131. '(do-stuff)))
  132. ;; delete bug
  133. ((os-get-prop :delete b)
  134. '(do-stuff))
  135. ;; else, modified bug
  136. (t
  137. '(do-stuff))))
  138. ;; return any bug that has changed (modification date, new bugs,
  139. ;; etc). they will overwrite/be added in the buglist in os.el
  140. ;; we return the same thing for the demo.
  141. ;; :bugs is the only property used from this function in os.el
  142. `(:bugs ((:id 1 :title "Foo" :status open :desc "bar."))))
  143. #+end_src
  144. That's it. A bug has to have at least an id, title and status
  145. properties. Other recognized but optionnal properties are
  146. =:date-deadline=, =:date-creation=, =:date-modification=, =:desc=.
  147. Any other properties are automatically added in the =PROPERTIES= block
  148. of the bug via =prin1-to-string= and are =read= back by org-sync. All
  149. the dates are regular emacs time object. For more details you can
  150. look at the github backend in =os-github.el=.
  151. * More information
  152. You can find more in the =os.el= commentary headers.
  153. There is also [[https://www.youtube.com/watch?v=kbj6-j0teCY][demo video on youtube]] that covers the Bitbucket backend
  154. and conflicts handling. Check it out.