Commit ffbebbe1 authored by to1ne's avatar to1ne

Syncing Todos is working now

parent 9a5b7f2b
Pipeline #57490301 passed with stage
in 30 seconds
......@@ -5,9 +5,9 @@
;; Author: Toon Claes <>
;; Maintainer: Toon Claes <>
;; Created: 13 Feb 2017
;; Modified: 28 Mar 2019
;; Modified: 18 Apr 2019
;; Version: 0.2
;; Package-Version: 20190328.2137
;; Package-Version: 20190418.2141
;; Package-Requires: ((async "1.9") (request "0.3") (org "9.0"))
;; Keywords: org-mode gitlab todos issues merge-requests
;; URL:
......@@ -150,28 +150,31 @@ saved in customize."
(defun org-gitlab--singularize-class (class)
"Returns the singular form of CLASS."
"Return the singular form of CLASS."
(cond ((equal "issues" class) "issue")
((equal "merge-requests" class) "merge-request")))
(defun org-gitlab--try-set-property (property issuable &optional key)
"Set the org property KEY from ISSUABLE, if KEY exists.
"Read KEY from ISSUABLE and store it in PROPERTY, if KEY exists.
KEY should be a string."
(let ((key (or key (make-symbol property)))
(attr (assoc key issuable)))
(when attr
(if (listp attr)
(setq attr (cdr attr)))
(org-set-property property attr))))
(defun org-gitlab--format-iid (issuable &optional key)
"It formats the iid from the ISSUABLE `web_url'."
(let* ((web-url (cdr (assoc (or key 'web_url) issuable)))
(val (alist-get key issuable)))
(if val (org-set-property property val))))
(defun org-gitlab--format-ref (issuable &optional key)
"Format the ISSUABLE to a reference using KEY or `web_url'."
(let* ((web-url (alist-get (or key 'web_url) issuable))
(web-filename (substring (url-filename (url-generic-parse-url web-url)) 1))
(iid (replace-regexp-in-string "/merge_requests/" "!"
(ref (replace-regexp-in-string "/merge_requests/" "!"
(replace-regexp-in-string "/issues/" "#" web-filename))))
(org-make-link-string web-url iid)))
(org-make-link-string web-url ref)))
(defun org-gitlab--format-user (user)
"Format a USER to a clickable username."
(let ((web-url (alist-get 'web_url user))
(username (concat "@" (alist-get 'username user))))
(org-make-link-string web-url username)))
(defun org-gitlab--sync-issuables (class &optional params)
"Synchronize issuables from GitLab server to sub headings.
......@@ -185,7 +188,7 @@ to filter."
(heading-pos (point))
(dolist (issuable issuables)
(let ((attr (number-to-string (cdr (assoc 'id issuable)))))
(let ((attr (number-to-string (alist-get 'id issuable))))
(if (setq pos (org-find-property "id" attr))
(goto-char pos)
(goto-char heading-pos)
......@@ -193,28 +196,31 @@ to filter."
(org-set-property "org-gitlab" (org-gitlab--singularize-class class))
(org-set-property "id" attr))
(org-edit-headline (cdr (assoc 'title issuable)))
(org-edit-headline (alist-get 'title issuable))
(org-todo "TODO")
(org-gitlab--try-set-property "branch" issuable 'source_branch)
(org-set-property "iid" (org-gitlab--format-iid issuable))
(org-set-property "ref" (org-gitlab--format-ref issuable))
(org-gitlab--try-set-property "assignee" issuable))))))
(defun org-gitlab--titlize-todo (todo)
"Generate title for TODO."
(let* ((action (cdr (assoc 'action_name todo)))
(iid (org-gitlab--format-iid todo 'target_url))
(author (assoc 'author todo)))
(let* ((action (alist-get 'action_name todo))
(ref (org-gitlab--format-ref todo 'target_url))
(author (alist-get 'author todo)))
(if author
(concat "@" (cdr (assoc 'username author))
(concat (org-gitlab--format-user author)
(cond ((equal "assigned" action) " assigned ")
((equal "mentioned" action) " mentioned you on ")
((equal "marked" action) " added a todo for ")
((equal "approval_required" action) " asked your approval for ")
((equal "directly_addressed" action) " directly addressed you on "))
((equal "directly_addressed" action) " directly addressed you on ")
((equal "build_failed" action) "'s build failed for ")
(t (concat " " action " ")))
(concat (cond ((equal "build_failed" action) "The build failed for ")
((equal "unmergeable" action) "Merge is not possible on "))
((equal "unmergeable" action) "Merge is not possible on ")
(t (concat action " on ")))
(defun org-gitlab--sync-todos (&optional params)
"Synchronize your Todos from GitLab server to sub headings.
......@@ -226,18 +232,24 @@ Optionally specify PARAMS to filter."
(heading-pos (point))
(dolist (todo todos)
(let ((attr (number-to-string (cdr (assoc 'id todo)))))
(let ((attr (number-to-string (alist-get 'id todo))))
(if (setq pos (org-find-property "id" attr))
(goto-char pos)
(goto-char heading-pos)
(org-set-property "org-gitlab" "todo")
(org-set-property "id" attr))
(org-edit-headline (org-gitlab--titlize-todo todo))
(org-set-property "action" (cdr (assoc 'action_name todo)))
;; TODO more
(org-set-property "id" attr)
(org-set-property "title" (alist-get 'title (alist-get 'target todo)))
(org-edit-headline (org-gitlab--titlize-todo todo))
(org-set-property "action" (alist-get 'action_name todo))
;; TODO more properties?
(goto-char (cdr (org-get-property-block)))
(insert (alist-get 'body todo))
(org-todo "TODO"))))))
(defun org-gitlab--untodo-tree ()
"Remove TODO from all headings in tree."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment