forked from octokit/octokit.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIssueApi.js
231 lines (213 loc) · 7.22 KB
/
IssueApi.js
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
/**
* Copyright 2010 Ajax.org B.V.
*
* This product includes software developed by
* Ajax.org B.V. (http://www.ajax.org/).
*
* Author: Fabian Jaokbs <[email protected]>
*/
"use strict";
var util = require("util");
var AbstractApi = require("./AbstractApi").AbstractApi;
var IssueApi = exports.IssueApi = function(api) {
this.$api = api;
};
util.inherits(IssueApi, AbstractApi);
(function() {
/**
* List issues by username, repo and state
* http://develop.github.com/p/issues.html#list_a_projects_issues
*
* @param {String} username the username
* @param {String} repo the repo
* @param {String} $state the issue state, can be open or closed
*/
this.getList = function(username, repo, state, callback)
{
var state = state || "open";
this.$api.get(
'issues/list/' + encodeURI(username) + "/" + encodeURI(repo) + "/" + encodeURI(state),
null, null,
this.$createListener(callback, "issues")
);
};
/**
* Retrieves an issue detail
*
* @param {String} username the username
* @param {String} repo the repo
* @param {Number} number issue number
*/
this.getIssue = function(username, repo, number, callback)
{
this.$api.get(
'issues/show/' + encodeURI(username) + "/" + encodeURI(repo) + "/" + encodeURI(number),
null, null,
this.$createListener(callback, "issue")
);
};
/**
* Retrieves comments on an issue
*
* @param {String} username the username
* @param {String} repo the repo
* @param {Number} number issue number
*/
this.getIssueComments = function(username, repo, number, callback)
{
this.$api.get(
'issues/comments/' + encodeURI(username) + "/" + encodeURI(repo) + "/" + encodeURI(number),
null, null,
this.$createListener(callback, "comments")
);
};
/**
* Retrieves labels for a project's issues
*
* @param {String} username the username
* @param {String} repo the repo
*/
this.getIssueLabels = function(username, repo, callback)
{
this.$api.get(
'issues/labels/' + encodeURI(username) + "/" + encodeURI(repo),
null, null,
this.$createListener(callback, "labels")
);
};
/**
* Search issues
*
* @param {String} username the username
* @param {String} repo the repo
* @param {String} state the issue state, can be open or closed
* @param {String} term the search term
*/
this.searchIssues = function(username, repo, state, term, callback)
{
this.$api.get(
'issues/search/' + encodeURI(username) + "/" + encodeURI(repo) + "/"
+ encodeURI(state) + "/" + encodeURI(term),
null, null,
this.$createListener(callback, "issues")
);
};
/**
* Opens a new issue
*
* @param {String} username the username
* @param {String} repo the repo
* @param {String} title the new issue title text
* @param {String} body the new issue body text
*/
this.openIssue = function(username, repo, title, body, callback)
{
this.$api.post(
'issues/open/' + encodeURI(username) + "/" + encodeURI(repo),
{ "title" : title, "body" : body }, null,
this.$createListener(callback, "issue")
);
};
/**
* Closes an issue
*
* @param {String} username the username
* @param {String} repo the repo
* @param {Number} number the issue number
*/
this.closeIssue = function(username, repo, number, callback)
{
this.$api.post(
'issues/close/' + encodeURI(username) + "/" + encodeURI(repo) + "/" + encodeURI(number),
null, null,
this.$createListener(callback, "issue")
);
};
/**
* Reopens an issue
*
* @param {String} username the username
* @param {String} repo the repo
* @param {Number} number the issue number
*/
this.reopenIssue = function(username, repo, number, callback)
{
this.$api.post(
'issues/reopen/' + encodeURI(username) + "/" + encodeURI(repo) + "/" + encodeURI(number),
null, null,
this.$createListener(callback, "issue")
);
};
/**
* Edits an issue
*
* @param {String} username the username
* @param {String} repo the repo
* @param {Number} number the issue number
* @param {String} title the new title
* @param {String} body the new body
*/
this.editIssue = function(username, repo, number, title, body, callback)
{
var postParameters = {};
if (title)
postParameters.title = title;
if (body)
postParameters.body = body;
this.$api.post(
'issues/edit/' + encodeURI(username) + "/" + encodeURI(repo) + "/" + encodeURI(number),
postParameters, null,
this.$createListener(callback, "issue")
);
};
/**
* Adds a label to an issue
*
* @param {String} username the username
* @param {String} repo the repo
* @param {Number} number the issue number
* @param {String} label the label to apply
*/
this.addIssueLabel = function(username, repo, number, label, callback)
{
this.$api.get(
'issues/label/add/' + encodeURI(username) + "/" + encodeURI(repo) + "/"
+ encodeURI(label) + "/" + encodeURI(number),
null, null,
this.$createListener(callback, "labels")
);
};
/**
* Removes a label from an issue
*
* @param {String} username the username
* @param {String} repo the repo
* @param {Number} number the issue number
* @param {String} label the label to remove
*/
this.removeIssueLabel = function(username, repo, number, label, callback)
{
this.$api.get(
'issues/label/remove/' + encodeURI(username) + "/" + encodeURI(repo) + "/"
+ encodeURI(label) + "/" + encodeURI(number),
null, null,
this.$createListener(callback, "labels")
);
};
/**
* Adds a comment to an issue
*
* @param {String} username the username
* @param {String} repo the repo
* @param {Number} number the issue number
* @param {String} comment the comment to add
*/
this.addIssueComment = function(username, repo, number, comment, callback)
{
this.$api.post(
'issues/comment/' + encodeURI(username) + "/" + encodeURI(repo) + "/" + encodeURI(number),
{ "comment" : comment }, null,
this.$createListener(callback, "comment")
);
};
}).call(IssueApi.prototype);