From 307c51b0331149cc98fea439eb11b98f547776b5 Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Thu, 28 Sep 2023 15:09:47 +0200 Subject: [PATCH 1/3] added comment to report an error --- src/bot.ts | 6 +++++- src/index.ts | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bot.ts b/src/bot.ts index 6cd0e57..29d03a7 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -24,7 +24,8 @@ export class Bot { private readonly pr: Issue, private readonly logger: ActionLogger, private readonly commentsApi: CommentsApi, - ) {} + private readonly actionUrl: string, + ) { } /** Verifies if the author is the author of the PR or a member of the org */ async canTriggerBot(): Promise { @@ -109,6 +110,9 @@ export class Bot { } } catch (e) { this.logger.error(e as Error); + + // If possible, let's try to comment about an issue + await this.commentsApi.comment("There was a problem running the action.\n\n" + "❌😵❌" + `Please see more at the [logs](${this.actionUrl})`) throw e; } } diff --git a/src/index.ts b/src/index.ts index bfd9844..ef2ad74 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,6 +60,8 @@ logger.info( }`, ); +const actionUrl = `${context.serverUrl}/${repo.owner}/${repo.repo}/actions/runs/${context.runId}`; + if (context.payload.comment) { const token = getInput("GITHUB_TOKEN", { required: true }); const comment = context.payload.comment as unknown as IssueComment; From 71292521ceaa88af1b103223616cdea88988acf2 Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Thu, 28 Sep 2023 15:11:18 +0200 Subject: [PATCH 2/3] fixed styling --- src/bot.ts | 8 ++++++-- src/index.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 29d03a7..67ebb0b 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -25,7 +25,7 @@ export class Bot { private readonly logger: ActionLogger, private readonly commentsApi: CommentsApi, private readonly actionUrl: string, - ) { } + ) {} /** Verifies if the author is the author of the PR or a member of the org */ async canTriggerBot(): Promise { @@ -112,7 +112,11 @@ export class Bot { this.logger.error(e as Error); // If possible, let's try to comment about an issue - await this.commentsApi.comment("There was a problem running the action.\n\n" + "❌😵❌" + `Please see more at the [logs](${this.actionUrl})`) + await this.commentsApi.comment( + "### There was a problem running the action.\n\n" + + "❌😵❌\n\n" + + `Please see more at the [logs](${this.actionUrl})`, + ); throw e; } } diff --git a/src/index.ts b/src/index.ts index ef2ad74..d337a99 100644 --- a/src/index.ts +++ b/src/index.ts @@ -79,7 +79,7 @@ if (context.payload.comment) { headers: { authorization: `token ${token}` }, }) as graphql; const merger = new Merger(issue.node_id, gql, logger, getMergeMethod()); - const bot = new Bot(comment, issue, logger, commentsApi); + const bot = new Bot(comment, issue, logger, commentsApi, actionUrl); bot .run(merger) .then(() => logger.info("Finished!")) From 7093fac77b4dccd6d9783a40538454348fdceb3b Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Thu, 28 Sep 2023 15:16:29 +0200 Subject: [PATCH 3/3] added override command This way it won't be ignored in silent mode --- src/bot.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bot.ts b/src/bot.ts index 67ebb0b..2e117fc 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -115,7 +115,8 @@ export class Bot { await this.commentsApi.comment( "### There was a problem running the action.\n\n" + "❌😵❌\n\n" + - `Please see more at the [logs](${this.actionUrl})`, + `Please find more information in the [logs](${this.actionUrl}).`, + true, ); throw e; }