1
1
const fs = require ( "fs-extra" )
2
- const path = require ( 'path' ) ;
3
- const { securePayload, gitHubApiHeaders } = require ( "./common.js" )
2
+ const { securePayload } = require ( "./common.js" )
4
3
const { readBuildDir, sortBuildInfo, checkIfBranchExists } = require ( "./commonChoreForVocabs.js" )
5
4
const types = require ( "./types.js" )
5
+ const logger = require ( "./logger.js" )
6
6
require ( "dotenv" ) . config ( )
7
7
8
8
const { SECRET , BUILD_URL , REBUILD_MAX_ATTEMPTS } = process . env
@@ -46,7 +46,7 @@ const sendBuildRequest = async (buildInfo) => {
46
46
const respBody = await response . text ( )
47
47
// get url from response
48
48
const responseUrl = protocolizeUrl ( respBody . substring ( 17 ) )
49
- console . log ( " Build Urls:" , responseUrl )
49
+ logger . info ( ` Build Urls: ${ responseUrl } ` )
50
50
const url = new URL ( responseUrl )
51
51
const id = url . searchParams . get ( "id" )
52
52
@@ -56,7 +56,7 @@ const sendBuildRequest = async (buildInfo) => {
56
56
ref : buildInfo . ref
57
57
}
58
58
} catch ( error ) {
59
- console . error ( " Error sending request" , error )
59
+ logger . error ( ` Error sending request ${ error } ` )
60
60
return {
61
61
id : null ,
62
62
repository : buildInfo . repository ,
@@ -66,11 +66,7 @@ const sendBuildRequest = async (buildInfo) => {
66
66
}
67
67
68
68
/**
69
- * @param {{
70
- * id: string
71
- * repository: string
72
- * ref: string
73
- * }} buildInfo
69
+ * @param {types.BuildInfo } buildInfo
74
70
*/
75
71
const checkBuildStatus = ( buildInfo ) => {
76
72
const maxAttempts = REBUILD_MAX_ATTEMPTS ? Number ( REBUILD_MAX_ATTEMPTS ) : 30
@@ -81,15 +77,18 @@ const checkBuildStatus = (buildInfo) => {
81
77
const response = fs . readFileSync ( `./dist/build/${ buildInfo . id } .json` )
82
78
/** @type {BuildInfo } */
83
79
json = JSON . parse ( response )
84
- if ( json . status === "complete" || json . status === "error" ) {
85
- console . log ( `${ json . repository } , ${ json . ref } : Finish with status: ${ json . status } (ID: ${ buildInfo . id } )` )
80
+ if ( json . status === "complete" ) {
81
+ logger . info ( `${ json . repository } , ${ json . ref } : Finish with status: ${ json . status } (ID: ${ buildInfo . id } )` )
82
+ return
83
+ } else if ( json . status === "error" ) {
84
+ logger . error ( `${ json . repository } , ${ json . ref } : Finish with status: ${ json . status } (ID: ${ buildInfo . id } )` )
86
85
return
87
86
} else {
88
87
throw new Error ( "Not completed" )
89
88
}
90
89
} catch ( error ) {
91
90
if ( attempts > maxAttempts || ! buildInfo . id ) {
92
- console . log ( `${ buildInfo . repository } , ${ buildInfo . ref } : did not finish after ${ attempts } attempts. Aborting. Error: ${ error } (ID: ${ buildInfo . id } )` )
91
+ logger . info ( `${ buildInfo . repository } , ${ buildInfo . ref } : did not finish after ${ attempts } attempts.Aborting.Error: ${ error } (ID: ${ buildInfo . id } )` )
93
92
return
94
93
}
95
94
setTimeout ( ( ) => {
0 commit comments