2023-01-05 11:41:14 +01:00
|
|
|
import { Args } from "@bp/service/args/args.types";
|
2024-02-23 15:13:34 +01:00
|
|
|
import { Configs } from "@bp/service/configs/configs.types";
|
2023-01-05 11:41:14 +01:00
|
|
|
import PullRequestConfigsParser from "@bp/service/configs/pullrequest/pr-configs-parser";
|
2023-07-02 00:05:17 +02:00
|
|
|
import GitClientFactory from "@bp/service/git/git-client-factory";
|
|
|
|
import { GitClientType } from "@bp/service/git/git.types";
|
|
|
|
import { mockGitHubClient } from "../../../support/mock/git-client-mock-support";
|
2024-02-23 15:13:34 +01:00
|
|
|
import { addProcessArgs, createTestFile, removeTestFile, resetProcessArgs } from "../../../support/utils";
|
2023-08-03 21:57:11 +02:00
|
|
|
import { MERGED_PR_FIXTURE, OPEN_PR_FIXTURE, NOT_MERGED_PR_FIXTURE, REPO, TARGET_OWNER, MULT_COMMITS_PR_FIXTURE } from "../../../support/mock/github-data";
|
2023-07-05 22:11:23 +02:00
|
|
|
import CLIArgsParser from "@bp/service/args/cli/cli-args-parser";
|
2023-07-11 11:22:01 +02:00
|
|
|
import GitHubMapper from "@bp/service/git/github/github-mapper";
|
|
|
|
import GitHubClient from "@bp/service/git/github/github-client";
|
2023-07-05 22:11:23 +02:00
|
|
|
|
|
|
|
const GITHUB_MERGED_PR_SIMPLE_CONFIG_FILE_CONTENT_PATHNAME = "./github-pr-configs-parser-simple-pr-merged.json";
|
|
|
|
const GITHUB_MERGED_PR_SIMPLE_CONFIG_FILE_CONTENT = {
|
|
|
|
"targetBranch": "prod",
|
2023-08-03 21:57:11 +02:00
|
|
|
"pullRequest": `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MERGED_PR_FIXTURE.number}`,
|
2023-07-05 22:11:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const GITHUB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT_PATHNAME = "./github-pr-configs-parser-complex-pr-merged.json";
|
|
|
|
const GITHUB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT = {
|
|
|
|
"dryRun": false,
|
|
|
|
"auth": "my-auth-token",
|
2023-08-03 21:57:11 +02:00
|
|
|
"pullRequest": `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MERGED_PR_FIXTURE.number}`,
|
2023-07-05 22:11:23 +02:00
|
|
|
"targetBranch": "prod",
|
|
|
|
"gitUser": "Me",
|
|
|
|
"gitEmail": "me@email.com",
|
|
|
|
"title": "New Title",
|
|
|
|
"body": "New Body",
|
|
|
|
"bodyPrefix": "New Body Prefix -",
|
|
|
|
"reviewers": ["user1", "user2"],
|
|
|
|
"assignees": ["user3", "user4"],
|
|
|
|
"inheritReviewers": true, // not taken into account
|
2023-07-10 08:49:11 +02:00
|
|
|
"labels": ["cherry-pick :cherries:"],
|
|
|
|
"inheritLabels": true,
|
2023-07-05 22:11:23 +02:00
|
|
|
};
|
2023-01-05 11:41:14 +01:00
|
|
|
|
2023-07-11 11:22:01 +02:00
|
|
|
jest.spyOn(GitHubMapper.prototype, "mapPullRequest");
|
|
|
|
jest.spyOn(GitHubClient.prototype, "getPullRequest");
|
|
|
|
|
2023-07-02 00:05:17 +02:00
|
|
|
describe("github pull request config parser", () => {
|
2023-01-05 11:41:14 +01:00
|
|
|
|
2023-08-03 21:57:11 +02:00
|
|
|
const mergedPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MERGED_PR_FIXTURE.number}`;
|
|
|
|
const openPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${OPEN_PR_FIXTURE.number}`;
|
|
|
|
const notMergedPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${NOT_MERGED_PR_FIXTURE.number}`;
|
|
|
|
const multipleCommitsPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MULT_COMMITS_PR_FIXTURE.number}`;
|
2023-01-05 11:41:14 +01:00
|
|
|
|
2023-07-05 22:11:23 +02:00
|
|
|
let argsParser: CLIArgsParser;
|
|
|
|
let configParser: PullRequestConfigsParser;
|
2023-01-05 11:41:14 +01:00
|
|
|
|
|
|
|
beforeAll(() => {
|
2023-07-05 22:11:23 +02:00
|
|
|
// create a temporary file
|
|
|
|
createTestFile(GITHUB_MERGED_PR_SIMPLE_CONFIG_FILE_CONTENT_PATHNAME, JSON.stringify(GITHUB_MERGED_PR_SIMPLE_CONFIG_FILE_CONTENT));
|
|
|
|
createTestFile(GITHUB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT_PATHNAME, JSON.stringify(GITHUB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT));
|
|
|
|
|
2023-07-02 00:05:17 +02:00
|
|
|
GitClientFactory.reset();
|
|
|
|
GitClientFactory.getOrCreate(GitClientType.GITHUB, "whatever", "http://localhost/api/v3");
|
2023-01-05 11:41:14 +01:00
|
|
|
});
|
|
|
|
|
2023-07-05 22:11:23 +02:00
|
|
|
afterAll(() => {
|
|
|
|
// clean up all temporary files
|
|
|
|
removeTestFile(GITHUB_MERGED_PR_SIMPLE_CONFIG_FILE_CONTENT_PATHNAME);
|
|
|
|
removeTestFile(GITHUB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT_PATHNAME);
|
|
|
|
});
|
|
|
|
|
2023-01-05 11:41:14 +01:00
|
|
|
beforeEach(() => {
|
2023-07-05 22:11:23 +02:00
|
|
|
// reset process.env variables
|
|
|
|
resetProcessArgs();
|
|
|
|
|
2023-07-11 22:43:22 +02:00
|
|
|
// mock octokit
|
|
|
|
mockGitHubClient("http://localhost/api/v3");
|
|
|
|
|
2023-07-05 22:11:23 +02:00
|
|
|
// create a fresh new instance every time
|
|
|
|
argsParser = new CLIArgsParser();
|
|
|
|
configParser = new PullRequestConfigsParser();
|
2023-01-05 11:41:14 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("parse configs from pull request", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: false,
|
|
|
|
pullRequest: mergedPRUrl,
|
2023-06-22 17:44:14 +02:00
|
|
|
targetBranch: "prod",
|
|
|
|
gitUser: "GitHub",
|
|
|
|
gitEmail: "noreply@github.com",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: [],
|
|
|
|
inheritReviewers: true,
|
2023-01-05 11:41:14 +01:00
|
|
|
};
|
|
|
|
|
2023-07-05 22:11:23 +02:00
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
2023-01-05 11:41:14 +01:00
|
|
|
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
2024-04-08 18:51:13 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
|
|
|
2023-01-05 11:41:14 +01:00
|
|
|
expect(configs.dryRun).toEqual(false);
|
2023-06-22 17:44:14 +02:00
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "GitHub",
|
|
|
|
email: "noreply@github.com"
|
|
|
|
});
|
2023-12-10 22:05:53 +01:00
|
|
|
expect(configs.auth).toEqual(undefined);
|
2023-01-05 11:41:14 +01:00
|
|
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
|
|
expect(configs.originalPullRequest).toEqual({
|
|
|
|
number: 2368,
|
|
|
|
author: "gh-user",
|
|
|
|
url: "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
|
|
htmlUrl: "https://github.com/owner/reponame/pull/2368",
|
|
|
|
state: "closed",
|
|
|
|
merged: true,
|
|
|
|
mergedBy: "that-s-a-user",
|
|
|
|
title: "PR Title",
|
|
|
|
body: "Please review and merge",
|
|
|
|
reviewers: ["requested-gh-user", "gh-user"],
|
2023-06-22 17:44:14 +02:00
|
|
|
assignees: [],
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: ["backport prod"],
|
2023-01-05 11:41:14 +01:00
|
|
|
targetRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
sourceRepo: {
|
|
|
|
owner: "fork",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
|
|
},
|
|
|
|
nCommits: 2,
|
|
|
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]
|
|
|
|
});
|
2023-08-03 21:57:11 +02:00
|
|
|
expect(configs.backportPullRequests.length).toEqual(1);
|
|
|
|
expect(configs.backportPullRequests[0]).toEqual({
|
2023-07-27 11:26:39 +02:00
|
|
|
owner: "owner",
|
|
|
|
repo: "reponame",
|
|
|
|
head: "bp-prod-28f63db",
|
|
|
|
base: "prod",
|
|
|
|
title: "[prod] PR Title",
|
2023-06-28 11:56:36 +02:00
|
|
|
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
2023-01-05 11:41:14 +01:00
|
|
|
reviewers: ["gh-user", "that-s-a-user"],
|
2023-06-22 17:44:14 +02:00
|
|
|
assignees: [],
|
2023-07-10 08:49:11 +02:00
|
|
|
labels: [],
|
2023-07-27 11:26:39 +02:00
|
|
|
comments: [],
|
2023-01-05 11:41:14 +01:00
|
|
|
});
|
2024-04-10 23:01:16 +02:00
|
|
|
expect(configs.errorNotification).toEqual({
|
|
|
|
enabled: false,
|
|
|
|
message: "The backport to `{{target-branch}}` failed. Check the latest run for more details."
|
|
|
|
});
|
2023-01-05 11:41:14 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("override folder", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: true,
|
|
|
|
auth: "whatever",
|
|
|
|
pullRequest: mergedPRUrl,
|
|
|
|
targetBranch: "prod",
|
2023-06-22 17:44:14 +02:00
|
|
|
folder: "/tmp/test",
|
|
|
|
gitUser: "GitHub",
|
|
|
|
gitEmail: "noreply@github.com",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: [],
|
|
|
|
inheritReviewers: true,
|
2023-01-05 11:41:14 +01:00
|
|
|
};
|
|
|
|
|
2023-07-05 22:11:23 +02:00
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
2023-01-05 11:41:14 +01:00
|
|
|
|
|
|
|
expect(configs.dryRun).toEqual(true);
|
|
|
|
expect(configs.auth).toEqual("whatever");
|
|
|
|
expect(configs.folder).toEqual("/tmp/test");
|
2023-06-22 17:44:14 +02:00
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "GitHub",
|
|
|
|
email: "noreply@github.com"
|
|
|
|
});
|
2023-01-05 11:41:14 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("still open pull request", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: true,
|
|
|
|
auth: "whatever",
|
|
|
|
pullRequest: openPRUrl,
|
2023-06-22 17:44:14 +02:00
|
|
|
targetBranch: "prod",
|
|
|
|
gitUser: "GitHub",
|
|
|
|
gitEmail: "noreply@github.com",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: [],
|
|
|
|
inheritReviewers: true,
|
2023-01-05 11:41:14 +01:00
|
|
|
};
|
|
|
|
|
2023-07-05 22:11:23 +02:00
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
2023-01-05 11:41:14 +01:00
|
|
|
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
2024-04-08 18:51:13 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 4444, undefined);
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
2024-04-08 18:51:13 +02:00
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]);
|
2023-07-11 11:22:01 +02:00
|
|
|
|
2023-01-05 11:41:14 +01:00
|
|
|
expect(configs.dryRun).toEqual(true);
|
|
|
|
expect(configs.auth).toEqual("whatever");
|
2023-06-22 17:44:14 +02:00
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "GitHub",
|
|
|
|
email: "noreply@github.com"
|
|
|
|
});
|
2023-01-05 11:41:14 +01:00
|
|
|
expect(configs.originalPullRequest).toEqual({
|
|
|
|
number: 4444,
|
|
|
|
author: "gh-user",
|
|
|
|
url: "https://api.github.com/repos/owner/reponame/pulls/4444",
|
|
|
|
htmlUrl: "https://github.com/owner/reponame/pull/4444",
|
|
|
|
state: "open",
|
|
|
|
merged: false,
|
2023-07-02 00:05:17 +02:00
|
|
|
mergedBy: undefined,
|
2023-01-05 11:41:14 +01:00
|
|
|
title: "PR Title",
|
|
|
|
body: "Please review and merge",
|
|
|
|
reviewers: ["gh-user"],
|
2023-06-22 17:44:14 +02:00
|
|
|
assignees: [],
|
2023-07-10 08:49:11 +02:00
|
|
|
labels: [],
|
2023-01-05 11:41:14 +01:00
|
|
|
targetRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
sourceRepo: {
|
|
|
|
owner: "fork",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
|
|
},
|
2023-06-20 22:29:52 +02:00
|
|
|
bpBranchName: undefined,
|
2023-01-05 11:41:14 +01:00
|
|
|
nCommits: 2,
|
2024-04-08 18:51:13 +02:00
|
|
|
commits: ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"],
|
2023-01-05 11:41:14 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("closed pull request", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: true,
|
|
|
|
auth: "whatever",
|
|
|
|
pullRequest: notMergedPRUrl,
|
2023-06-22 17:44:14 +02:00
|
|
|
targetBranch: "prod",
|
|
|
|
gitUser: "GitHub",
|
|
|
|
gitEmail: "noreply@github.com",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: [],
|
|
|
|
inheritReviewers: true,
|
2023-01-05 11:41:14 +01:00
|
|
|
};
|
|
|
|
|
2023-07-20 10:05:07 +02:00
|
|
|
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("Provided pull request is closed and not merged");
|
2023-01-05 11:41:14 +01:00
|
|
|
});
|
2023-06-20 22:29:52 +02:00
|
|
|
|
2023-07-10 08:49:11 +02:00
|
|
|
test("override backport pr data inheriting reviewers", async () => {
|
2023-06-20 22:29:52 +02:00
|
|
|
const args: Args = {
|
|
|
|
dryRun: false,
|
|
|
|
auth: "",
|
|
|
|
pullRequest: mergedPRUrl,
|
|
|
|
targetBranch: "prod",
|
2023-06-22 17:44:14 +02:00
|
|
|
gitUser: "Me",
|
|
|
|
gitEmail: "me@email.com",
|
2023-06-20 22:29:52 +02:00
|
|
|
title: "New Title",
|
|
|
|
body: "New Body",
|
|
|
|
bodyPrefix: "New Body Prefix -",
|
2023-06-22 17:44:14 +02:00
|
|
|
reviewers: [],
|
|
|
|
assignees: [],
|
|
|
|
inheritReviewers: true,
|
2023-07-27 11:26:39 +02:00
|
|
|
bpBranchName: "custom-branch"
|
2023-06-20 22:29:52 +02:00
|
|
|
};
|
|
|
|
|
2023-07-05 22:11:23 +02:00
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
2023-06-20 22:29:52 +02:00
|
|
|
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
2024-04-08 18:51:13 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
|
|
|
2023-06-20 22:29:52 +02:00
|
|
|
expect(configs.dryRun).toEqual(false);
|
2023-06-22 17:44:14 +02:00
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "Me",
|
|
|
|
email: "me@email.com"
|
|
|
|
});
|
2023-06-20 22:29:52 +02:00
|
|
|
expect(configs.auth).toEqual("");
|
|
|
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
|
|
expect(configs.originalPullRequest).toEqual({
|
|
|
|
number: 2368,
|
|
|
|
author: "gh-user",
|
|
|
|
url: "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
|
|
htmlUrl: "https://github.com/owner/reponame/pull/2368",
|
|
|
|
state: "closed",
|
|
|
|
merged: true,
|
|
|
|
mergedBy: "that-s-a-user",
|
|
|
|
title: "PR Title",
|
|
|
|
body: "Please review and merge",
|
|
|
|
reviewers: ["requested-gh-user", "gh-user"],
|
2023-06-22 17:44:14 +02:00
|
|
|
assignees: [],
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: ["backport prod"],
|
2023-06-20 22:29:52 +02:00
|
|
|
targetRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
sourceRepo: {
|
|
|
|
owner: "fork",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
|
|
},
|
|
|
|
bpBranchName: undefined,
|
|
|
|
nCommits: 2,
|
|
|
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
|
|
|
});
|
2023-08-03 21:57:11 +02:00
|
|
|
expect(configs.backportPullRequests.length).toEqual(1);
|
|
|
|
expect(configs.backportPullRequests[0]).toEqual({
|
2023-07-27 11:26:39 +02:00
|
|
|
owner: "owner",
|
|
|
|
repo: "reponame",
|
|
|
|
head: "custom-branch",
|
|
|
|
base: "prod",
|
2023-06-20 22:29:52 +02:00
|
|
|
title: "New Title",
|
|
|
|
body: "New Body Prefix -New Body",
|
|
|
|
reviewers: ["gh-user", "that-s-a-user"],
|
2023-06-22 17:44:14 +02:00
|
|
|
assignees: [],
|
2023-07-10 08:49:11 +02:00
|
|
|
labels: [],
|
2023-07-27 11:26:39 +02:00
|
|
|
comments: [],
|
2023-06-22 17:44:14 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-08-03 21:57:11 +02:00
|
|
|
test("override backport with empty bp branch name", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: false,
|
|
|
|
auth: "",
|
|
|
|
pullRequest: mergedPRUrl,
|
|
|
|
targetBranch: "prod",
|
|
|
|
gitUser: "Me",
|
|
|
|
gitEmail: "me@email.com",
|
|
|
|
title: "New Title",
|
|
|
|
body: "New Body",
|
|
|
|
bodyPrefix: "New Body Prefix -",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: [],
|
|
|
|
inheritReviewers: true,
|
|
|
|
bpBranchName: " "
|
|
|
|
};
|
|
|
|
|
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
|
|
|
|
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
2024-04-08 18:51:13 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
2023-08-03 21:57:11 +02:00
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
|
|
|
|
|
|
expect(configs.dryRun).toEqual(false);
|
|
|
|
expect(configs.auth).toEqual("");
|
|
|
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
|
|
expect(configs.backportPullRequests.length).toEqual(1);
|
|
|
|
expect(configs.backportPullRequests[0]).toEqual({
|
|
|
|
owner: "owner",
|
|
|
|
repo: "reponame",
|
|
|
|
head: "bp-prod-28f63db",
|
|
|
|
base: "prod",
|
|
|
|
title: "New Title",
|
|
|
|
body: "New Body Prefix -New Body",
|
|
|
|
reviewers: ["gh-user", "that-s-a-user"],
|
|
|
|
assignees: [],
|
|
|
|
labels: [],
|
|
|
|
comments: [],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-06-22 17:44:14 +02:00
|
|
|
test("override backport pr reviewers and assignees", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: false,
|
|
|
|
auth: "",
|
|
|
|
pullRequest: mergedPRUrl,
|
|
|
|
targetBranch: "prod",
|
|
|
|
gitUser: "Me",
|
|
|
|
gitEmail: "me@email.com",
|
|
|
|
title: "New Title",
|
|
|
|
body: "New Body",
|
|
|
|
bodyPrefix: "New Body Prefix -",
|
|
|
|
reviewers: ["user1", "user2"],
|
|
|
|
assignees: ["user3", "user4"],
|
|
|
|
inheritReviewers: true, // not taken into account
|
|
|
|
};
|
|
|
|
|
2023-07-05 22:11:23 +02:00
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
2023-06-22 17:44:14 +02:00
|
|
|
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
2024-04-08 18:51:13 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
|
|
|
2023-06-22 17:44:14 +02:00
|
|
|
expect(configs.dryRun).toEqual(false);
|
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "Me",
|
|
|
|
email: "me@email.com"
|
|
|
|
});
|
|
|
|
expect(configs.auth).toEqual("");
|
|
|
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
|
|
expect(configs.originalPullRequest).toEqual({
|
|
|
|
number: 2368,
|
|
|
|
author: "gh-user",
|
|
|
|
url: "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
|
|
htmlUrl: "https://github.com/owner/reponame/pull/2368",
|
|
|
|
state: "closed",
|
|
|
|
merged: true,
|
|
|
|
mergedBy: "that-s-a-user",
|
|
|
|
title: "PR Title",
|
|
|
|
body: "Please review and merge",
|
|
|
|
reviewers: ["requested-gh-user", "gh-user"],
|
|
|
|
assignees: [],
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: ["backport prod"],
|
2023-06-22 17:44:14 +02:00
|
|
|
targetRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
sourceRepo: {
|
|
|
|
owner: "fork",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
|
|
},
|
|
|
|
bpBranchName: undefined,
|
|
|
|
nCommits: 2,
|
|
|
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
|
|
|
});
|
2023-08-03 21:57:11 +02:00
|
|
|
expect(configs.backportPullRequests.length).toEqual(1);
|
|
|
|
expect(configs.backportPullRequests[0]).toEqual({
|
2023-07-27 11:26:39 +02:00
|
|
|
owner: "owner",
|
|
|
|
repo: "reponame",
|
|
|
|
head: "bp-prod-28f63db",
|
|
|
|
base: "prod",
|
2023-06-22 17:44:14 +02:00
|
|
|
title: "New Title",
|
|
|
|
body: "New Body Prefix -New Body",
|
|
|
|
reviewers: ["user1", "user2"],
|
|
|
|
assignees: ["user3", "user4"],
|
2023-07-10 08:49:11 +02:00
|
|
|
labels: [],
|
2023-07-27 11:26:39 +02:00
|
|
|
comments: [],
|
2023-06-22 17:44:14 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("override backport pr empty reviewers", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: false,
|
|
|
|
auth: "",
|
|
|
|
pullRequest: mergedPRUrl,
|
|
|
|
targetBranch: "prod",
|
|
|
|
gitUser: "Me",
|
|
|
|
gitEmail: "me@email.com",
|
|
|
|
title: "New Title",
|
|
|
|
body: "New Body",
|
|
|
|
bodyPrefix: "New Body Prefix -",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: ["user3", "user4"],
|
|
|
|
inheritReviewers: false,
|
|
|
|
};
|
|
|
|
|
2023-07-05 22:11:23 +02:00
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
2023-06-22 17:44:14 +02:00
|
|
|
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
2024-04-08 18:51:13 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
|
|
|
2023-06-22 17:44:14 +02:00
|
|
|
expect(configs.dryRun).toEqual(false);
|
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "Me",
|
|
|
|
email: "me@email.com"
|
|
|
|
});
|
|
|
|
expect(configs.auth).toEqual("");
|
|
|
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
|
|
expect(configs.originalPullRequest).toEqual({
|
|
|
|
number: 2368,
|
|
|
|
author: "gh-user",
|
|
|
|
url: "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
|
|
htmlUrl: "https://github.com/owner/reponame/pull/2368",
|
|
|
|
state: "closed",
|
|
|
|
merged: true,
|
|
|
|
mergedBy: "that-s-a-user",
|
|
|
|
title: "PR Title",
|
|
|
|
body: "Please review and merge",
|
|
|
|
reviewers: ["requested-gh-user", "gh-user"],
|
|
|
|
assignees: [],
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: ["backport prod"],
|
2023-06-22 17:44:14 +02:00
|
|
|
targetRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
sourceRepo: {
|
|
|
|
owner: "fork",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
|
|
},
|
|
|
|
bpBranchName: undefined,
|
|
|
|
nCommits: 2,
|
|
|
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
|
|
|
});
|
2023-08-03 21:57:11 +02:00
|
|
|
expect(configs.backportPullRequests.length).toEqual(1);
|
|
|
|
expect(configs.backportPullRequests[0]).toEqual({
|
2023-07-27 11:26:39 +02:00
|
|
|
owner: "owner",
|
|
|
|
repo: "reponame",
|
|
|
|
head: "bp-prod-28f63db",
|
|
|
|
base: "prod",
|
2023-06-22 17:44:14 +02:00
|
|
|
title: "New Title",
|
|
|
|
body: "New Body Prefix -New Body",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: ["user3", "user4"],
|
2023-07-10 08:49:11 +02:00
|
|
|
labels: [],
|
2023-07-27 11:26:39 +02:00
|
|
|
comments: [],
|
2023-07-10 08:49:11 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("override backport pr custom labels with duplicates", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: false,
|
|
|
|
auth: "",
|
|
|
|
pullRequest: mergedPRUrl,
|
|
|
|
targetBranch: "prod",
|
|
|
|
gitUser: "Me",
|
|
|
|
gitEmail: "me@email.com",
|
|
|
|
title: "New Title",
|
|
|
|
body: "New Body",
|
|
|
|
bodyPrefix: "New Body Prefix -",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: ["user3", "user4"],
|
|
|
|
inheritReviewers: false,
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: ["custom-label", "backport prod"], // also include the one inherited
|
2023-07-10 08:49:11 +02:00
|
|
|
inheritLabels: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
|
|
|
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
2024-04-08 18:51:13 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
|
|
|
2023-07-10 08:49:11 +02:00
|
|
|
expect(configs.dryRun).toEqual(false);
|
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "Me",
|
|
|
|
email: "me@email.com"
|
|
|
|
});
|
|
|
|
expect(configs.auth).toEqual("");
|
|
|
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
|
|
expect(configs.originalPullRequest).toEqual({
|
|
|
|
number: 2368,
|
|
|
|
author: "gh-user",
|
|
|
|
url: "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
|
|
htmlUrl: "https://github.com/owner/reponame/pull/2368",
|
|
|
|
state: "closed",
|
|
|
|
merged: true,
|
|
|
|
mergedBy: "that-s-a-user",
|
|
|
|
title: "PR Title",
|
|
|
|
body: "Please review and merge",
|
|
|
|
reviewers: ["requested-gh-user", "gh-user"],
|
|
|
|
assignees: [],
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: ["backport prod"],
|
2023-07-10 08:49:11 +02:00
|
|
|
targetRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
sourceRepo: {
|
|
|
|
owner: "fork",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
|
|
},
|
|
|
|
bpBranchName: undefined,
|
|
|
|
nCommits: 2,
|
|
|
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
|
|
|
});
|
2023-08-03 21:57:11 +02:00
|
|
|
expect(configs.backportPullRequests.length).toEqual(1);
|
|
|
|
expect(configs.backportPullRequests[0]).toEqual({
|
2023-07-27 11:26:39 +02:00
|
|
|
owner: "owner",
|
|
|
|
repo: "reponame",
|
|
|
|
head: "bp-prod-28f63db",
|
|
|
|
base: "prod",
|
2023-07-10 08:49:11 +02:00
|
|
|
title: "New Title",
|
|
|
|
body: "New Body Prefix -New Body",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: ["user3", "user4"],
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: ["custom-label", "backport prod"],
|
2023-07-27 11:26:39 +02:00
|
|
|
comments: [],
|
2023-06-20 22:29:52 +02:00
|
|
|
});
|
|
|
|
});
|
2023-07-05 22:11:23 +02:00
|
|
|
|
|
|
|
test("using simple config file", async () => {
|
|
|
|
addProcessArgs([
|
|
|
|
"-cf",
|
|
|
|
GITHUB_MERGED_PR_SIMPLE_CONFIG_FILE_CONTENT_PATHNAME,
|
|
|
|
]);
|
|
|
|
|
|
|
|
const args: Args = argsParser.parse();
|
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
|
|
|
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
|
|
|
2023-07-05 22:11:23 +02:00
|
|
|
expect(configs.dryRun).toEqual(false);
|
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "GitHub",
|
|
|
|
email: "noreply@github.com"
|
|
|
|
});
|
|
|
|
expect(configs.auth).toEqual(undefined);
|
|
|
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
|
|
expect(configs.originalPullRequest).toEqual({
|
|
|
|
number: 2368,
|
|
|
|
author: "gh-user",
|
|
|
|
url: "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
|
|
htmlUrl: "https://github.com/owner/reponame/pull/2368",
|
|
|
|
state: "closed",
|
|
|
|
merged: true,
|
|
|
|
mergedBy: "that-s-a-user",
|
|
|
|
title: "PR Title",
|
|
|
|
body: "Please review and merge",
|
|
|
|
reviewers: ["requested-gh-user", "gh-user"],
|
|
|
|
assignees: [],
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: ["backport prod"],
|
2023-07-05 22:11:23 +02:00
|
|
|
targetRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
sourceRepo: {
|
|
|
|
owner: "fork",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
|
|
},
|
|
|
|
nCommits: 2,
|
|
|
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]
|
|
|
|
});
|
2023-08-03 21:57:11 +02:00
|
|
|
expect(configs.backportPullRequests.length).toEqual(1);
|
|
|
|
expect(configs.backportPullRequests[0]).toEqual({
|
2023-07-27 11:26:39 +02:00
|
|
|
owner: "owner",
|
|
|
|
repo: "reponame",
|
|
|
|
head: "bp-prod-28f63db",
|
|
|
|
base: "prod",
|
2023-07-05 22:11:23 +02:00
|
|
|
title: "[prod] PR Title",
|
|
|
|
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
|
|
|
reviewers: ["gh-user", "that-s-a-user"],
|
|
|
|
assignees: [],
|
2023-07-10 08:49:11 +02:00
|
|
|
labels: [],
|
2023-07-27 11:26:39 +02:00
|
|
|
comments: [],
|
2023-07-05 22:11:23 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("using complex config file", async () => {
|
|
|
|
addProcessArgs([
|
|
|
|
"-cf",
|
|
|
|
GITHUB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT_PATHNAME,
|
|
|
|
]);
|
|
|
|
|
|
|
|
const args: Args = argsParser.parse();
|
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
|
|
|
|
2023-07-11 11:22:01 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
|
|
|
2023-07-05 22:11:23 +02:00
|
|
|
expect(configs.dryRun).toEqual(false);
|
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "Me",
|
|
|
|
email: "me@email.com"
|
|
|
|
});
|
|
|
|
expect(configs.auth).toEqual("my-auth-token");
|
|
|
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
|
|
expect(configs.originalPullRequest).toEqual({
|
|
|
|
number: 2368,
|
|
|
|
author: "gh-user",
|
|
|
|
url: "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
|
|
htmlUrl: "https://github.com/owner/reponame/pull/2368",
|
|
|
|
state: "closed",
|
|
|
|
merged: true,
|
|
|
|
mergedBy: "that-s-a-user",
|
|
|
|
title: "PR Title",
|
|
|
|
body: "Please review and merge",
|
|
|
|
reviewers: ["requested-gh-user", "gh-user"],
|
|
|
|
assignees: [],
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: ["backport prod"],
|
2023-07-05 22:11:23 +02:00
|
|
|
targetRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
sourceRepo: {
|
|
|
|
owner: "fork",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
|
|
},
|
|
|
|
bpBranchName: undefined,
|
|
|
|
nCommits: 2,
|
|
|
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
|
|
|
});
|
2023-08-03 21:57:11 +02:00
|
|
|
expect(configs.backportPullRequests.length).toEqual(1);
|
|
|
|
expect(configs.backportPullRequests[0]).toEqual({
|
2023-07-27 11:26:39 +02:00
|
|
|
owner: "owner",
|
|
|
|
repo: "reponame",
|
|
|
|
head: "bp-prod-28f63db",
|
|
|
|
base: "prod",
|
2023-07-05 22:11:23 +02:00
|
|
|
title: "New Title",
|
|
|
|
body: "New Body Prefix -New Body",
|
|
|
|
reviewers: ["user1", "user2"],
|
|
|
|
assignees: ["user3", "user4"],
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: ["cherry-pick :cherries:", "backport prod"],
|
2023-07-27 11:26:39 +02:00
|
|
|
comments: [],
|
2023-07-05 22:11:23 +02:00
|
|
|
});
|
|
|
|
});
|
2023-07-11 11:22:01 +02:00
|
|
|
|
|
|
|
test("parse configs from pull request without squashing with multiple commits", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: false,
|
|
|
|
auth: "",
|
|
|
|
pullRequest: multipleCommitsPRUrl,
|
|
|
|
targetBranch: "prod",
|
|
|
|
gitUser: "GitHub",
|
|
|
|
gitEmail: "noreply@github.com",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: [],
|
|
|
|
inheritReviewers: true,
|
|
|
|
squash: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
|
|
|
|
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 8632, false);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]);
|
|
|
|
|
|
|
|
expect(configs.dryRun).toEqual(false);
|
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "GitHub",
|
|
|
|
email: "noreply@github.com"
|
|
|
|
});
|
|
|
|
expect(configs.auth).toEqual("");
|
|
|
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
|
|
expect(configs.originalPullRequest).toEqual({
|
|
|
|
number: 8632,
|
|
|
|
author: "gh-user",
|
|
|
|
url: "https://api.github.com/repos/owner/reponame/pulls/8632",
|
|
|
|
htmlUrl: "https://github.com/owner/reponame/pull/8632",
|
|
|
|
state: "closed",
|
|
|
|
merged: true,
|
|
|
|
mergedBy: "that-s-a-user",
|
|
|
|
title: "PR Title",
|
|
|
|
body: "Please review and merge",
|
|
|
|
reviewers: ["requested-gh-user", "gh-user"],
|
|
|
|
assignees: [],
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: [
|
|
|
|
"backport v1",
|
|
|
|
"backport v2",
|
|
|
|
"backport v3",
|
|
|
|
],
|
2023-07-11 11:22:01 +02:00
|
|
|
targetRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
sourceRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
nCommits: 2,
|
|
|
|
commits: ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]
|
|
|
|
});
|
2023-08-03 21:57:11 +02:00
|
|
|
expect(configs.backportPullRequests.length).toEqual(1);
|
|
|
|
expect(configs.backportPullRequests[0]).toEqual({
|
2023-07-27 11:26:39 +02:00
|
|
|
owner: "owner",
|
|
|
|
repo: "reponame",
|
|
|
|
head: "bp-prod-0404fb9-11da4e3",
|
|
|
|
base: "prod",
|
2023-07-11 11:22:01 +02:00
|
|
|
title: "[prod] PR Title",
|
|
|
|
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
|
|
|
|
reviewers: ["gh-user", "that-s-a-user"],
|
|
|
|
assignees: [],
|
|
|
|
labels: [],
|
2023-07-27 11:26:39 +02:00
|
|
|
comments: [],
|
2023-07-11 11:22:01 +02:00
|
|
|
});
|
|
|
|
});
|
2023-07-27 12:31:04 +02:00
|
|
|
|
|
|
|
test("override backport pr with additional comments", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: false,
|
|
|
|
auth: "",
|
|
|
|
pullRequest: mergedPRUrl,
|
|
|
|
targetBranch: "prod",
|
|
|
|
gitUser: "Me",
|
|
|
|
gitEmail: "me@email.com",
|
|
|
|
title: "New Title",
|
|
|
|
body: "New Body",
|
|
|
|
bodyPrefix: "New Body Prefix -",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: ["user3", "user4"],
|
|
|
|
inheritReviewers: false,
|
|
|
|
labels: [],
|
|
|
|
inheritLabels: false,
|
|
|
|
comments: ["First comment", "Second comment"],
|
|
|
|
};
|
|
|
|
|
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
|
|
|
|
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
2024-04-08 18:51:13 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
2023-07-27 12:31:04 +02:00
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
|
|
|
|
|
|
expect(configs.dryRun).toEqual(false);
|
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "Me",
|
|
|
|
email: "me@email.com"
|
|
|
|
});
|
|
|
|
expect(configs.auth).toEqual("");
|
|
|
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
|
|
expect(configs.originalPullRequest).toEqual({
|
|
|
|
number: 2368,
|
|
|
|
author: "gh-user",
|
|
|
|
url: "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
|
|
htmlUrl: "https://github.com/owner/reponame/pull/2368",
|
|
|
|
state: "closed",
|
|
|
|
merged: true,
|
|
|
|
mergedBy: "that-s-a-user",
|
|
|
|
title: "PR Title",
|
|
|
|
body: "Please review and merge",
|
|
|
|
reviewers: ["requested-gh-user", "gh-user"],
|
|
|
|
assignees: [],
|
2024-03-30 19:19:17 +01:00
|
|
|
labels: ["backport prod"],
|
|
|
|
targetRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
sourceRepo: {
|
|
|
|
owner: "fork",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
|
|
},
|
|
|
|
bpBranchName: undefined,
|
|
|
|
nCommits: 2,
|
|
|
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
|
|
|
});
|
|
|
|
expect(configs.backportPullRequests.length).toEqual(1);
|
|
|
|
expect(configs.backportPullRequests[0]).toEqual({
|
|
|
|
owner: "owner",
|
|
|
|
repo: "reponame",
|
|
|
|
head: "bp-prod-28f63db",
|
|
|
|
base: "prod",
|
|
|
|
title: "New Title",
|
|
|
|
body: "New Body Prefix -New Body",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: ["user3", "user4"],
|
|
|
|
labels: [],
|
|
|
|
comments: ["First comment", "Second comment"],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("no extracted target branches from pr labels due to wrong group name", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: false,
|
|
|
|
auth: "",
|
|
|
|
pullRequest: mergedPRUrl,
|
|
|
|
targetBranchPattern: "^backport (?<wrong>([^ ]+))$",
|
|
|
|
gitUser: "Me",
|
|
|
|
gitEmail: "me@email.com",
|
|
|
|
title: "New Title",
|
|
|
|
body: "New Body",
|
|
|
|
bodyPrefix: "New Body Prefix -",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: ["user3", "user4"],
|
|
|
|
inheritReviewers: false,
|
|
|
|
labels: [],
|
|
|
|
inheritLabels: false,
|
|
|
|
comments: ["First comment", "Second comment"],
|
|
|
|
};
|
|
|
|
|
|
|
|
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("Unable to extract target branches with regular expression");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("extract target branches from pr labels", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: false,
|
|
|
|
auth: "",
|
|
|
|
pullRequest: mergedPRUrl,
|
|
|
|
targetBranchPattern: "^backport (?<target>([^ ]+))$",
|
|
|
|
gitUser: "Me",
|
|
|
|
gitEmail: "me@email.com",
|
|
|
|
title: "New Title",
|
|
|
|
body: "New Body",
|
|
|
|
bodyPrefix: "New Body Prefix -",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: ["user3", "user4"],
|
|
|
|
inheritReviewers: false,
|
|
|
|
labels: [],
|
|
|
|
inheritLabels: false,
|
|
|
|
comments: ["First comment", "Second comment"],
|
|
|
|
};
|
|
|
|
|
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
|
|
|
|
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
2024-04-08 18:51:13 +02:00
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
2024-03-30 19:19:17 +01:00
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
|
|
|
|
|
|
expect(configs.dryRun).toEqual(false);
|
|
|
|
expect(configs.git).toEqual({
|
|
|
|
user: "Me",
|
|
|
|
email: "me@email.com"
|
|
|
|
});
|
|
|
|
expect(configs.auth).toEqual("");
|
|
|
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
|
|
expect(configs.originalPullRequest).toEqual({
|
|
|
|
number: 2368,
|
|
|
|
author: "gh-user",
|
|
|
|
url: "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
|
|
htmlUrl: "https://github.com/owner/reponame/pull/2368",
|
|
|
|
state: "closed",
|
|
|
|
merged: true,
|
|
|
|
mergedBy: "that-s-a-user",
|
|
|
|
title: "PR Title",
|
|
|
|
body: "Please review and merge",
|
|
|
|
reviewers: ["requested-gh-user", "gh-user"],
|
|
|
|
assignees: [],
|
|
|
|
labels: ["backport prod"],
|
2023-07-27 12:31:04 +02:00
|
|
|
targetRepo: {
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
},
|
|
|
|
sourceRepo: {
|
|
|
|
owner: "fork",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
|
|
},
|
|
|
|
bpBranchName: undefined,
|
|
|
|
nCommits: 2,
|
|
|
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
|
|
|
});
|
2023-08-03 21:57:11 +02:00
|
|
|
expect(configs.backportPullRequests.length).toEqual(1);
|
|
|
|
expect(configs.backportPullRequests[0]).toEqual({
|
2023-07-27 12:31:04 +02:00
|
|
|
owner: "owner",
|
|
|
|
repo: "reponame",
|
|
|
|
head: "bp-prod-28f63db",
|
|
|
|
base: "prod",
|
|
|
|
title: "New Title",
|
|
|
|
body: "New Body Prefix -New Body",
|
|
|
|
reviewers: [],
|
|
|
|
assignees: ["user3", "user4"],
|
|
|
|
labels: [],
|
|
|
|
comments: ["First comment", "Second comment"],
|
|
|
|
});
|
|
|
|
});
|
2024-04-10 23:01:16 +02:00
|
|
|
|
|
|
|
test("enable error notification message", async () => {
|
|
|
|
const args: Args = {
|
|
|
|
dryRun: false,
|
|
|
|
auth: "",
|
|
|
|
pullRequest: mergedPRUrl,
|
|
|
|
targetBranch: "prod",
|
|
|
|
enableErrorNotification: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
const configs: Configs = await configParser.parseAndValidate(args);
|
|
|
|
|
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
|
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
|
|
|
|
|
|
expect(configs.errorNotification).toEqual({
|
|
|
|
"enabled": true,
|
|
|
|
"message": "The backport to `{{target-branch}}` failed. Check the latest run for more details."
|
|
|
|
});
|
|
|
|
});
|
2023-01-05 11:41:14 +01:00
|
|
|
});
|