@@ -466,9 +466,11 @@ const filterUsers = async (req, res) => {
466
466
467
467
// one time script function to perform the migration - adding github_user_id field to the document
468
468
const migrate = async ( req , res ) => {
469
- const authToken = `${ config . get ( "githubOauth.clientId" ) } : ${ config . get ( "githubOauth.clientSecret ") } ` ;
469
+ const authToken = `${ config . get ( "githubOauth.patToken " ) } ` ;
470
470
// converting the `authToken` string into Base64 format
471
- const encodedToken = Buffer . from ( `${ authToken } ` , "binary" ) . toString ( "base64" ) ;
471
+ const encodedToken = Buffer . from ( `${ authToken } ` ) . toString ( "base64" ) ;
472
+ const usernameNotFound = [ ] ;
473
+ let countUserNotFound = 0 ;
472
474
try {
473
475
// Fetch user data from GitHub API for each document in the users collection
474
476
// divided by 500 because firestore api guarantee that we can process in batch of 500.
@@ -481,6 +483,7 @@ const migrate = async (req, res) => {
481
483
const batchWrites = [ ] ;
482
484
for ( const userDoc of batchDocs ) {
483
485
const githubUsername = userDoc . data ( ) . github_id ;
486
+ const userName = userDoc . data ( ) . github_display_name ;
484
487
batchWrite . update ( userDoc . ref , { github_user_id : null } ) ;
485
488
batchWrites . push (
486
489
axios
@@ -496,7 +499,12 @@ const migrate = async (req, res) => {
496
499
} )
497
500
. catch ( ( error ) => {
498
501
if ( error . response && error . response . status === 404 ) {
499
- logger . error ( `Error: github_user_id not found for ${ githubUsername } ` ) ;
502
+ countUserNotFound ++ ;
503
+ const userNotFound = {
504
+ name : `${ userName } ` ,
505
+ username : `${ githubUsername } ` ,
506
+ } ;
507
+ usernameNotFound . push ( userNotFound ) ;
500
508
} else {
501
509
// Other error occurred
502
510
logger . error ( "An error occurred at axios.get:" , error ) ;
@@ -510,11 +518,14 @@ const migrate = async (req, res) => {
510
518
511
519
return res . status ( 200 ) . json ( {
512
520
message : "All Users github_user_id added successfully" ,
521
+ data : {
522
+ invalidUsers : usernameNotFound ,
523
+ totalCount : countUserNotFound ,
524
+ } ,
513
525
} ) ;
514
526
} catch ( error ) {
515
- return res . status ( 500 ) . json ( {
516
- message : "Internal Server Error" ,
517
- } ) ;
527
+ logger . error ( `Error while Updating all users: ${ error } ` ) ;
528
+ return res . boom . badImplementation ( INTERNAL_SERVER_ERROR ) ;
518
529
}
519
530
} ;
520
531
0 commit comments