feat: update the default comment on error

This commit is contained in:
Andrea Lamparelli 2024-04-10 22:34:29 +02:00
parent 7c420531c8
commit 8b0412b111
10 changed files with 75 additions and 29 deletions

View file

@ -141,7 +141,7 @@ describe("github pull request config parser", () => {
});
expect(configs.errorNotification).toEqual({
enabled: false,
message: "Backporting failed: {{error}}"
message: "The backport to `{{target-branch}}` failed. Check the latest run for more details."
});
});
@ -962,7 +962,7 @@ describe("github pull request config parser", () => {
expect(configs.errorNotification).toEqual({
"enabled": true,
"message": "Backporting failed: {{error}}"
"message": "The backport to `{{target-branch}}` failed. Check the latest run for more details."
});
});
});

View file

@ -146,7 +146,7 @@ describe("gitlab merge request config parser", () => {
});
expect(configs.errorNotification).toEqual({
"enabled": false,
"message": "Backporting failed: {{error}}"
"message": "The backport to `{{target-branch}}` failed. Check the latest run for more details."
});
});
@ -905,7 +905,7 @@ describe("gitlab merge request config parser", () => {
expect(configs.errorNotification).toEqual({
"enabled": true,
"message": "Backporting failed: {{error}}",
"message": "The backport to `{{target-branch}}` failed. Check the latest run for more details.",
});
});
});

View file

@ -1238,7 +1238,6 @@ describe("cli runner", () => {
test("with multiple target branches, one failure and error notification enabled", async () => {
jest.spyOn(GitHubClient.prototype, "createPullRequest").mockImplementation((backport: BackportPullRequest) => {
throw new Error(`Mocked error: ${backport.base}`);
});
@ -1323,9 +1322,9 @@ describe("cli runner", () => {
});
expect(GitHubClient.prototype.createPullRequest).toThrowError();
expect(GitHubClient.prototype.createPullRequestComment).toBeCalledTimes(3);
expect(GitHubClient.prototype.createPullRequestComment).toBeCalledWith("https://api.github.com/repos/owner/reponame/pulls/2368", "Backporting failed: Error: Mocked error: v1");
expect(GitHubClient.prototype.createPullRequestComment).toBeCalledWith("https://api.github.com/repos/owner/reponame/pulls/2368", "Backporting failed: Error: Mocked error: v2");
expect(GitHubClient.prototype.createPullRequestComment).toBeCalledWith("https://api.github.com/repos/owner/reponame/pulls/2368", "Backporting failed: Error: Mocked error: v3");
expect(GitHubClient.prototype.createPullRequestComment).toBeCalledWith("https://api.github.com/repos/owner/reponame/pulls/2368", "The backport to `v1` failed. Check the latest run for more details.");
expect(GitHubClient.prototype.createPullRequestComment).toBeCalledWith("https://api.github.com/repos/owner/reponame/pulls/2368", "The backport to `v2` failed. Check the latest run for more details.");
expect(GitHubClient.prototype.createPullRequestComment).toBeCalledWith("https://api.github.com/repos/owner/reponame/pulls/2368", "The backport to `v3` failed. Check the latest run for more details.");
});
test("with some failures and dry run enabled", async () => {

View file

@ -1,11 +1,19 @@
import { injectError } from "@bp/service/runner/runner-util";
import { injectError, injectTargetBranch } from "@bp/service/runner/runner-util";
describe("check runner utilities", () => {
test("properly inject error message", () => {
expect(injectError("Original message: {{error}}", "to inject")).toStrictEqual("Original message: to inject");
});
test("missing placeholder in the original message", () => {
test("missing error placeholder in the original message", () => {
expect(injectError("Original message: {{wrong}}", "to inject")).toStrictEqual("Original message: {{wrong}}");
});
test("properly inject target branch into message", () => {
expect(injectTargetBranch("Original message: {{target-branch}}", "to inject")).toStrictEqual("Original message: to inject");
});
test("missing target branch placeholder in the original message", () => {
expect(injectTargetBranch("Original message: {{wrong}}", "to inject")).toStrictEqual("Original message: {{wrong}}");
});
});