@@ -79,6 +79,10 @@ export class GitHubGlue {
7979 const [ , short , completedAt ] = match ;
8080 const url = `https://github.com/${ baseOwner } /${ this . repo } /commit/${ gitGitCommit } ` ;
8181
82+ if ( process . env . GITGITGADGET_DRY_RUN ) {
83+ console . log ( `Would annotate ${ originalCommit } :\n${ gitGitCommit } as ${ short } at ${ completedAt } \n${ url } ` ) ;
84+ return - 1 ; // debug mode does not actually do anything
85+ }
8286 await this . ensureAuthenticated ( repositoryOwner ) ;
8387 const checks = await this . client . rest . checks . create ( {
8488 completed_at : completedAt ,
@@ -177,6 +181,10 @@ export class GitHubGlue {
177181 * @returns the comment ID and the URL to the comment
178182 */
179183 public async addPRComment ( pullRequest : pullRequestKeyInfo , comment : string ) : Promise < { id : number ; url : string } > {
184+ if ( process . env . GITGITGADGET_DRY_RUN ) {
185+ console . log ( `Would add comment to ${ JSON . stringify ( pullRequest ) } :\n${ comment } ` ) ;
186+ return { id : - 1 , url : "" } ; // debug mode does not actually do anything
187+ }
180188 const prKey = getPullRequestKey ( pullRequest ) ;
181189
182190 await this . ensureAuthenticated ( prKey . owner ) ;
@@ -208,6 +216,10 @@ export class GitHubGlue {
208216 comment : string ,
209217 line ?: number ,
210218 ) : Promise < { id : number ; url : string } > {
219+ if ( process . env . GITGITGADGET_DRY_RUN ) {
220+ console . log ( `Would add comment to ${ JSON . stringify ( pullRequest ) } , commit ${ commit } :\n${ comment } ` ) ;
221+ return { id : - 1 , url : "" } ; // debug mode does not actually do anything
222+ }
211223 const prKey = getPullRequestKey ( pullRequest ) ;
212224
213225 await this . ensureAuthenticated ( prKey . owner ) ;
@@ -241,6 +253,10 @@ export class GitHubGlue {
241253 id : number ,
242254 comment : string ,
243255 ) : Promise < { id : number ; url : string } > {
256+ if ( process . env . GITGITGADGET_DRY_RUN ) {
257+ console . log ( `Would add reply to ${ JSON . stringify ( pullRequest ) } , id ${ id } :\n${ comment } ` ) ;
258+ return { id : - 1 , url : "" } ; // debug mode does not actually do anything
259+ }
244260 const prKey = getPullRequestKey ( pullRequest ) ;
245261
246262 await this . ensureAuthenticated ( prKey . owner ) ;
@@ -265,6 +281,10 @@ export class GitHubGlue {
265281 * @returns the PR number
266282 */
267283 public async updatePR ( prKey : pullRequestKey , body ?: string , title ?: string ) : Promise < number > {
284+ if ( process . env . GITGITGADGET_DRY_RUN ) {
285+ console . log ( `Would add update ${ JSON . stringify ( prKey ) } :\ntitle: ${ title } \nbody: ${ body } ` ) ;
286+ return prKey . pull_number ; // debug mode does not actually do anything
287+ }
268288 await this . ensureAuthenticated ( prKey . owner ) ;
269289
270290 const result = await this . client . rest . pulls . update ( {
@@ -277,6 +297,10 @@ export class GitHubGlue {
277297 }
278298
279299 public async addPRLabels ( pullRequest : pullRequestKeyInfo , labels : string [ ] ) : Promise < string [ ] > {
300+ if ( process . env . GITGITGADGET_DRY_RUN ) {
301+ console . log ( `Would add labels to ${ JSON . stringify ( pullRequest ) } :\n${ labels . join ( ", " ) } ` ) ;
302+ return labels ; // debug mode does not actually do anything
303+ }
280304 const prKey = getPullRequestKey ( pullRequest ) ;
281305
282306 await this . ensureAuthenticated ( prKey . owner ) ;
@@ -290,6 +314,10 @@ export class GitHubGlue {
290314 }
291315
292316 public async closePR ( pullRequest : pullRequestKeyInfo , viaMergeCommit : string ) : Promise < number > {
317+ if ( process . env . GITGITGADGET_DRY_RUN ) {
318+ console . log ( `Would add close ${ JSON . stringify ( pullRequest ) } :\n${ viaMergeCommit } ` ) ;
319+ return - 1 ; // debug mode does not actually do anything
320+ }
293321 const prKey = getPullRequestKey ( pullRequest ) ;
294322
295323 await this . ensureAuthenticated ( prKey . owner ) ;
@@ -454,6 +482,16 @@ export class GitHubGlue {
454482 * @param login the GitHub login
455483 */
456484 public async getGitHubUserInfo ( login : string ) : Promise < IGitHubUser > {
485+ if ( process . env . GITGITGADGET_DRY_RUN ) {
486+ if ( login === "dscho" )
487+ return {
488+ 489+ login,
490+ name : "Ohai!" ,
491+ type : "user" ,
492+ } ;
493+ throw new Error ( `Cannot mock getByUsername: ${ login } ` ) ;
494+ }
457495 // required to get email
458496 await this . ensureAuthenticated ( this . authenticated || this . owner ) ;
459497
0 commit comments