-
Notifications
You must be signed in to change notification settings - Fork 30
/
gitlab-issues.el
184 lines (158 loc) · 6.94 KB
/
gitlab-issues.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
;;; gitlab-issues.el --- Issues API
;; 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:
;; See API doc :
;; https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/issues.md
;;; Code:
(require 's)
(require 'gitlab-http)
(defun gitlab-list-issues (page per-page)
"Get all issues created by authenticated user.
PAGE: current page number
PER-PAGE: number of items on page max 100"
(let ((params '()))
(add-to-list 'params (cons 'per_page (number-to-string per-page)))
(add-to-list 'params (cons 'page (number-to-string page)))
(perform-gitlab-request "GET"
"issues"
params
200)))
(defun gitlab-list-all-issues ()
"Get a list of all issues."
(interactive)
(let* ((page 1)
(per-page 100)
(issues)
(all-issues (gitlab-list-issues page per-page))
(all-issues-count (length all-issues)))
(while (>= all-issues-count (* page per-page))
(setq issues (gitlab-list-issues page per-page))
(setq all-issues (vconcat all-issues issues))
(setq all-issues-count (length all-issues))
(setq page (1+ page)))
all-issues))
(defun gitlab--get-issue-uri (project-id issue-id)
"Retrieve URI to retrieve an issue.
PROJECT-ID : The ID of a project
ISSUE-ID : The ID of a project issue"
(s-concat "projects/"
(url-hexify-string
(format "%s" project-id))
"/issues/"
issue-id))
(defun gitlab-list-project-issues (project-id &optional page per-page params)
"Get a list of project issues.
PROJECT-ID : The ID of a project
PAGE: current page number
PER-PAGE: number of items on page max 100
PARAMS: an alist for query parameters. Exple: '((state . \"opened\"))"
(let ((params params))
(when page
(add-to-list 'params (cons 'per_page (number-to-string per-page))))
(when per-page
(add-to-list 'params (cons 'page (number-to-string page))))
(perform-gitlab-request "GET"
(s-concat "projects/"
(url-hexify-string
(format "%s" project-id))
"/issues")
params
200)))
(defun gitlab-list-all-project-issues (project-id &optional page per-page)
"Get a list of all PROJECT-ID issues.
PROJECT-ID : The ID of a project
PAGE: current page number
PER-PAGE: number of items on page max 100"
(interactive)
(let* ((page 1)
(per-page 100)
(issues)
(all-issues (gitlab-list-project-issues project-id page per-page))
(all-issues-count (length all-issues)))
(while (>= all-issues-count (* page per-page))
(setq issues (gitlab-list-project-issues project-id page per-page))
(setq all-issues (vconcat all-issues issues))
(setq all-issues-count (length all-issues))
(setq page (1+ page)))
all-issues))
(defun gitlab-get-issue (project-id issue-id)
"Gets a single project issue.
PROJECT-ID : The ID of a project
ISSUE-ID : The ID of a project issue"
(perform-gitlab-request "GET"
(gitlab--get-issue-uri
(url-hexify-string
(format "%s" project-id))
(format "%s" issue-id))
nil
200))
(defun gitlab-create-issue (project-id title &optional description assignee milestone labels)
"Create a project issue.
PROJECT-ID the ID or NAMESPACE%2FPROJECT_NAME of a project
TITLE issue title
DESCRIPTION issue description
ASSIGNEE assignee ID
MILESTONE milestone ID
LABELS comma-separated list label names"
(lwarn '(gitlab) :debug "Create ISSUE in project: %s" project-id)
(perform-gitlab-request "POST"
(format "projects/%s/issues"
(url-hexify-string
(format "%s" project-id)))
(format "title=%s%s"
title
(concat
(when description
(format "&description=%s" description))
(when assignee
(format "&assignee_id=%s" assignee))
(when milestone
(format "&milestone_id=%s" milestone))
(when labels
(format "&labels=%s" labels))
))
201))
(defun gitlab-edit-issue (project-id issue-id &optional title description assignee-id milestone-id labels state-event)
"Create a project issue.
PROJECT-ID the ID or NAMESPACE%2FPROJECT_NAME of a project
ISSUE-ID : The ID of a project issue
TITLE issue title
DESCRIPTION issue description
ASSIGNEE-ID assignee ID
MILESTONE-ID milestone ID
LABELS comma-separated list label names"
(lwarn '(gitlab) :debug "UPDATE ISSUE in project: %s\n" project-id)
(perform-gitlab-request "PUT"
(format "projects/%s/issues/%s"
(url-hexify-string
(format "%s" project-id))
issue-id)
(format "%s"
(concat
(when title
(format "&title=%s" title))
(when description
(format "&description=%s" description))
(when assignee-id
(format "&assignee_id=%s" assignee-id))
(when milestone-id
(format "&milestone_id=%s" milestone-id))
(when labels
(format "&labels=%s" labels))
(when state-event
(format "&state_event=%s" state-event))))
200))
(provide 'gitlab-issues)
;;; gitlab-issues.el ends here