From ef940d1dbf08a97e01f0c1d737cc0397d3afbfba Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 8 Apr 2024 19:02:46 +0200 Subject: [PATCH] feat: comment on the original pull/merge request when on error A comment is added to the original PR when a backport fails. The developers watching the PR will be notified even if they are not watching the CI. Fixes: https://github.com/kiegroup/git-backporting/issues/123 --- src/service/git/git-client.ts | 5 +++++ src/service/git/github/github-client.ts | 10 ++++++++++ src/service/runner/runner.ts | 6 +++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/service/git/git-client.ts b/src/service/git/git-client.ts index c9d0f10..c012b79 100644 --- a/src/service/git/git-client.ts +++ b/src/service/git/git-client.ts @@ -37,6 +37,11 @@ import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/ // WRITE + /** + * Add a comment about a failed backport. + */ + commentError(prUrl: string, message: string): Promise; + /** * Create a new pull request on the underneath git service * @param backport backport pull request data diff --git a/src/service/git/github/github-client.ts b/src/service/git/github/github-client.ts index 40f1831..e5e2df0 100644 --- a/src/service/git/github/github-client.ts +++ b/src/service/git/github/github-client.ts @@ -141,6 +141,16 @@ export default class GitHubClient implements GitClient { return data.html_url; } + async commentError(prUrl: string, message: string): Promise { + const { owner, project, id } = this.extractPullRequestData(prUrl); + await this.octokit.rest.issues.createComment({ + owner: owner, + repo: repo, + issue_number: id, + body: message, + }); + } + // UTILS /** diff --git a/src/service/runner/runner.ts b/src/service/runner/runner.ts index d4ddf42..322a4d3 100644 --- a/src/service/runner/runner.ts +++ b/src/service/runner/runner.ts @@ -91,7 +91,11 @@ export default class Runner { gitCli: git, }); } catch(error) { - this.logger.error(`Something went wrong backporting to ${pr.base}: ${error}`); + const error = `Something went wrong backporting to ${pr.base}: ${error}`; + if (!args.dryRun) { + gitApi.commentError(configs.originalPullRequest.url, error) + } + this.logger.error(error); failures.push(error as string); } }