@@ -37,7 +37,7 @@ async function _authenticate(accessToken) {
37
37
} ) ;
38
38
return gitlab ;
39
39
} catch ( err ) {
40
- throw errors . convertGitLabError ( err , 'Failed to during authenticate to Github using access token of copilot.' ) ;
40
+ throw errors . handleGitLabError ( err , 'Failed to during authenticate to Github using access token of copilot.' ) ;
41
41
}
42
42
}
43
43
@@ -55,25 +55,37 @@ async function _removeAssignees(gitlab, projectId, issueId, assignees) {
55
55
const oldAssignees = _ . difference ( issue . assignee_ids , assignees ) ;
56
56
await gitlab . projects . issues . edit ( projectId , issueId , { assignee_ids : oldAssignees } ) ;
57
57
} catch ( err ) {
58
- throw errors . convertGitLabError ( err , 'Error occurred during remove assignees from issue.' ) ;
58
+ throw errors . handleGitLabError ( err , 'Error occurred during remove assignees from issue.' ) ;
59
59
}
60
60
}
61
61
62
+ /**
63
+ * Get gitlab issue url
64
+ * @param {String } repoPath the repo path
65
+ * @param {Number } issueId the issue number
66
+ * @returns {String } the url
67
+ * @private
68
+ */
69
+ function _getIssueUrl ( repoPath , issueId ) {
70
+ return `https://gitlab.com/${ repoPath } /issues/${ issueId } ` ;
71
+ }
72
+
62
73
/**
63
74
* creates the comments on gitlab issue
64
75
* @param {Object } copilot the copilot
65
- * @param {Number } projectId the project id
76
+ * @param {Object } project the project object
66
77
* @param {Number } issueId the issue number
67
78
* @param {string } body the comment body text
68
79
*/
69
- async function createComment ( copilot , projectId , issueId , body ) {
80
+ async function createComment ( copilot , project , issueId , body ) {
81
+ const projectId = project . id ;
70
82
Joi . attempt ( { copilot, projectId, issueId, body} , createComment . schema ) ;
71
83
const gitlab = await _authenticate ( copilot . accessToken ) ;
72
84
try {
73
85
body = helper . prepareAutomatedComment ( body , copilot ) ;
74
86
await gitlab . projects . issues . notes . create ( projectId , issueId , { body} ) ;
75
87
} catch ( err ) {
76
- throw errors . convertGitLabError ( err , 'Error occurred during creating comment on issue.' ) ;
88
+ throw errors . handleGitLabError ( err , 'Error occurred during creating comment on issue.' , copilot . topcoderUsername , _getIssueUrl ( project . full_name , issueId ) ) ;
77
89
}
78
90
logger . debug ( `Gitlab comment is added on issue with message: "${ body } "` ) ;
79
91
}
@@ -88,17 +100,18 @@ createComment.schema = {
88
100
/**
89
101
* updates the title of gitlab issue
90
102
* @param {Object } copilot the copilot
91
- * @param {Number } projectId the project id
103
+ * @param {Object } project the project object
92
104
* @param {Number } issueId the issue number
93
105
* @param {string } title new title
94
106
*/
95
- async function updateIssue ( copilot , projectId , issueId , title ) {
107
+ async function updateIssue ( copilot , project , issueId , title ) {
108
+ const projectId = project . id ;
96
109
Joi . attempt ( { copilot, projectId, issueId, title} , updateIssue . schema ) ;
97
110
const gitlab = await _authenticate ( copilot . accessToken ) ;
98
111
try {
99
112
await gitlab . projects . issues . edit ( projectId , issueId , { title} ) ;
100
113
} catch ( err ) {
101
- throw errors . convertGitLabError ( err , 'Error occurred during updating issue.' ) ;
114
+ throw errors . handleGitLabError ( err , 'Error occurred during updating issue.' , copilot . topcoderUsername , _getIssueUrl ( project . full_name , issueId ) ) ;
102
115
}
103
116
logger . debug ( `Gitlab issue title is updated for issue number ${ issueId } ` ) ;
104
117
}
@@ -113,11 +126,12 @@ updateIssue.schema = {
113
126
/**
114
127
* Assigns the issue to user login
115
128
* @param {Object } copilot the copilot
116
- * @param {Number } projectId the project id
129
+ * @param {Object } project the project object
117
130
* @param {Number } issueId the issue number
118
131
* @param {Number } userId the user id of assignee
119
132
*/
120
- async function assignUser ( copilot , projectId , issueId , userId ) {
133
+ async function assignUser ( copilot , project , issueId , userId ) {
134
+ const projectId = project . id ;
121
135
Joi . attempt ( { copilot, projectId, issueId, userId} , assignUser . schema ) ;
122
136
const gitlab = await _authenticate ( copilot . accessToken ) ;
123
137
try {
@@ -128,7 +142,7 @@ async function assignUser(copilot, projectId, issueId, userId) {
128
142
}
129
143
await gitlab . projects . issues . edit ( projectId , issueId , { assignee_ids : [ userId ] } ) ;
130
144
} catch ( err ) {
131
- throw errors . convertGitLabError ( err , 'Error occurred during assigning issue user.' ) ;
145
+ throw errors . handleGitLabError ( err , 'Error occurred during assigning issue user.' , copilot . topcoderUsername , _getIssueUrl ( project . full_name , issueId ) ) ;
132
146
}
133
147
logger . debug ( `Gitlab issue with number ${ issueId } is assigned to ${ issueId } ` ) ;
134
148
}
@@ -143,11 +157,12 @@ assignUser.schema = {
143
157
/**
144
158
* Removes an assignee from the issue
145
159
* @param {Object } copilot the copilot
146
- * @param {Number } projectId the project id
160
+ * @param {Object } project the project object
147
161
* @param {Number } issueId the issue number
148
162
* @param {Number } userId the user id of assignee to remove
149
163
*/
150
- async function removeAssign ( copilot , projectId , issueId , userId ) {
164
+ async function removeAssign ( copilot , project , issueId , userId ) {
165
+ const projectId = project . id ;
151
166
Joi . attempt ( { copilot, projectId, issueId, userId} , removeAssign . schema ) ;
152
167
const gitlab = await _authenticate ( copilot . accessToken ) ;
153
168
await _removeAssignees ( gitlab , projectId , issueId , [ userId ] ) ;
@@ -195,14 +210,15 @@ getUserIdByLogin.schema = {
195
210
/**
196
211
* updates the gitlab issue as paid and fix accepted
197
212
* @param {Object } copilot the copilot
198
- * @param {Number } projectId the project id
213
+ * @param {Object } project the project object
199
214
* @param {Number } issueId the issue number
200
215
* @param {String } challengeUUID the challenge uuid
201
216
* @param {Array } existLabels the issue labels
202
217
* @param {String } winner the winner topcoder handle
203
218
* @param {Boolean } createCopilotPayments the option to create copilot payments or not
204
219
*/
205
- async function markIssueAsPaid ( copilot , projectId , issueId , challengeUUID , existLabels , winner , createCopilotPayments ) { // eslint-disable-line max-params
220
+ async function markIssueAsPaid ( copilot , project , issueId , challengeUUID , existLabels , winner , createCopilotPayments ) { // eslint-disable-line max-params
221
+ const projectId = project . id ;
206
222
Joi . attempt ( { copilot, projectId, issueId, challengeUUID, existLabels, winner, createCopilotPayments} , markIssueAsPaid . schema ) ;
207
223
const gitlab = await _authenticate ( copilot . accessToken ) ;
208
224
const labels = _ ( existLabels ) . filter ( ( i ) => i !== config . FIX_ACCEPTED_ISSUE_LABEL )
@@ -222,7 +238,7 @@ async function markIssueAsPaid(copilot, projectId, issueId, challengeUUID, exist
222
238
const body = helper . prepareAutomatedComment ( commentMessage , copilot ) ;
223
239
await gitlab . projects . issues . notes . create ( projectId , issueId , { body} ) ;
224
240
} catch ( err ) {
225
- throw errors . convertGitLabError ( err , 'Error occurred during updating issue as paid.' ) ;
241
+ throw errors . handleGitLabError ( err , 'Error occurred during updating issue as paid.' , copilot . topcoderUsername , _getIssueUrl ( project . full_name , issueId ) ) ;
226
242
}
227
243
logger . debug ( `Gitlab issue is updated for as paid and fix accepted for ${ issueId } ` ) ;
228
244
}
@@ -240,17 +256,18 @@ markIssueAsPaid.schema = {
240
256
/**
241
257
* change the state of gitlab issue
242
258
* @param {Object } copilot the copilot
243
- * @param {string } projectId the project id
259
+ * @param {Object } project the project object
244
260
* @param {Number } issueId the issue issue id
245
261
* @param {string } state new state
246
262
*/
247
- async function changeState ( copilot , projectId , issueId , state ) {
263
+ async function changeState ( copilot , project , issueId , state ) {
264
+ const projectId = project . id ;
248
265
Joi . attempt ( { copilot, projectId, issueId, state} , changeState . schema ) ;
249
266
const gitlab = await _authenticate ( copilot . accessToken ) ;
250
267
try {
251
268
await gitlab . projects . issues . edit ( projectId , issueId , { state_event : state } ) ;
252
269
} catch ( err ) {
253
- throw errors . convertGitLabError ( err , 'Error occurred during updating status of issue.' ) ;
270
+ throw errors . handleGitLabError ( err , 'Error occurred during updating status of issue.' , copilot . topcoderUsername , _getIssueUrl ( project . full_name , issueId ) ) ;
254
271
}
255
272
logger . debug ( `Gitlab issue state is updated to '${ state } ' for issue number ${ issueId } ` ) ;
256
273
}
@@ -265,17 +282,18 @@ changeState.schema = {
265
282
/**
266
283
* updates the gitlab issue with new labels
267
284
* @param {Object } copilot the copilot
268
- * @param {string } projectId the project id
285
+ * @param {Object } project the project object
269
286
* @param {Number } issueId the issue issue id
270
287
* @param {Number } labels the labels
271
288
*/
272
- async function addLabels ( copilot , projectId , issueId , labels ) {
289
+ async function addLabels ( copilot , project , issueId , labels ) {
290
+ const projectId = project . id ;
273
291
Joi . attempt ( { copilot, projectId, issueId, labels} , addLabels . schema ) ;
274
292
const gitlab = await _authenticate ( copilot . accessToken ) ;
275
293
try {
276
294
await gitlab . projects . issues . edit ( projectId , issueId , { labels : _ . join ( labels , ',' ) } ) ;
277
295
} catch ( err ) {
278
- throw errors . convertGitLabError ( err , 'Error occurred during adding label in issue.' ) ;
296
+ throw errors . handleGitLabError ( err , 'Error occurred during adding label in issue.' , copilot . topcoderUsername , _getIssueUrl ( project . full_name , issueId ) ) ;
279
297
}
280
298
logger . debug ( `Gitlab issue is updated with new labels for ${ issueId } ` ) ;
281
299
}
0 commit comments