@@ -900,66 +900,6 @@ const getNonNickNameSyncedUsers = async () => {
900900 throw err ;
901901 }
902902} ;
903- const addGithubUserId = async ( page , size ) => {
904- try {
905- const usersNotFound = [ ] ;
906- let countUserFound = 0 ;
907- let countUserNotFound = 0 ;
908-
909- const requestOptions = {
910- method : "GET" ,
911- headers : {
912- "Content-Type" : "application/json" ,
913- Authorization :
914- "Basic " + btoa ( `${ config . get ( "githubOauth.clientId" ) } :${ config . get ( "githubOauth.clientSecret" ) } ` ) ,
915- } ,
916- } ;
917- const usersSnapshot = await firestore
918- . collection ( "users" )
919- . limit ( size )
920- . offset ( page * size )
921- . get ( ) ;
922- // Create batch write operations for each batch of documents
923- const batchWrite = firestore . batch ( ) ;
924- const batchWrites = [ ] ;
925- for ( const userDoc of usersSnapshot . docs ) {
926- if ( userDoc . data ( ) . github_user_id ) continue ;
927- const githubUsername = userDoc . data ( ) . github_id ;
928- const username = userDoc . data ( ) . username ;
929- const userId = userDoc . id ;
930- const getUserDetails = fetch ( `https://api.github.com/users/${ githubUsername } ` , requestOptions )
931- . then ( ( response ) => {
932- if ( ! response . ok ) {
933- throw new Error ( "Network response was not ok" ) ;
934- }
935- return response . json ( ) ;
936- } )
937- . then ( ( data ) => {
938- const githubUserId = data . id ;
939- batchWrite . update ( userDoc . ref , { github_user_id : `${ githubUserId } ` , updated_at : Date . now ( ) } ) ;
940- countUserFound ++ ;
941- } )
942- . catch ( ( error ) => {
943- countUserNotFound ++ ;
944- const invalidUsers = { userId, username, githubUsername } ;
945- usersNotFound . push ( invalidUsers ) ;
946- logger . error ( "An error occurred at fetch:" , error ) ;
947- } ) ;
948- batchWrites . push ( getUserDetails ) ;
949- }
950- await Promise . all ( batchWrites ) ;
951- await batchWrite . commit ( ) ;
952- return {
953- totalUsers : usersSnapshot . docs . length ,
954- usersUpdated : countUserFound ,
955- usersNotUpdated : countUserNotFound ,
956- invalidUsersDetails : usersNotFound ,
957- } ;
958- } catch ( error ) {
959- logger . error ( `Error while Updating all users: ${ error } ` ) ;
960- throw Error ( error ) ;
961- }
962- } ;
963903
964904module . exports = {
965905 addOrUpdate,
@@ -990,5 +930,4 @@ module.exports = {
990930 fetchUsersListForMultipleValues,
991931 fetchUserForKeyValue,
992932 getNonNickNameSyncedUsers,
993- addGithubUserId,
994933} ;
0 commit comments