Skip to content

Commit 383d4f2

Browse files
committed
chore: πŸ”Š Add logging
1 parent 632120a commit 383d4f2

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

β€Žsrc/github.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
trimStringToByteLength,
3434
wildcardMatch
3535
} from "./utils";
36+
import {GraphQlResponse} from "@octokit/graphql/dist-types/types";
3637

3738
export async function createIssueBranch(app: Probot, ctx: Context<any>, branchName: string, config: Config) {
3839
if (await hasValidSubscription(app, ctx, config)) {
@@ -263,29 +264,37 @@ export async function createBranch(app: Probot, ctx: Context<any>, config: Confi
263264
}
264265

265266
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);
270271
const draft = config.openDraftPR;
272+
const logContext: any = {owner, repo, branchName, base, title, draft, username};
271273
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;
274278
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;
277282
}
278283
const {data: pr} = await ctx.octokit.pulls.create(
279284
{owner, repo, head: branchName, base, title, body: await getPrBody(app, ctx, config), draft: draft})
280285
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);
282287
} 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```');
285294
}
286295
}
287296

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>> {
289298
const owner = getRepoOwnerLogin(ctx)
290299
const repo = getRepoName(ctx)
291300
const createEptyCommitMutation = `
@@ -303,7 +312,7 @@ async function createEmptyCommit(ctx: Context<any>, branchName: string, message:
303312
}
304313
}
305314
}`
306-
await ctx.octokit.graphql(createEptyCommitMutation, {
315+
return await ctx.octokit.graphql(createEptyCommitMutation, {
307316
repositoryNameWithOwner: `${owner}/${repo}`, branchName: branchName, message: message, headSha: headSha
308317
})
309318
}

β€Žsrc/probot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async function insertEventIntoDatabase(app: Probot, ctx: any) {
9999
}
100100
const connectionString = process.env.CREATE_ISSUE_BRANCH_MONGODB;
101101
if (!connectionString) {
102-
app.log.info('Environment variable CREATE_ISSUE_BRANCH_MONGODB not set, skipping database insert');
102+
app.log.debug('Environment variable CREATE_ISSUE_BRANCH_MONGODB not set, skipping database insert');
103103
} else {
104104
const dbService = new MongoDbService(connectionString);
105105
app.log.info(`Inserting event into database: ${JSON.stringify(webhookEvent)}`);

0 commit comments

Comments
Β (0)