@@ -35,24 +35,24 @@ async function manageVanillaUser (data) {
35
35
}
36
36
const topcoderProfile = JSON . parse ( topcoderProfileResponseStr ) . result . content [ 0 ]
37
37
38
- const { text : topcoderRolesResponseStr } = await topcoderApi . getRoles ( topcoderProfile . id )
38
+ const { text : topcoderRolesResponseStr } = await topcoderApi . getRoles ( topcoderProfile . id )
39
39
const topcoderRolesResponse = JSON . parse ( topcoderRolesResponseStr ) . result . content
40
40
const topcoderRoleNames = _ . map ( topcoderRolesResponse , 'roleName' )
41
41
42
- const { body : allVanillaRoles } = await vanillaClient . getAllRoles ( )
42
+ const { body : allVanillaRoles } = await vanillaClient . getAllRoles ( )
43
43
44
44
// Add all missing Topcoder roles
45
45
await addTopcoderRoles ( allVanillaRoles , topcoderRoleNames )
46
46
47
47
const { body : allNewVanillaRoles } = await vanillaClient . getAllRoles ( )
48
48
49
- let allTopcoderRoles = _ . filter ( allNewVanillaRoles , { type : 'topcoder' } )
49
+ const allTopcoderRoles = _ . filter ( allNewVanillaRoles , { type : 'topcoder' } )
50
50
51
- let nonTopcoderRoles = _ . filter ( allNewVanillaRoles , role => role [ ' type' ] ! = 'topcoder' )
52
- let nonTopcoderRoleIDs = _ . map ( nonTopcoderRoles , 'roleID' )
51
+ const nonTopcoderRoles = _ . filter ( allNewVanillaRoles , role => role . type != = 'topcoder' )
52
+ const nonTopcoderRoleIDs = _ . map ( nonTopcoderRoles , 'roleID' )
53
53
54
- let userTopcoderRoles = _ . filter ( allTopcoderRoles , role => topcoderRoleNames . includes ( role [ ' name' ] ) )
55
- let userTopcoderRoleIDs = _ . map ( userTopcoderRoles , 'roleID' )
54
+ const userTopcoderRoles = _ . filter ( allTopcoderRoles , role => topcoderRoleNames . includes ( role . name ) )
55
+ const userTopcoderRoleIDs = _ . map ( userTopcoderRoles , 'roleID' )
56
56
57
57
if ( ! vanillaUser ) {
58
58
logger . info ( `The '${ username } ' user wasn't found in Vanilla` )
@@ -79,7 +79,7 @@ async function manageVanillaUser (data) {
79
79
vanillaUser = user
80
80
81
81
// Sync Topcoder roles
82
- const allCurrentUserRoleIDs = _ . map ( vanillaUser . roles , 'roleID' ) ;
82
+ const allCurrentUserRoleIDs = _ . map ( vanillaUser . roles , 'roleID' )
83
83
const currentVanillaRoleIDs = _ . intersection ( allCurrentUserRoleIDs , nonTopcoderRoleIDs )
84
84
const userData = {
85
85
roleID : [ ...currentVanillaRoleIDs , ...userTopcoderRoleIDs ]
@@ -119,15 +119,15 @@ async function manageVanillaUser (data) {
119
119
}
120
120
}
121
121
122
- async function addTopcoderRoles ( allVanillaRoles , topcoderRoleNames ) {
122
+ async function addTopcoderRoles ( allVanillaRoles , topcoderRoleNames ) {
123
123
const allTopcoderRoles = _ . filter ( allVanillaRoles , { type : 'topcoder' } )
124
- const userTopcoderRoles = _ . filter ( allTopcoderRoles , role => topcoderRoleNames . includes ( role [ ' name' ] ) )
124
+ const userTopcoderRoles = _ . filter ( allTopcoderRoles , role => topcoderRoleNames . includes ( role . name ) )
125
125
const userTopcoderRoleIDs = _ . map ( userTopcoderRoles , 'roleID' )
126
126
127
- if ( topcoderRoleNames . length != userTopcoderRoleIDs . length ) {
128
- const missingRoles = _ . difference ( topcoderRoleNames , _ . map ( userTopcoderRoles , 'name' ) )
127
+ if ( topcoderRoleNames . length !== userTopcoderRoleIDs . length ) {
128
+ const missingRoles = _ . difference ( topcoderRoleNames , _ . map ( userTopcoderRoles , 'name' ) )
129
129
logger . info ( 'Missing roles:' + JSON . stringify ( missingRoles ) )
130
- for ( const missingRole of missingRoles ) {
130
+ for ( const missingRole of missingRoles ) {
131
131
await vanillaClient . createRole ( {
132
132
canSession : 1 ,
133
133
description : 'Added by Challenge Forum Processor' ,
@@ -168,7 +168,7 @@ async function createVanillaGroup (challenge) {
168
168
throw new Error ( 'Multiple discussions with type=\'challenge\' and provider=\'vanilla\' are not supported.' )
169
169
}
170
170
171
- const { body : project } = await topcoderApi . getProject ( challenge . projectId )
171
+ const { body : project } = await topcoderApi . getProject ( challenge . projectId )
172
172
const copilots = _ . filter ( project . members , { role : constants . TOPCODER . ROLE_COPILOT } )
173
173
const challengesForums = _ . filter ( template . categories , [ 'name' , constants . VANILLA . CHALLENGES_FORUM ] )
174
174
if ( ! challengesForums ) {
@@ -228,15 +228,15 @@ async function createVanillaGroup (challenge) {
228
228
229
229
// Create the root challenge category
230
230
const { body : challengeCategory } = await vanillaClient . createCategory ( {
231
- name : challengeDetailsDiscussion . name ,
231
+ name : challenge . name ,
232
232
urlcode : `${ challenge . id } ` ,
233
233
parentCategoryID : parentCategory [ 0 ] . categoryID ,
234
234
displayAs : groupTemplate . categories ? constants . VANILLA . CATEGORY_DISPLAY_STYLE . CATEGORIES : constants . VANILLA . CATEGORY_DISPLAY_STYLE . DISCUSSIONS
235
235
} )
236
236
237
237
logger . info ( `The '${ challengeCategory . name } ' category was created` )
238
238
239
- if ( groupTemplate . categories ) {
239
+ if ( groupTemplate . categories ) {
240
240
for ( const item of groupTemplate . categories ) {
241
241
const urlCodeTemplate = _ . template ( item . urlcode )
242
242
const { body : childCategory } = await vanillaClient . createCategory ( {
@@ -245,16 +245,16 @@ async function createVanillaGroup (challenge) {
245
245
parentCategoryID : challengeCategory . categoryID
246
246
} )
247
247
logger . info ( `The '${ item . name } ' category was created` )
248
- await createDiscussions ( group , challenge , item . discussions , childCategory ) ;
248
+ await createDiscussions ( group , challenge , item . discussions , childCategory )
249
249
}
250
250
}
251
251
252
- if ( groupTemplate . discussions ) {
253
- await createDiscussions ( group , challenge , groupTemplate . discussions , challengeCategory ) ;
252
+ if ( groupTemplate . discussions ) {
253
+ await createDiscussions ( group , challenge , groupTemplate . discussions , challengeCategory )
254
254
}
255
255
256
256
for ( const copilot of copilots ) {
257
- await manageVanillaUser ( { challengeId : challenge . id , action : constants . USER_ACTIONS . INVITE , handle : copilot . handle } )
257
+ await manageVanillaUser ( { challengeId : challenge . id , action : constants . USER_ACTIONS . INVITE , handle : copilot . handle } )
258
258
}
259
259
260
260
challengeDetailsDiscussion . url = `${ challengeCategory . url } `
@@ -274,34 +274,47 @@ async function updateVanillaGroup (challenge) {
274
274
logger . info ( `The challenge with challengeID=${ challenge . id } :` )
275
275
276
276
const { body : groups } = await vanillaClient . searchGroups ( challenge . id )
277
- if ( groups . length == 0 ) {
278
- throw new Error ( 'The group wasn\'t found for this challenge' )
277
+ if ( groups . length === 0 ) {
278
+ throw new Error ( 'The group wasn\'t found for this challenge' )
279
279
}
280
280
281
281
if ( groups . length > 1 ) {
282
282
throw new Error ( 'Multiple groups were found for this challenge' )
283
283
}
284
284
285
- const { body : updatedGroup } = await vanillaClient . updateGroup ( groups [ 0 ] . groupID , { name : challenge . name } )
286
-
285
+ const { body : updatedGroup } = await vanillaClient . updateGroup ( groups [ 0 ] . groupID , { name : challenge . name } )
287
286
logger . info ( `The group was updated: ${ JSON . stringify ( updatedGroup ) } ` )
287
+
288
+ const { body : groupCategory } = await vanillaClient . getCategoryByUrlcode ( `${ challenge . id } ` )
289
+ if ( ! groupCategory ) {
290
+ throw new Error ( 'Group category wasn\'t found for this challenge' )
291
+ }
292
+
293
+ const { body : groupCategoryForEdit } = await vanillaClient . getCategoryForEdit ( groupCategory . categoryID )
294
+ if ( ! groupCategoryForEdit ) {
295
+ throw new Error ( 'Group category wasn\'t found for this challenge' )
296
+ }
297
+ groupCategoryForEdit . name = challenge . name
298
+
299
+ const { body : updatedGroupCategory } = await vanillaClient . updateCategory ( groupCategoryForEdit . categoryID , groupCategoryForEdit )
300
+ logger . info ( `The group category was updated: ${ JSON . stringify ( updatedGroupCategory ) } ` )
288
301
}
289
302
290
303
async function createDiscussions ( group , challenge , templateDiscussions , vanillaCategory ) {
291
- for ( const discussion of templateDiscussions ) {
292
- // create a discussion
293
- const bodyTemplate = _ . template ( discussion . body )
294
- await vanillaClient . createDiscussion ( {
295
- body : bodyTemplate ( { challenge : challenge } ) ,
296
- name : discussion . title ,
297
- groupID : group . groupID ,
298
- categoryID : vanillaCategory . categoryID ,
299
- format : constants . VANILLA . DISCUSSION_FORMAT . WYSIWYG ,
300
- closed : discussion . closed ,
301
- pinned : discussion . announce
302
- } )
303
- logger . info ( `The '${ discussion . title } ' discussion/announcement was created` )
304
- }
304
+ for ( const discussion of templateDiscussions ) {
305
+ // create a discussion
306
+ const bodyTemplate = _ . template ( discussion . body )
307
+ await vanillaClient . createDiscussion ( {
308
+ body : bodyTemplate ( { challenge : challenge } ) ,
309
+ name : discussion . title ,
310
+ groupID : group . groupID ,
311
+ categoryID : vanillaCategory . categoryID ,
312
+ format : constants . VANILLA . DISCUSSION_FORMAT . WYSIWYG ,
313
+ closed : discussion . closed ,
314
+ pinned : discussion . announce
315
+ } )
316
+ logger . info ( `The '${ discussion . title } ' discussion/announcement was created` )
317
+ }
305
318
}
306
319
307
320
module . exports = {
0 commit comments