@@ -33,6 +33,7 @@ import {
33
33
trimStringToByteLength ,
34
34
wildcardMatch
35
35
} from "./utils" ;
36
+ import { GraphQlResponse } from "@octokit/graphql/dist-types/types" ;
36
37
37
38
export async function createIssueBranch ( app : Probot , ctx : Context < any > , branchName : string , config : Config ) {
38
39
if ( await hasValidSubscription ( app , ctx , config ) ) {
@@ -263,29 +264,37 @@ export async function createBranch(app: Probot, ctx: Context<any>, config: Confi
263
264
}
264
265
265
266
export async function createPr ( app : Probot , ctx : Context < any > , config : Config , username : string , branchName : string ) {
266
- const owner = getRepoOwnerLogin ( ctx )
267
- const repo = getRepoName ( ctx )
268
- const base = getPrTargetBranch ( ctx , config )
269
- const title = getIssueTitle ( ctx )
267
+ const owner = getRepoOwnerLogin ( ctx ) ;
268
+ const repo = getRepoName ( ctx ) ;
269
+ const base = getPrTargetBranch ( ctx , config ) ;
270
+ const title = getIssueTitle ( ctx ) ;
270
271
const draft = config . openDraftPR ;
272
+ const logContext : any = { owner, repo, branchName, base, title, draft, username} ;
271
273
try {
272
- const baseHeadSha = await getBranchHeadSha ( ctx , base )
273
- const branchHeadSha = await getBranchHeadSha ( ctx , branchName )
274
+ const baseHeadSha = await getBranchHeadSha ( ctx , base ) ;
275
+ logContext . baseHeadSha = baseHeadSha ;
276
+ const branchHeadSha = await getBranchHeadSha ( ctx , branchName ) ;
277
+ logContext . branchHeadSha = branchHeadSha ;
274
278
if ( branchHeadSha === baseHeadSha ) {
275
- app . log . info ( 'Branch and base heads are equal, creating empty commit for PR' )
276
- await createEmptyCommit ( ctx , branchName , getCommitText ( ctx , config ) , String ( branchHeadSha ) )
279
+ app . log . info ( 'Branch and base heads are equal, creating empty commit for PR' ) ;
280
+ const res = await createEmptyCommit ( ctx , branchName , getCommitText ( ctx , config ) , String ( branchHeadSha ) ) ;
281
+ logContext . emptyCommitResponse = res ;
277
282
}
278
283
const { data : pr } = await ctx . octokit . pulls . create (
279
284
{ owner, repo, head : branchName , base, title, body : await getPrBody ( app , ctx , config ) , draft : draft } )
280
285
app . log . info ( `${ draft ? 'Created draft' : 'Created' } pull request ${ pr . number } for branch ${ branchName } ` )
281
- await copyIssueAttributesToPr ( app , ctx , config , pr )
286
+ await copyIssueAttributesToPr ( app , ctx , config , pr ) ;
282
287
} catch ( e : any ) {
283
- app . log . info ( `Could not create PR (${ e . message } )` )
284
- await addComment ( ctx , config , `Could not create PR (${ e . message } )` )
288
+ app . log . info ( `Could not create PR (${ e . message } )` ) ;
289
+ await addComment ( ctx , config , `` ) ;
290
+ await addComment ( ctx , config ,
291
+ 'Could not create PR (${e.message})\n' +
292
+ 'Context:\n' +
293
+ '```json\n' + JSON . stringify ( logContext , null , 2 ) + '\n```' ) ;
285
294
}
286
295
}
287
296
288
- async function createEmptyCommit ( ctx : Context < any > , branchName : string , message : string , headSha : string ) {
297
+ async function createEmptyCommit ( ctx : Context < any > , branchName : string , message : string , headSha : string ) : Promise < GraphQlResponse < any > > {
289
298
const owner = getRepoOwnerLogin ( ctx )
290
299
const repo = getRepoName ( ctx )
291
300
const createEptyCommitMutation = `
@@ -303,7 +312,7 @@ async function createEmptyCommit(ctx: Context<any>, branchName: string, message:
303
312
}
304
313
}
305
314
}`
306
- await ctx . octokit . graphql ( createEptyCommitMutation , {
315
+ return await ctx . octokit . graphql ( createEptyCommitMutation , {
307
316
repositoryNameWithOwner : `${ owner } /${ repo } ` , branchName : branchName , message : message , headSha : headSha
308
317
} )
309
318
}
0 commit comments