...
 
Commits (8)
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
......@@ -290,8 +290,8 @@ to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
org-gitlab
Copyright (C) 2017 Toon Claes
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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
......@@ -329,7 +329,7 @@ necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
{signature of Ty Coon}, 1 April 1989
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
......
......@@ -5,11 +5,11 @@
;; Author: Toon Claes <toon@iotcl.com>
;; Maintainer: Toon Claes <toon@iotcl.com>
;; Created: 13 Feb 2017
;; Modified: 23 Apr 2017
;; Modified: 26 May 2018
;; Version: 0.1
;; Package-Version: 20170423.0809
;; Package-Version: 20180526.1029
;; Package-Requires: ((async "1.9") (request "0.3") (org "9.0"))
;; Keywords: org-mode gitlab todos
;; Keywords: org-mode gitlab todos issues merge-requests
;; URL: https://gitlab.com/to1ne/org-gitlab
;; This program is free software; you can redistribute it and/or
......@@ -95,12 +95,6 @@ saved in customize."
(or org-gitlab-token
(getenv "GITLAB_TOKEN")))
(defun org-gitlab--user-id ()
"Return the user id from customize or get it from the API."
(when (eq org-gitlab-user-id 'unspecified)
(error "Getting the user id from API is not yet implemented"))
org-gitlab-user-id)
(defun gitlab--get-headers ()
"Return the HTTP headers for Gitlab API."
;;(if (not (s-blank? gitlab-token-id))
......@@ -109,7 +103,9 @@ saved in customize."
(defun org-gitlab--compose-uri (path)
"Compose the full URL for the endpoint at PATH."
(concat org-gitlab-server "/api/v4" path))
(mapconcat (lambda (x)
(file-name-as-directory (subst-char-in-string ?- ?_ x)))
`(,org-gitlab-server "api/v4" ,path) nil))
(defun org-gitlab--get-request (path &optional params)
"Send a request to the GitLab server.
......@@ -123,16 +119,16 @@ saved in customize."
:parser (lambda ()
(let ((json-array-type 'list))
(json-read))))))
;; TODO error handling
;; TODO error handling --> widen narrowing
(request-response-data response)))
(defun org-gitlab--get-issues (params)
"Fetch all Issues from api using PARAMS."
(org-gitlab--get-request "/issues" params))
(defun org-gitlab--get-merge-requests (params)
"Fetch all Merge Requests from api using PARAMS."
(org-gitlab--get-request "/merge_requests" params))
(defun org-gitlab--get-issuables (class params)
"Fetch all issuables of type CLASS from api using PARAMS."
(org-gitlab--get-request class params))
(defun org-gitlab--params-at-point ()
"Get the query parameters for the heading at point."
......@@ -153,63 +149,60 @@ saved in customize."
(error "No query parameters found"))
params))
(defun org-gitlab--sync-issues (&optional params)
"Synchronize issues on GitLab server to sub headings.
(defun org-gitlab--singularize-class (class)
"Returns the singular form of CLASS."
(cond ((equal "issues" class) "issue")
((equal "merge-requests" class) "merge-request")))
Optionally specify PARAMS to filter."
(save-excursion
(let* ((params (org-gitlab--params-at-point))
(issues (org-gitlab--get-issues params))
(heading-pos (point))
issue pos attr)
(dolist (issue issues)
(setq attr (number-to-string (cdr (assoc 'id issue))))
(if (setq pos (org-find-property "id" attr))
(goto-char pos)
(goto-char heading-pos)
(org-insert-heading-respect-content)
(org-do-demote)
(org-set-property "id" attr))
(org-edit-headline (cdr (assoc 'title 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--try-set-property (property issuable &optional key)
"Set the org property KEY from ISSUABLE, 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)
"It formats the issuable iid from the `web_url'."
"It formats the iid from the ISSUABLE `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.
(defun org-gitlab--sync-issuables (class &optional params)
"Synchronize issuables from GitLab server to sub headings.
Optionally specify PARAMS to filter."
Specify the CLASS of the issuables and optionally specify PARAMS
to filter."
(save-excursion
(let* ((params (org-gitlab--params-at-point))
(merge-requests (org-gitlab--get-merge-requests params))
(unless params
(setq params (org-gitlab--params-at-point)))
(let* ((issuables (org-gitlab--get-issuables class params))
(heading-pos (point))
merge-request attr)
(dolist (merge-request merge-requests)
(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)
(org-do-demote)
(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" (org-gitlab--format-iid merge-request))
(if (setq attr (cdr (assoc 'assignee merge-request)))
(org-set-property "assignee" (cdr (assoc 'username attr))))))))
pos)
(dolist (issuable issuables)
(let ((attr (number-to-string (cdr (assoc 'id issuable)))))
(if (setq pos (org-find-property "id" attr))
(goto-char pos)
(goto-char heading-pos)
(org-insert-heading-respect-content)
(org-do-demote)
(org-set-property "org-gitlab" (org-gitlab--singularize-class class))
(org-set-property "id" attr))
(org-edit-headline (cdr (assoc 'title issuable)))
(org-gitlab--try-set-property "branch" issuable 'source_branch)
(org-set-property "iid" (org-gitlab--format-iid issuable))
(org-gitlab--try-set-property "assignee" issuable))))))
;;;###autoload
(defun org-gitlab-sync-at-point ()
"Synchronize the heading at point.
It has the contain the `org-gitlab' property. This property can have
It has to contain the `org-gitlab' property. This property can have
the value: `issues', `merge-requests', or `todos'.
For the values `issues' and `merge requests', the heading must also
contain one of the following properties: `author' or `assignee'."
......@@ -217,11 +210,9 @@ contain one of the following properties: `author' or `assignee'."
(save-excursion
(org-narrow-to-subtree)
(let ((params (org-gitlab--params-at-point))
(scope (org-entry-get (point) "org-gitlab")))
(cond ((equal "issues" scope)
(org-gitlab--sync-issues params)))
(cond ((equal "merge-requests" scope)
(org-gitlab--sync-merge-requests params))))
(class (org-entry-get (point) "org-gitlab")))
(if (or (equal "issues" class) (equal "merge-requests" class))
(org-gitlab--sync-issuables class params)))
(widen)))
;;;###autoload
......