44 cacheExchange,
55 fetchExchange
66} = require ( "@urql/core" ) ;
7+ const { info, error, debug } = require ( "./src/log" ) ;
78
89let GITHUB_GRAPHQL_URL = null ;
910let githubToken = null ;
@@ -16,7 +17,7 @@ let client = null;
1617 * @param {string } apiUrl GitHub GraphQL API URL
1718 */
1819function init ( token , apiUrl ) {
19- githubToken = token || process . env . GITHUB_TOKEN ;
20+ const githubToken = token || process . env . GITHUB_TOKEN ;
2021 if ( ! githubToken ) {
2122 throw new Error ( "Error: token argument missing or GITHUB_TOKEN env var not set." ) ;
2223 }
@@ -87,10 +88,7 @@ function extractChangedOrDeletedFiles(changedFiles, deletedFiles) {
8788
8889function checkErrorResponse ( response ) {
8990 if ( ! ! response . errors || ! ! response . error || ! response . data ) {
90- console . error (
91- "Error response from API:" ,
92- JSON . stringify ( response , null , 2 )
93- ) ;
91+ error ( "Error response from API:" , JSON . stringify ( response , null , 2 ) ) ;
9492 throw new Error ( "Received error response from API" ) ;
9593 }
9694}
@@ -119,11 +117,11 @@ async function fetchBranchData(repoOwner, repoName, branchName) {
119117 const response = await client . query ( query , variables ) ;
120118 checkErrorResponse ( response ) ;
121119 return response ;
122- } catch ( error ) {
123- console . error (
124- `Error while trying to fetch data from API: ${ error . message } `
120+ } catch ( err ) {
121+ error (
122+ `Error while trying to fetch data from API: ${ err . message } `
125123 ) ;
126- throw error ;
124+ throw err ;
127125 }
128126}
129127
@@ -179,8 +177,8 @@ async function createCommitOnBranch(
179177 changedFiles ,
180178 deletedFiles
181179 ) ) ;
182- console . log ( "Changed files:" , JSON . stringify ( changedFiles , null , 2 ) ) ;
183- console . log ( "Deleted files:" , JSON . stringify ( deletedFiles , null , 2 ) ) ;
180+ info ( "Changed files:" , JSON . stringify ( changedFiles , null , 2 ) ) ;
181+ info ( "Deleted files:" , JSON . stringify ( deletedFiles , null , 2 ) ) ;
184182
185183 if ( ! commitMessage ) {
186184 throw new Error ( "No commit message provided. Aborting." ) ;
@@ -216,11 +214,11 @@ async function createCommitOnBranch(
216214 data : response ,
217215 commitUrl : response ?. data ?. createCommitOnBranch ?. commit ?. url || null
218216 } ;
219- } catch ( error ) {
220- console . error (
221- `Error while performing commit action via GraphQL API: ${ error . message } `
217+ } catch ( err ) {
218+ error (
219+ `Error while performing commit action via GraphQL API: ${ err . message } `
222220 ) ;
223- throw error ;
221+ throw err ;
224222 }
225223}
226224
0 commit comments