Commit 7313c42a authored by to1ne's avatar to1ne

Some finalizations since GitLab 9.5-RC2 was deployed to GitLab.com

GitLab 9.5 includes some changes to make the top-level `/issues` and
`/merge-requests` API endpoints work better. So use them.

See gitlab-org/gitlab-ce!13060 &
    gitlab-org/gitlab-ce!13004.
parent c403f229
......@@ -29,10 +29,11 @@
;;; Commentary:
;; This `org-gitlab' synchronizes your GitLab Todos, issues, and merge
;; requests to a local org-mode file. It runs in the background and
;; refreshes existing headlines and properties. The synchronization
;; is one-way and only syncs from GitLab to a local file.
;; This `org-gitlab' minor synchronizes your GitLab Todos, issues, and
;; merge requests to a local org-mode file. It runs in the background
;; and refreshes existing headlines and properties. The
;; synchronization is one-way and only syncs from GitLab to a local
;; file.
;;
;; To synchronize a heading with GitLab, you should specify some
;; properties. The heading should look something like:
......@@ -71,7 +72,7 @@ By default gitlab.com is used."
:group 'org-gitlab
:type 'string)
(defcustom org-gitlab-mode-ligther "org-gl "
(defcustom org-gitlab-mode-lighter "org-gl "
"Lighter shown in the modeline when `org-gitlab-mode' is active."
:group 'org-gitlab
:type 'string)
......@@ -131,19 +132,19 @@ saved in customize."
(defun org-gitlab--get-merge-requests (params)
"Fetch all Merge Requests from api using PARAMS."
(org-gitlab--get-request "/projects/gitlab-org%2Fgitlab-ce/merge_requests" params))
(org-gitlab--get-request "/merge_requests" params))
(defun org-gitlab--params-at-point ()
"Get the query parameters for the heading at point."
(let ((author (org-entry-get (point) "author"))
(assignee (org-entry-get (point) "assignee"))
(scope (org-entry-get (point) "scope")) ;; TODO check if it works, or remove
(scope (org-entry-get (point) "scope"))
(state (org-entry-get (point) "state"))
(params '()))
(if author
(setq params (append params (list (cons "author_username" author)))))
(setq params (append params (list (cons "author_id" author)))))
(if assignee
(setq params (append params (list (cons "assignee_username" assignee)))))
(setq params (append params (list (cons "assignee_id" assignee)))))
(if state
(setq params (append params (list (cons "state" state)))))
(if scope
......@@ -170,10 +171,18 @@ Optionally specify PARAMS to filter."
(org-do-demote)
(org-set-property "id" attr))
(org-edit-headline (cdr (assoc 'title issue)))
(org-set-property "iid" (format "#%d" (cdr (assoc 'iid issue))))
(org-set-property "iid" (org-gitlab--format-iid issue))
(if (setq attr (cdr (assoc 'assignee issue)))
(org-set-property "assignee" (format "@%s" (cdr (assoc 'username attr)))))))))
(defun org-gitlab--format-iid (issuable)
"It formats the issuable iid from the `web_url'."
(let* ((web-url (cdr (assoc 'web_url issuable)))
(web-filename (substring (url-filename (url-generic-parse-url web-url)) 1))
(iid (replace-regexp-in-string "/merge_requests/" "!"
(replace-regexp-in-string "/issues/" "#" web-filename))))
(org-make-link-string web-url iid)))
(defun org-gitlab--sync-merge-requests (&optional params)
"Synchronize merge request on GitLab server to sub headings.
......@@ -184,7 +193,7 @@ Optionally specify PARAMS to filter."
(heading-pos (point))
merge-request attr)
(dolist (merge-request merge-requests)
(setq attr (format "!%d" (cdr (assoc 'id merge-request))))
(setq attr (number-to-string (cdr (assoc 'id merge-request))))
(unless (org-find-property "id" attr)
(goto-char heading-pos)
(org-insert-heading-respect-content)
......@@ -192,7 +201,7 @@ Optionally specify PARAMS to filter."
(org-set-property "id" attr))
(org-edit-headline (cdr (assoc 'title merge-request)))
(org-set-property "branch" (cdr (assoc 'source_branch merge-request)))
(org-set-property "iid" (number-to-string (cdr (assoc 'iid merge-request))))
(org-set-property "iid" (org-gitlab--format-iid merge-request))
(if (setq attr (cdr (assoc 'assignee merge-request)))
(org-set-property "assignee" (cdr (assoc 'username attr))))))))
......@@ -273,7 +282,7 @@ ARG, enable `org-gitlab-mode' if ARG is positive, otherwise disable
it.
\\{org-gitlab-mode-map}"
:init-value nil
:lighter org-gitlab-mode-ligther
:lighter org-gitlab-mode-lighter
:group 'org-gitlab
:keymap org-gitlab-mode-map
)
......
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