-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathgh-issues.el
More file actions
272 lines (218 loc) · 10.6 KB
/
gh-issues.el
File metadata and controls
272 lines (218 loc) · 10.6 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
;;; gh-issues.el --- issues api for github -*- lexical-binding: t; -*-
;; Copyright (C) 2014-2015 Yann Hodique
;; Copyright (C) 2014 Travis Thieman
;; Copyright (C) 2012 Raimon Grau
;; Author: Raimon Grau <raimonster@gmail.com>
;; Keywords:
;; 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 3 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, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Basic usage:
;; (setf api (gh-issues-api "api" :sync nil :cache nil :num-retries 1))
;; (setf issues (gh-issues-issue-list api "user" "repo"))
;; (last (oref issues data)) ; get one issue
;; (setq mi (make-instance 'gh-issues-issue :body "issue body" :title "issue title"))
;; (gh-issues-issue-new api "user" "repo" mi)
;; (setf comments (gh-issues-comments-list api "user" "repo" "issue id"))
;; (setq my-comment (make-instance 'gh-issues-comment :body "This is great!"))
;; (gh-issues-comments-new api "user" "repo" "issue id" my-comment)
;;; Code:
(require 'eieio)
(require 'gh-api)
(require 'gh-auth)
(require 'gh-comments)
(require 'gh-common)
(require 'gh-repos)
(defclass gh-issues-api (gh-api-v3 gh-comments-api-mixin)
((issue-cls :allocation :class :initform gh-issues-issue)
(milestone-cls :allocation :class :initform gh-issues-milestone)
(label-cls :allocation :class :initform gh-issues-label)
(comment-cls :allocation :class :initform gh-issues-comment))
"Github Issues api")
(gh-defclass gh-issues-issue (gh-ref-object)
((number :initarg :number)
(state :initarg :state)
(title :initarg :title)
(body :initarg :body)
(user :initarg :user :initform nil :marshal-type gh-user)
(labels :initarg :labels :initform nil :marshal-type (list gh-issues-label))
(assignees :initarg :assignees :initform nil :marshal-type (list gh-user))
(assignee :initarg :assignee :initform nil :marshal-type gh-user)
(milestone :initarg :milestone :initform nil :marshal-type gh-issues-milestone)
(comments :initarg :comments :initform 0)
(pull-request :initarg :pull-request :marshal-type gh-issues-pull-request)
(closed-at :initarg :closed-at)
(created-at :initarg :created-at)
(updated-at :initarg :updated-at))
"issues request")
(gh-defclass gh-issues-pull-request (gh-object)
((html-url :initarg :html-url)
(diff-url :initarg :diff-url)
(patch-url :initarg :patch-url)))
(gh-defclass gh-issues-label (gh-ref-object)
((name :initarg :name)
(color :initarg :color)))
(cl-defmethod gh-issues-label-req-to-update ((label gh-issues-label))
`(("name" . ,(oref label :name))
("color" . ,(oref label :color))))
(gh-defclass gh-issues-milestone (gh-ref-object)
((number :initarg :number)
(state :initarg :state)
(title :initarg :title)
(description :initarg :description)
(creator :initarg :creator :initform nil :marshal-type gh-user)
(open-issues :initarg :open-issues )
(closed-issues :initarg :closed-issues)
(created-at :initarg :created-at)
(due-on :initarg :due-on))
"github milestone")
(gh-defclass gh-issues-comment (gh-comment)
())
(cl-defmethod gh-issues-issue-list ((api gh-issues-api) user repo)
(gh-api-authenticated-request
api (gh-object-list-reader (oref api issue-cls)) "GET"
(format "/repos/%s/%s/issues" user repo)))
(cl-defmethod gh-issues-milestone-list ((api gh-issues-api) user repo)
(gh-api-authenticated-request
api (gh-object-list-reader (oref api milestone-cls)) "GET"
(format "/repos/%s/%s/milestones" user repo)))
(cl-defmethod gh-issues-milestone-get ((api gh-issues-api) user repo id)
(gh-api-authenticated-request
api (gh-object-reader (oref api milestone-cls)) "GET"
(format "/repos/%s/%s/milestones/%s" user repo id)))
(cl-defmethod gh-issues-milestone-new ((api gh-issues-api) user repo milestone)
(gh-api-authenticated-request
api (gh-object-reader (oref api milestone-cls)) "POST"
(format "/repos/%s/%s/milestones" user repo)
(gh-issues-milestone-req-to-update milestone)))
(cl-defmethod gh-issues-milestone-update ((api gh-issues-api) user repo
id milestone)
(gh-api-authenticated-request
api (gh-object-reader (oref api milestone-cls)) "PATCH"
(format "/repos/%s/%s/milestones/%s" user repo id)
(gh-issues-milestone-req-to-update milestone)))
(cl-defmethod gh-issues-milestone-req-to-update ((milestone gh-issues-milestone))
(let ((state (oref milestone :state))
(description (oref milestone :description))
(due-on (oref milestone :due-on))
(to-update `(("title" . ,(oref milestone :title)))))
(when state (nconc to-update `(("state" . ,state))))
(when description (nconc to-update `(("description" . ,description))))
(when due-on (nconc to-update `(("due_on" . ,due-on))))
to-update))
(cl-defmethod gh-issues-issue-get ((api gh-issues-api) user repo id)
(gh-api-authenticated-request
api (gh-object-reader (oref api issue-cls)) "GET"
(format "/repos/%s/%s/issues/%s" user repo id)))
(cl-defmethod gh-issues-issue-req-to-update ((req gh-issues-issue))
(let ((assignee (oref req :assignee))
;; (labels (oref req labels))
(milestone (oref req :milestone))
(to-update `(("title" . ,(oref req :title))
("state" . ,(oref req :state))
("body" . ,(oref req :body)))))
;; (when labels (nconc to-update `(("labels" . ,(oref req labels) ))))
(when milestone
(nconc to-update `(("milestone" . ,(oref milestone :number)))))
(when assignee
(nconc to-update `(("assignee" . ,(oref assignee :login)))))
to-update))
(cl-defmethod gh-issues-issue-update ((api gh-issues-api) user repo id req)
(gh-api-authenticated-request
api (gh-object-reader (oref api issue-cls)) "PATCH"
(format "/repos/%s/%s/issues/%s" user repo id)
(gh-issues-issue-req-to-update req)))
(cl-defmethod gh-issues-issue-new ((api gh-issues-api) user repo issue)
(gh-api-authenticated-request
api (gh-object-reader (oref api issue-cls)) "POST"
(format "/repos/%s/%s/issues" user repo)
(gh-issues-issue-req-to-update issue)))
;;; Labels
(cl-defmethod gh-issues-label-get ((api gh-issues-api) user repo name)
(gh-api-authenticated-request
api (gh-object-reader (oref api label-cls)) "GET"
(format "/repos/%s/%s/labels/%s" user repo name)))
(cl-defmethod gh-issues-label-list ((api gh-issues-api) user repo)
(gh-api-authenticated-request
api (gh-object-list-reader (oref api label-cls)) "GET"
(format "/repos/%s/%s/labels" user repo )))
(cl-defmethod gh-issues-label-new ((api gh-issues-api) user repo req)
(gh-api-authenticated-request
api (gh-object-reader (oref api label-cls)) "POST"
(format "/repos/%s/%s/labels" user repo)
(gh-issues-label-req-to-update req)))
(cl-defmethod gh-issues-label-update ((api gh-issues-api) user repo req)
(gh-api-authenticated-request
api (gh-object-reader (oref api label-cls)) "POST"
(format "/repos/%s/%s/labels/%s" user repo (oref req :name))
(gh-issues-label-req-to-update req)))
(cl-defmethod gh-issues-label-delete ((api gh-issues-api) user repo name)
(gh-api-authenticated-request
api (gh-object-reader (oref api label-cls)) "DELETE"
(format "/repos/%s/%s/labels/%s" user repo name)))
(cl-defmethod gh-issues-labels-in-issue ((api gh-issues-api) user repo
issue-or-issue-id)
(let ((issue-id (gh-issues--issue-id issue-or-issue-id)))
(gh-api-authenticated-request
api (gh-object-list-reader (oref api label-cls)) "GET"
(format "/repos/%s/%s/issues/%s/labels" user repo issue-id))))
(cl-defmethod gh-issues-labels-add-to-issue ((api gh-issues-api) user repo
issue-or-issue-id labels)
(let ((issue-id (gh-issues--issue-id issue-or-issue-id)))
(gh-api-authenticated-request
api (gh-object-list-reader (oref api label-cls)) "PUT"
(format "/repos/%s/%s/issues/%s/labels" user repo issue-id)
(mapcar #'gh-issues--label-name labels))))
(cl-defmethod gh-issues-labels-remove-all-from-issue ((api gh-issues-api) user repo
issue-or-issue-id )
(let ((issue-id (gh-issues--issue-id issue-or-issue-id)))
(gh-api-authenticated-request
api (lambda (x) x) "DELETE"
(format "/repos/%s/%s/issues/%s/labels" user repo issue-id))))
(cl-defmethod gh-issues-labels-in-milestone ((api gh-issues-api) user repo
milestone-or-milestone-id)
(let ((milestone-id (gh-issues--milestone-id milestone-or-milestone-id)))
(gh-api-authenticated-request
api (gh-object-list-reader (oref api label-cls)) "GET"
(format "/repos/%s/%s/milestones/%s/labels" user repo milestone-id))))
;;; Comments
(cl-defmethod gh-issues-comments-list ((api gh-issues-api) user repo issue-id)
(gh-comments-list api (format "/repos/%s/%s/issues/%s" user repo issue-id)))
(cl-defmethod gh-issues-comments-get ((api gh-issues-api) user repo comment-id)
(gh-comments-get api (format "/repos/%s/%s/issues" user repo) comment-id))
(cl-defmethod gh-issues-comments-update ((api gh-issues-api)
user repo comment-id comment)
(gh-comments-update api (format "/repos/%s/%s/issues" user repo)
comment-id comment))
(cl-defmethod gh-issues-comments-new ((api gh-issues-api)
user repo issue-id comment)
(gh-comments-new api (format "/repos/%s/%s/issues/%s" user repo issue-id)
comment))
(cl-defmethod gh-issues-comments-delete ((api gh-issues-api) user repo comment-id)
(gh-comments-delete api (format "/repos/%s/%s/issues" user repo) comment-id))
;;; helpers
(defun gh-issues--issue-id (issue-or-issue-id)
(if (eieio-object-p issue-or-issue-id)
(oref issue-or-issue-id :id)
issue-or-issue-id))
(defun gh-issues--milestone-id (milestone-or-milestone-id)
(if (eieio-object-p milestone-or-milestone-id)
(oref milestone-or-milestone-id :id)
milestone-or-milestone-id))
(defun gh-issues--label-name (label-or-label-name)
(if (eieio-object-p label-or-label-name)
(oref label-or-label-name :name)
label-or-label-name))
(provide 'gh-issues)
;;; gh-issues.el ends here
;; Local Variables:
;; indent-tabs-mode: nil
;; End: