Last active
May 2, 2024 08:08
-
-
Save viiru-/e9085b2f1f872a67c5fba307c633f1d4 to your computer and use it in GitHub Desktop.
Create Org mode todo items from Gitlab issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun forge-org-issue-create-or-sync (issue) | |
(save-window-excursion | |
(let* ((id (cdr (assoc 'id issue))) | |
(location (org-id-find id))) | |
(if location (org-id-goto id) | |
(forge-org-issue-create issue)) | |
(forge-org-issue-sync-props issue)))) | |
(defun forge-org-issue-sync-props (issue) | |
(let* ((labels (mapcar (lambda (val) (split-string val "::")) (cdr (assoc 'labels test-issue)))) | |
(stage (car (last (assoc-string 'stage labels t)))) | |
(priority (car (last (assoc-string 'priority labels t))))) | |
(org-set-property "author" (cdr (assoc 'name (assoc 'author issue)))) | |
(org-set-property "link" (cdr (assoc 'web_url issue))) | |
(when stage (org-set-property "stage" stage)) | |
(when priority (org-set-property "priority" priority)))) | |
(defun forge-org-issue-create (issue) | |
(org-capture nil "w") | |
(insert (format "%s | |
:PROPERTIES: | |
:id: %d | |
:END: | |
%s | |
" | |
(cdr (assoc 'title issue)) | |
(cdr (assoc 'id issue)) | |
(subst-char-in-string "*" "-" (cdr (assoc 'description issue))))) | |
(org-capture-finalize t)) | |
;;;###autoload | |
(defun viiru/sync-glab-issues() | |
(interactive) | |
(let ((repo (make-instance 'forge-gitlab-repository))) | |
(mapcar | |
'forge-org-issue-create-or-sync | |
(forge--glab-get repo "/issues" | |
(cons (cons 'assignee_username viiru/glab-sync-username) '((state . "opened") (scope . "all"))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment