-
Notifications
You must be signed in to change notification settings - Fork 30
/
helm-gitlab.el
189 lines (141 loc) · 5.73 KB
/
helm-gitlab.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
;;; helm-gitlab.el --- Helm interface to Gitlab
;; Author: Nicolas Lamirault <[email protected]>
;; URL: https://github.com/nlamirault/emacs-gitlab
;; Version: 0.1.0
;; Keywords: gitlab, helm
;; Package-Requires: ((s "1.9.0") (dash "2.9.0") (helm "1.0") (gitlab "0.8.0"))
;; Copyright (C) 2014, 2015, 2016 Nicolas Lamirault <[email protected]>
;; 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
;; 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.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
;; 02110-1301, USA.
;;; Commentary:
;; Provides a Helm interface to Gitlab
;;; Code:
(require 'browse-url)
(require 'dash)
(require 'helm)
(require 'helm-buffers)
(require 's)
;; Customization
(defgroup helm-gitlab nil
"Helm interface for Emacs."
:group 'gitlab
:link '(url-link :tag "Github" "https://github.com/nlamirault/emacs-gitlab")
:link '(emacs-commentary-link :tag "Commentary" "emacs-gitlab"))
;; Gitlab library
(require 'gitlab-api)
(require 'gitlab-session)
(require 'gitlab-projects)
(require 'gitlab-issues)
(require 'gitlab-ui)
;; UI
;; ----
(defface helm-gitlab--title
'((((class color) (background light)) :foreground "red" :weight semi-bold)
(((class color) (background dark)) :foreground "green" :weight semi-bold))
"Face of Gitlab information"
:group 'helm-gitlab)
;; Core
;; ------
(defun helm-gitlab--project-issues-init (project-id)
(with-gitlab-auth
(let ((issues (gitlab-list-project-issues project-id)))
(mapcar (lambda (i)
(cons (format "[%s] %s [%s]"
(assoc-default 'id i)
(propertize (assoc-default 'title i)
'face
'helm-gitlab--title)
(assoc-default 'state i))
(list :project-id (assoc-default 'project_id i)
:issue-id (assoc-default 'id i)
:name (assoc-default 'title i))))
issues))))
(defvar helm-gitlab--project-issues-source
'((name . "Gitlab project issues")
(candidates . helm-gitlab--project-issues-init)
(action . (("Browse Link" . helm-gitlab--issue-browse-link)
("Show issue" . helm-gitlab--issue-show)))))
(defun helm-gitlab--projects-init ()
(with-gitlab-auth
(let ((projects (gitlab-list-all-projects)))
(mapcar (lambda (p)
(cons (format "%s" (propertize (assoc-default 'name p)
'face
'helm-gitlab--title))
(list :page (assoc-default 'web_url p)
:name (assoc-default 'name p)
:project-id (assoc-default 'id p))))
projects))))
(defun helm-gitlab--project-browse-page (cast)
(browse-url (plist-get cast :page)))
(defvar helm-gitlab--projects-source
'((name . "Gitlab projects")
(candidates . helm-gitlab--projects-init)
(action . (("Browse project page" . helm-gitlab--project-browse-page)
("Issues" . helm-gitlab--project-issues)
("Members" . helm-gitlab--project-members)
))
(candidate-number-limit . 9999)))
(defun helm-gitlab--issue-show (issue)
(let ((buf (get-buffer-create helm-gitlab--buffer-name)))
(switch-to-buffer buf)
(let ((inhibit-read-only t))
(erase-buffer)
(save-excursion
(gitlab-mode)
issue))))
(defun helm-gitlab--issues-init ()
(with-gitlab-auth
(let ((issues (gitlab-list-all-issues)))
(mapcar (lambda (i)
(cons (format "[%s] %s [%s]"
(assoc-default 'id i)
(propertize (assoc-default 'title i)
'face
'helm-gitlab--title)
(assoc-default 'state i))
(list :project-id (assoc-default 'project_id i)
:issue-id (assoc-default 'id i)
:name (assoc-default 'title i))))
issues))))
(defun helm-gitlab--issue-browse-link (cand)
(browse-url
(gitlab-projects--get-issue-link (plist-get cand :project-id)
(plist-get cand :issue-id))))
(defvar helm-gitlab--issues-source
'((name . "Gitlab issues")
(candidates . helm-gitlab--issues-init)
(action . (("Browse Link" . helm-gitlab--issue-browse-link)
("Show issue" . helm-gitlab--issue-show)))))
;; API
;;;###autoload
(defun helm-gitlab-projects ()
"List Gitlab projects using Helm interface."
(interactive)
(helm :sources '(helm-gitlab--projects-source)
:buffer helm-gitlab--buffer-name))
;;;###autoload
(defun helm-gitlab-project-issues ()
"List Gitlab projects using Helm interface."
(interactive "P")
(helm :sources helm-gitlab--project-issues-source
:prompt "Project : "
:buffer helm-gitlab--buffer-name))
;;;###autoload
(defun helm-gitlab-issues ()
"List Gitlab issues using Helm interface."
(interactive)
(helm :sources '(helm-gitlab--issues-source)
:buffer helm-gitlab--buffer-name))
(provide 'helm-gitlab)
;;; helm-gitlab.el ends here