@@ -22,6 +22,19 @@ const copilotUserSchema = Joi.object().keys({
22
22
topcoderUsername : Joi . string ( )
23
23
} ) . required ( ) ;
24
24
25
+ /**
26
+ * parse the repository name and repoFullName owner
27
+ * @param {String } fullName the full repository name
28
+ * @returns {Object } the parsed data
29
+ * @private
30
+ */
31
+ function _parseRepoUrl ( fullName ) {
32
+ const results = fullName . split ( '/' ) ;
33
+ const repo = results [ results . length - 1 ] ;
34
+ const owner = _ ( results ) . slice ( 0 , results . length - 1 ) . join ( '/' ) ;
35
+ return { owner, repo} ;
36
+ }
37
+
25
38
/**
26
39
* authenticate the github using access token
27
40
* @param {String } accessToken the access token of copilot
@@ -79,14 +92,14 @@ async function _getUsernameById(github, id) {
79
92
/**
80
93
* updates the title of github issue
81
94
* @param {Object } copilot the copilot
82
- * @param {string } repo the repository
95
+ * @param {string } repoFullName the repository
83
96
* @param {Number } number the issue number
84
97
* @param {string } title new title
85
98
*/
86
- async function updateIssue ( copilot , repo , number , title ) {
87
- Joi . attempt ( { copilot, repo , number, title} , updateIssue . schema ) ;
99
+ async function updateIssue ( copilot , repoFullName , number , title ) {
100
+ Joi . attempt ( { copilot, repoFullName , number, title} , updateIssue . schema ) ;
88
101
const github = await _authenticate ( copilot . accessToken ) ;
89
- const owner = await _getUsernameById ( github , copilot . userProviderId ) ;
102
+ const { owner, repo } = _parseRepoUrl ( repoFullName ) ;
90
103
try {
91
104
await github . issues . edit ( { owner, repo, number, title} ) ;
92
105
} catch ( err ) {
@@ -97,22 +110,22 @@ async function updateIssue(copilot, repo, number, title) {
97
110
98
111
updateIssue . schema = {
99
112
copilot : copilotUserSchema ,
100
- repo : Joi . string ( ) . required ( ) ,
113
+ repoFullName : Joi . string ( ) . required ( ) ,
101
114
number : Joi . number ( ) . required ( ) ,
102
115
title : Joi . string ( ) . required ( )
103
116
} ;
104
117
105
118
/**
106
119
* Assigns the issue to user
107
120
* @param {Object } copilot the copilot
108
- * @param {string } repo the repository
121
+ * @param {string } repoFullName the repository
109
122
* @param {Number } number the issue number
110
123
* @param {string } user the user login of assignee
111
124
*/
112
- async function assignUser ( copilot , repo , number , user ) {
113
- Joi . attempt ( { copilot, repo , number, user} , assignUser . schema ) ;
125
+ async function assignUser ( copilot , repoFullName , number , user ) {
126
+ Joi . attempt ( { copilot, repoFullName , number, user} , assignUser . schema ) ;
114
127
const github = await _authenticate ( copilot . accessToken ) ;
115
- const owner = await _getUsernameById ( github , copilot . userProviderId ) ;
128
+ const { owner, repo } = _parseRepoUrl ( repoFullName ) ;
116
129
try {
117
130
const issue = await github . issues . get ( { owner, repo, number} ) ;
118
131
@@ -129,23 +142,23 @@ async function assignUser(copilot, repo, number, user) {
129
142
130
143
assignUser . schema = {
131
144
copilot : copilotUserSchema ,
132
- repo : Joi . string ( ) . required ( ) ,
145
+ repoFullName : Joi . string ( ) . required ( ) ,
133
146
number : Joi . number ( ) . required ( ) ,
134
147
user : Joi . string ( ) . required ( )
135
148
} ;
136
149
137
150
/**
138
151
* Removes an assignee from the issue
139
152
* @param {Object } copilot the copilot
140
- * @param {string } repo the repository
153
+ * @param {string } repoFullName the repository
141
154
* @param {Number } number the issue number
142
155
* @param {string } user the user login of assignee
143
156
*/
144
- async function removeAssign ( copilot , repo , number , user ) {
145
- Joi . attempt ( { copilot, repo , number, user} , removeAssign . schema ) ;
157
+ async function removeAssign ( copilot , repoFullName , number , user ) {
158
+ Joi . attempt ( { copilot, repoFullName , number, user} , removeAssign . schema ) ;
146
159
147
160
const github = await _authenticate ( copilot . accessToken ) ;
148
- const owner = await _getUsernameById ( github , copilot . userProviderId ) ;
161
+ const { owner, repo } = _parseRepoUrl ( repoFullName ) ;
149
162
await _removeAssignees ( github , owner , repo , number , [ user ] ) ;
150
163
logger . debug ( `Github user ${ user } is unassigned from issue number ${ number } ` ) ;
151
164
}
@@ -155,15 +168,15 @@ removeAssign.schema = assignUser.schema;
155
168
/**
156
169
* creates the comments on github issue
157
170
* @param {Object } copilot the copilot
158
- * @param {string } repo the repository
171
+ * @param {string } repoFullName the repository
159
172
* @param {Number } number the issue number
160
173
* @param {string } body the comment body text
161
174
*/
162
- async function createComment ( copilot , repo , number , body ) {
163
- Joi . attempt ( { copilot, repo , number, body} , createComment . schema ) ;
175
+ async function createComment ( copilot , repoFullName , number , body ) {
176
+ Joi . attempt ( { copilot, repoFullName , number, body} , createComment . schema ) ;
164
177
165
178
const github = await _authenticate ( copilot . accessToken ) ;
166
- const owner = await _getUsernameById ( github , copilot . userProviderId ) ;
179
+ const { owner, repo } = _parseRepoUrl ( repoFullName ) ;
167
180
try {
168
181
await github . issues . createComment ( { owner, repo, number, body} ) ;
169
182
} catch ( err ) {
@@ -174,7 +187,7 @@ async function createComment(copilot, repo, number, body) {
174
187
175
188
createComment . schema = {
176
189
copilot : copilotUserSchema ,
177
- repo : Joi . string ( ) . required ( ) ,
190
+ repoFullName : Joi . string ( ) . required ( ) ,
178
191
number : Joi . number ( ) . required ( ) ,
179
192
body : Joi . string ( ) . required ( )
180
193
} ;
@@ -218,14 +231,14 @@ getUserIdByLogin.schema = {
218
231
/**
219
232
* updates the github issue as paid and fix accepted
220
233
* @param {Object } copilot the copilot
221
- * @param {string } repo the repository
234
+ * @param {string } repoFullName the repository
222
235
* @param {Number } number the issue number
223
236
* @param {Number } challengeId the challenge id
224
237
*/
225
- async function markIssueAsPaid ( copilot , repo , number , challengeId ) {
226
- Joi . attempt ( { copilot, repo , number, challengeId} , markIssueAsPaid . schema ) ;
238
+ async function markIssueAsPaid ( copilot , repoFullName , number , challengeId ) {
239
+ Joi . attempt ( { copilot, repoFullName , number, challengeId} , markIssueAsPaid . schema ) ;
227
240
const github = await _authenticate ( copilot . accessToken ) ;
228
- const owner = await _getUsernameById ( github , copilot . userProviderId ) ;
241
+ const { owner, repo } = _parseRepoUrl ( repoFullName ) ;
229
242
const labels = [ config . PAID_ISSUE_LABEL , config . FIX_ACCEPTED_ISSUE_LABEL ] ;
230
243
try {
231
244
await github . issues . edit ( { owner, repo, number, labels} ) ;
@@ -239,22 +252,22 @@ async function markIssueAsPaid(copilot, repo, number, challengeId) {
239
252
240
253
markIssueAsPaid . schema = {
241
254
copilot : copilotUserSchema ,
242
- repo : Joi . string ( ) . required ( ) ,
255
+ repoFullName : Joi . string ( ) . required ( ) ,
243
256
number : Joi . number ( ) . required ( ) ,
244
257
challengeId : Joi . number ( ) . positive ( ) . required ( )
245
258
} ;
246
259
247
260
/**
248
261
* change the state of github issue
249
262
* @param {Object } copilot the copilot
250
- * @param {string } repo the repository
263
+ * @param {string } repoFullName the repository
251
264
* @param {Number } number the issue number
252
265
* @param {string } state new state
253
266
*/
254
- async function changeState ( copilot , repo , number , state ) {
255
- Joi . attempt ( { copilot, repo , number, state} , changeState . schema ) ;
267
+ async function changeState ( copilot , repoFullName , number , state ) {
268
+ Joi . attempt ( { copilot, repoFullName , number, state} , changeState . schema ) ;
256
269
const github = await _authenticate ( copilot . accessToken ) ;
257
- const owner = await _getUsernameById ( github , copilot . userProviderId ) ;
270
+ const { owner, repo } = _parseRepoUrl ( repoFullName ) ;
258
271
try {
259
272
await github . issues . edit ( { owner, repo, number, state} ) ;
260
273
} catch ( err ) {
@@ -265,22 +278,22 @@ async function changeState(copilot, repo, number, state) {
265
278
266
279
changeState . schema = {
267
280
copilot : copilotUserSchema ,
268
- repo : Joi . string ( ) . required ( ) ,
281
+ repoFullName : Joi . string ( ) . required ( ) ,
269
282
number : Joi . number ( ) . required ( ) ,
270
283
state : Joi . string ( ) . required ( )
271
284
} ;
272
285
273
286
/**
274
287
* updates the github issue with new labels
275
288
* @param {Object } copilot the copilot
276
- * @param {string } repo the repository
289
+ * @param {string } repoFullName the repository
277
290
* @param {Number } number the issue number
278
291
* @param {Number } labels the challenge id
279
292
*/
280
- async function addLabels ( copilot , repo , number , labels ) {
281
- Joi . attempt ( { copilot, repo , number, labels} , addLabels . schema ) ;
293
+ async function addLabels ( copilot , repoFullName , number , labels ) {
294
+ Joi . attempt ( { copilot, repoFullName , number, labels} , addLabels . schema ) ;
282
295
const github = await _authenticate ( copilot . accessToken ) ;
283
- const owner = await _getUsernameById ( github , copilot . userProviderId ) ;
296
+ const { owner, repo } = _parseRepoUrl ( repoFullName ) ;
284
297
try {
285
298
await github . issues . edit ( { owner, repo, number, labels} ) ;
286
299
} catch ( err ) {
@@ -291,7 +304,7 @@ async function addLabels(copilot, repo, number, labels) {
291
304
292
305
addLabels . schema = {
293
306
copilot : copilotUserSchema ,
294
- repo : Joi . string ( ) . required ( ) ,
307
+ repoFullName : Joi . string ( ) . required ( ) ,
295
308
number : Joi . number ( ) . required ( ) ,
296
309
labels : Joi . array ( ) . items ( Joi . string ( ) ) . required ( )
297
310
} ;
0 commit comments