...
 
Commits (3)
This diff is collapsed.
;;; org-gitlab.el --- Your GitLab Todos in org-mode ;;; org-gitlab.el --- Your GitLab Todos in org-mode -*- lexical-binding: t; -*-
;; Copyright (C) 2017 Toon Claes ;; Copyright (C) 2017 Toon Claes
...@@ -12,27 +12,26 @@ ...@@ -12,27 +12,26 @@
;; Keywords: org-mode gitlab todos ;; Keywords: org-mode gitlab todos
;; URL: https://gitlab.com/to1ne/org-gitlab ;; URL: https://gitlab.com/to1ne/org-gitlab
;; This program is free software; you can redistribute it and/or ;; This program is free software: you can redistribute it and/or modify
;; modify it under the terms of the GNU General Public License as ;; it under the terms of the GNU General Public License as published by
;; published by the Free Software Foundation; either version 2, or (at ;; the Free Software Foundation, either version 3 of the License, or
;; your option) any later version. ;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful, but ;; This program is distributed in the hope that it will be useful,
;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; General Public License for more details. ;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License ;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary: ;;; Commentary:
;; This `org-gitlab' synchronizes your GitLab Todos, issues, and merge ;; This `org-gitlab' minor synchronizes your GitLab Todos, issues, and
;; requests to a local org-mode file. It runs in the background and ;; merge requests to a local org-mode file. It runs in the background
;; refreshes existing headlines and properties. The synchronization ;; and refreshes existing headlines and properties. The
;; is one-way and only syncs from GitLab to a local file. ;; synchronization is one-way and only syncs from GitLab to a local
;; file.
;; ;;
;; To synchronize a heading with GitLab, you should specify some ;; To synchronize a heading with GitLab, you should specify some
;; properties. The heading should look something like: ;; properties. The heading should look something like:
...@@ -71,7 +70,7 @@ By default gitlab.com is used." ...@@ -71,7 +70,7 @@ By default gitlab.com is used."
:group 'org-gitlab :group 'org-gitlab
:type 'string) :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." "Lighter shown in the modeline when `org-gitlab-mode' is active."
:group 'org-gitlab :group 'org-gitlab
:type 'string) :type 'string)
...@@ -131,19 +130,19 @@ saved in customize." ...@@ -131,19 +130,19 @@ saved in customize."
(defun org-gitlab--get-merge-requests (params) (defun org-gitlab--get-merge-requests (params)
"Fetch all Merge Requests from api using 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 () (defun org-gitlab--params-at-point ()
"Get the query parameters for the heading at point." "Get the query parameters for the heading at point."
(let ((author (org-entry-get (point) "author")) (let ((author (org-entry-get (point) "author"))
(assignee (org-entry-get (point) "assignee")) (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")) (state (org-entry-get (point) "state"))
(params '())) (params '()))
(if author (if author
(setq params (append params (list (cons "author_username" author))))) (setq params (append params (list (cons "author_id" author)))))
(if assignee (if assignee
(setq params (append params (list (cons "assignee_username" assignee))))) (setq params (append params (list (cons "assignee_id" assignee)))))
(if state (if state
(setq params (append params (list (cons "state" state))))) (setq params (append params (list (cons "state" state)))))
(if scope (if scope
...@@ -170,10 +169,18 @@ Optionally specify PARAMS to filter." ...@@ -170,10 +169,18 @@ Optionally specify PARAMS to filter."
(org-do-demote) (org-do-demote)
(org-set-property "id" attr)) (org-set-property "id" attr))
(org-edit-headline (cdr (assoc 'title issue))) (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))) (if (setq attr (cdr (assoc 'assignee issue)))
(org-set-property "assignee" (format "@%s" (cdr (assoc 'username attr))))))))) (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) (defun org-gitlab--sync-merge-requests (&optional params)
"Synchronize merge request on GitLab server to sub headings. "Synchronize merge request on GitLab server to sub headings.
...@@ -184,7 +191,7 @@ Optionally specify PARAMS to filter." ...@@ -184,7 +191,7 @@ Optionally specify PARAMS to filter."
(heading-pos (point)) (heading-pos (point))
merge-request attr) merge-request attr)
(dolist (merge-request merge-requests) (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) (unless (org-find-property "id" attr)
(goto-char heading-pos) (goto-char heading-pos)
(org-insert-heading-respect-content) (org-insert-heading-respect-content)
...@@ -192,7 +199,7 @@ Optionally specify PARAMS to filter." ...@@ -192,7 +199,7 @@ Optionally specify PARAMS to filter."
(org-set-property "id" attr)) (org-set-property "id" attr))
(org-edit-headline (cdr (assoc 'title merge-request))) (org-edit-headline (cdr (assoc 'title merge-request)))
(org-set-property "branch" (cdr (assoc 'source_branch 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))) (if (setq attr (cdr (assoc 'assignee merge-request)))
(org-set-property "assignee" (cdr (assoc 'username attr)))))))) (org-set-property "assignee" (cdr (assoc 'username attr))))))))
...@@ -273,7 +280,7 @@ ARG, enable `org-gitlab-mode' if ARG is positive, otherwise disable ...@@ -273,7 +280,7 @@ ARG, enable `org-gitlab-mode' if ARG is positive, otherwise disable
it. it.
\\{org-gitlab-mode-map}" \\{org-gitlab-mode-map}"
:init-value nil :init-value nil
:lighter org-gitlab-mode-ligther :lighter org-gitlab-mode-lighter
:group 'org-gitlab :group 'org-gitlab
:keymap org-gitlab-mode-map :keymap org-gitlab-mode-map
) )
......