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
This commit is contained in:
Earl Warren 2024-04-08 19:02:46 +02:00
parent fc5dba6703
commit ef940d1dbf
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 20 additions and 1 deletions

View file

@ -37,6 +37,11 @@ import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/
// WRITE // WRITE
/**
* Add a comment about a failed backport.
*/
commentError(prUrl: string, message: string): Promise<void>;
/** /**
* Create a new pull request on the underneath git service * Create a new pull request on the underneath git service
* @param backport backport pull request data * @param backport backport pull request data

View file

@ -141,6 +141,16 @@ export default class GitHubClient implements GitClient {
return data.html_url; return data.html_url;
} }
async commentError(prUrl: string, message: string): Promise<void> {
const { owner, project, id } = this.extractPullRequestData(prUrl);
await this.octokit.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: id,
body: message,
});
}
// UTILS // UTILS
/** /**

View file

@ -91,7 +91,11 @@ export default class Runner {
gitCli: git, gitCli: git,
}); });
} catch(error) { } 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); failures.push(error as string);
} }
} }