-
Notifications
You must be signed in to change notification settings - Fork 30
/
ivy-gitlab.el
184 lines (145 loc) · 6.16 KB
/
ivy-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
;;; ivy-gitlab.el --- Ivy interface to Gitlab
;; Author: Nicolas Lamirault <[email protected]>
;; URL: https://github.com/nlamirault/emacs-gitlab
;; Version: 0.1.0
;; Keywords: gitlab, ivy
;; Package-Requires: ((s "1.9.0") (dash "2.9.0") (ivy "0.8.0") (gitlab "0.8"))
;; 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 an Ivy interface to Gitlab
;;; Code:
(require 'browse-url)
(require 'dash)
(require 'ivy)
(require 's)
;; Customization
(defgroup ivy-gitlab nil
"Ivy interface for Emacs."
:group 'gitlab
:link '(url-link :tag "Github" "https://github.com/nlamirault/emacs-gitlab")
:link '(emacs-commentary-link :tag "Commentary" "emacs-gitlab"))
(defface ivy-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 'ivy-gitlab)
;; Gitlab library
(require 'gitlab-api)
(require 'gitlab-session)
(require 'gitlab-projects)
(require 'gitlab-issues)
(require 'gitlab-ui)
;; Core
(defun ivy-gitlab--list-projects ()
(with-gitlab-auth
(let ((projects (gitlab-list-all-projects))
(gitlab-projects-alist nil))
(mapc (lambda (p)
(add-to-list
'gitlab-projects-alist
(cons (format "%s" (propertize (assoc-default 'name_with_namespace p)
'face
'ivy-gitlab--title))
(list :page (assoc-default 'web_url p)
:name (assoc-default 'name p)
:project-id (assoc-default 'id p)))))
projects)
gitlab-projects-alist)))
(defun ivy-gitlab--list-project-issues (project-id)
(with-gitlab-auth
(let ((issues (gitlab-list-project-issues project-id))
(gitlab-project-issues-alist nil))
(mapc (lambda (i)
(add-to-list
'gitlab-project-issues-alist
(cons (format "#%-4s %s :%s:"
(assoc-default 'iid i)
(propertize (decode-coding-string (assoc-default 'title i) 'utf-8)
'face
'ivy-gitlab--title)
(assoc-default 'state i))
(list :project-id (assoc-default 'project_id i)
:issue-id (assoc-default 'iid i)
:name (decode-coding-string (assoc-default 'title i) 'utf-8)))))
issues)
gitlab-project-issues-alist)))
(defun ivy-gitlab--project-names ()
(with-gitlab-auth
(let ((projects (gitlab-list-all-projects))
(gitlab-project-names-alist nil))
(mapc (lambda (p)
(add-to-list
'gitlab-project-names-alist
(cons (assoc-default 'id p) (assoc-default 'name_with_namespace p))))
projects)
gitlab-project-names-alist)))
(defun ivy-gitlab--list-all-issues ()
(with-gitlab-auth
(let ((issues (gitlab-list-all-issues))
(gitlab-all-issues-alist nil)
(project-names (ivy-gitlab--project-names)))
(mapc (lambda (i)
(add-to-list
'gitlab-all-issues-alist
(cons (format "#%-4s %s :%s: -- %s"
(assoc-default 'iid i)
(propertize (decode-coding-string (assoc-default 'title i) 'utf-8)
'face
'ivy-gitlab--title)
(assoc-default 'state i)
(assoc-default (assoc-default 'project_id i) project-names))
(list :project-id (assoc-default 'project_id i)
:issue-id (assoc-default 'iid i)
:name (decode-coding-string (assoc-default 'title i) 'utf-8)))))
issues)
gitlab-all-issues-alist)))
(defun ivy-gitlab--list-projects-action-default (project)
(browse-url (plist-get (cdr project) :page)))
(defun ivy-gitlab--list-issues-action-default (issue)
(browse-url
(gitlab-projects--get-issue-link
(plist-get (cdr issue) :project-id) (plist-get (cdr issue) :issue-id))))
(defun ivy-gitlab--list-project-issues-action-default (project)
(ivy-read "Issues: "
(ivy-gitlab--list-project-issues (plist-get (cdr project) :project-id))
:action #'ivy-gitlab--list-issues-action-default
:caller 'ivy-gitlab--list-project-issues-action-default))
;; API
;;;###autoload
(defun ivy-gitlab-list-projects ()
"List Gitlab projects using Ivy."
(interactive)
(ivy-read "Projects: "
(ivy-gitlab--list-projects)
:action #'ivy-gitlab--list-projects-action-default
:caller 'ivy-gitlab-list-projects))
;;;###autoload
(defun ivy-gitlab-list-project-issues ()
"List Gitlab project issues using Ivy."
(interactive)
(ivy-read "Projects: "
(ivy-gitlab--list-projects)
:action #'ivy-gitlab--list-project-issues-action-default
:caller 'ivy-gitlab-list-project-issues))
;;;###autoload
(defun ivy-gitlab-list-all-issues ()
"List Gitlab all issues using Ivy."
(interactive)
(ivy-read "Issues: "
(ivy-gitlab--list-all-issues)
:action #'ivy-gitlab--list-issues-action-default
:caller 'ivy-gitlab--list-all-issues-action-default))
(provide 'ivy-gitlab)
;;; ivy-gitlab.el ends here