-
Notifications
You must be signed in to change notification settings - Fork 11
/
issues.clj
264 lines (223 loc) · 8.77 KB
/
issues.clj
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
(ns tentacles.issues
"Implements the Github Issues API: http://developer.github.com/v3/issues/"
(:use [tentacles.core :only [api-call no-content? reactions-header]]
[clojure.string :only [join]]))
;; Some API requests, namely GET ones, require that labels be passed as a
;; comma-delimited string of labels. The POST requests want it to be passed
;; as a list of strings. In order to be consistent, users will always pass
;; a list of labels. This joins the labels so that the string requirement
;; on GETs is transparent to the user.
(defn- join-labels [m]
(if (:labels m)
(update-in m [:labels] (partial join ","))
m))
;; ## Primary Issue API
(defn my-issues
"List issues for (authenticated) user.
Options are:
filter -- assigned: assigned to you,
created: created by you,
mentioned: issues that mention you,
subscribed: issues that you're subscribed to.
state -- open (default), closed.
labels -- A string of comma-separated label names.
sort -- created (default), updated, comments.
direction -- asc: ascending,
desc (default): descending.
since -- String ISO 8601 timestamp."
[options]
(api-call :get "issues" nil (join-labels options)))
(defn issues
"List issues for a repository.
Options are:
milestone -- Milestone number,
none: no milestone,
*: any milestone.
assignee -- A username,
none: no assigned user,
*: any assigned user.
mentioned -- A username.
state -- open (default), closed.
labels -- A string of comma-separated label names.
sort -- created (default), updated, comments.
direction -- asc: ascending,
desc (default): descending.
since -- String ISO 8601 timestamp."
[user repo & [options]]
(api-call :get "repos/%s/%s/issues" [user repo] (join-labels options)))
(defn org-issues
"List all issues for a given organization for (authenticated) user.
Options are:
filter -- assigned: assigned to you,
created: created by you,
mentioned: issues that mention you,
subscribed: issues that you're subscribed to.
state -- open (default), closed.
labels -- A string of comma-separated label names.
sort -- created (default), updated, comments.
direction -- asc: ascending,
desc (default): descending.
since -- String ISO 8601 timestamp."
[org & [options]]
(api-call :get "orgs/%s/issues" [org] (join-labels options)))
(defn specific-issue
"Fetch a specific issue."
[user repo number & [options]]
(api-call :get "repos/%s/%s/issues/%s" [user repo number] options))
(defn create-issue
"Create an issue.
Options are:
milestone -- Milestone number to associate with this issue..
assignee -- A username to assign to this issue.
labels -- A list of labels to associate with this issue.
body -- The body text of the issue."
[user repo title options]
(api-call :post "repos/%s/%s/issues" [user repo] (assoc options :title title)))
(defn edit-issue
"Edit an issue.
Options are:
milestone -- Milestone number to associate with this issue..
assignee -- A username to assign to this issue.
labels -- A list of labels to associate with this issue.
Replaces the existing labels.
state -- open or closed.
title -- Title of the issue.
body -- The body text of the issue."
[user repo id options]
(api-call :patch "repos/%s/%s/issues/%s" [user repo id] options))
;; ## Issue Comments API
(defn repo-issue-comments
"List issue comments in a repository."
[user repo & [options]]
(api-call :get "repos/%s/%s/issues/comments" [user repo] options))
(defn issue-comments
"List comments on an issue."
[user repo id & [options]]
(api-call :get "repos/%s/%s/issues/%s/comments" [user repo id] options))
(defn specific-comment
"Get a specific comment."
[user repo comment-id & [options]]
(api-call :get "repos/%s/%s/issues/comments/%s" [user repo comment-id] options))
(defn create-comment
"Create a comment."
[user repo id body options]
(api-call :post "repos/%s/%s/issues/%s/comments"
[user repo id] (assoc options :body body)))
(defn edit-comment
"Edit a comment."
[user repo comment-id body options]
(api-call :patch "repos/%s/%s/issues/comments/%s"
[user repo comment-id] (assoc options :body body)))
(defn delete-comment
"Delete a comment."
[user repo comment-id options]
(no-content?
(api-call :delete "repos/%s/%s/issues/comments/%s"
[user repo comment-id] options)))
;; ## Issue Event API
(defn issue-events
"List events for an issue."
[user repo id & [options]]
(api-call :get "repos/%s/%s/issues/%s/events" [user repo id] options))
(defn repo-events
"List events for a repository."
[user repo & [options]]
(api-call :get "repos/%s/%s/issues/events" [user repo] options))
(defn specific-event
"Get a single, specific event."
[user repo id & [options]]
(api-call :get "repos/%s/%s/issues/events/%s" [user repo id] options))
;; ## Issue Label API
(defn repo-labels
"List labels for a repo."
[user repo & [options]]
(api-call :get "repos/%s/%s/labels" [user repo] options))
(defn issue-labels
"List labels on an issue."
[user repo issue-id & [options]]
(api-call :get "repos/%s/%s/issues/%s/labels" [user repo issue-id] options))
(defn specific-label
"Get a specific label."
[user repo id & [options]]
(api-call :get "repos/%s/%s/labels/%s" [user repo id] options))
(defn create-label
"Create a label."
[user repo name color options]
(api-call :post "repos/%s/%s/labels"
[user repo] (assoc options :name name :color color)))
(defn edit-label
"Edit a label."
[user repo id name color options]
(api-call :patch "repos/%s/%s/labels/%s"
[user repo id] (assoc options :name name :color color)))
(defn delete-label
"Delete a label."
[user repo id options]
(no-content? (api-call :delete "repos/%s/%s/labels/%s" [user repo id] options)))
(defn add-labels
"Add labels to an issue."
[user repo issue-id labels options]
(api-call :post "repos/%s/%s/issues/%s/labels"
[user repo issue-id] (assoc options :raw labels)))
(defn remove-label
"Remove a label from an issue."
[user repo issue-id label-id options]
(api-call :delete "repos/%s/%s/issues/%s/labels/%s"
[user repo issue-id label-id] options))
(defn replace-labels
"Replace all labels for an issue."
[user repo issue-id labels options]
(api-call :put "repos/%s/%s/issues/%s/labels"
[user repo issue-id] (assoc options :raw labels)))
(defn remove-all-labels
"Remove all labels from an issue."
[user repo issue-id options]
(no-content? (api-call :delete "repos/%s/%s/issues/%s/labels" [user repo issue-id] options)))
(defn milestone-labels
"Get labels for every issue in a milestone."
[user repo stone-id & [options]]
(api-call :get "repos/%s/%s/milestones/%s/labels" [user repo stone-id] options))
;; ## Issue Milestones API
(defn repo-milestones
"List milestones for a repository.
Options are:
state -- open (default), closed.
direction -- asc, desc (default).
sort -- due_date (default), completeness."
[user repo & [options]]
(api-call :get "repos/%s/%s/milestones" [user repo] options))
(defn specific-milestone
"Get a specific milestone."
[user repo id & [options]]
(api-call :get "repos/%s/%s/milestones/%s" [user repo id] options))
(defn create-milestone
"Create a milestone.
Options are:
state -- open (default), closed.
description -- a description string.
due-on -- String ISO 8601 timestamp"
[user repo title options]
(api-call :post "repos/%s/%s/milestones"
[user repo] (assoc options :title title)))
(defn edit-milestone
"Edit a milestone.
Options are:
state -- open (default), closed.
description -- a description string.
due-on -- String ISO 8601 timestamp"
[user repo id title options]
(api-call :patch "repos/%s/%s/milestones/%s"
[user repo id] (assoc options :title title)))
(defn delete-milestone
"Delete a milestone."
[user repo id options]
(no-content? (api-call :delete "repos/%s/%s/milestones/%s" [user repo id] options)))
;; Reactions api
(defn issue-reactions
"Fetches the reactions for a specific issue"
[user repo issue-id & [options]]
(api-call :get "repos/%s/%s/issues/%s/reactions" [user repo issue-id] (reactions-header options)))
(defn comment-reactions
"Gets the reactions for a specific comment"
[user repo comment-id & [options]]
(api-call :get "repos/%s/%s/issues/comments/%s/reactions" [user repo comment-id] (reactions-header options)))