...
 
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
......@@ -12,27 +12,26 @@
;; Keywords: org-mode gitlab todos
;; URL: https://gitlab.com/to1ne/org-gitlab
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; 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
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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 +70,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 +130,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 +169,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 +191,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 +199,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 +280,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
)
......