mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-06-27 21:23:48 +00:00
feat(issue-77): handle multiple target branches (#78)
fix: https://github.com/kiegroup/git-backporting/issues/77 This enhancement allow users to backport the same change to multiple branches with one single tool invocation
This commit is contained in:
parent
c19a56a9ad
commit
5fc72e127b
25 changed files with 1774 additions and 234 deletions
|
@ -433,4 +433,63 @@ describe("cli args parser", () => {
|
|||
expect(args.squash).toEqual(true);
|
||||
expectArrayEqual(args.comments!,["first comment", "second comment"]);
|
||||
});
|
||||
|
||||
test("valid execution with multiple branches", () => {
|
||||
addProcessArgs([
|
||||
"-tb",
|
||||
"target, old",
|
||||
"-pr",
|
||||
"https://localhost/whatever/pulls/1"
|
||||
]);
|
||||
|
||||
const args: Args = parser.parse();
|
||||
expect(args.dryRun).toEqual(false);
|
||||
expect(args.auth).toEqual(undefined);
|
||||
expect(args.gitUser).toEqual(undefined);
|
||||
expect(args.gitEmail).toEqual(undefined);
|
||||
expect(args.folder).toEqual(undefined);
|
||||
expect(args.targetBranch).toEqual("target, old");
|
||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
||||
expect(args.title).toEqual(undefined);
|
||||
expect(args.body).toEqual(undefined);
|
||||
expect(args.bodyPrefix).toEqual(undefined);
|
||||
expect(args.bpBranchName).toEqual(undefined);
|
||||
expect(args.reviewers).toEqual([]);
|
||||
expect(args.assignees).toEqual([]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expect(args.labels).toEqual([]);
|
||||
expect(args.inheritLabels).toEqual(false);
|
||||
expect(args.squash).toEqual(true);
|
||||
expect(args.strategy).toEqual(undefined);
|
||||
expect(args.strategyOption).toEqual(undefined);
|
||||
});
|
||||
|
||||
test("invalid execution with empty target branch", () => {
|
||||
addProcessArgs([
|
||||
"-tb",
|
||||
" ",
|
||||
"-pr",
|
||||
"https://localhost/whatever/pulls/1"
|
||||
]);
|
||||
|
||||
expect(() => parser.parse()).toThrowError("Missing option: pull request and target branches must be provided");
|
||||
});
|
||||
|
||||
test("invalid execution with missing mandatory target branch", () => {
|
||||
addProcessArgs([
|
||||
"-pr",
|
||||
"https://localhost/whatever/pulls/1"
|
||||
]);
|
||||
|
||||
expect(() => parser.parse()).toThrowError("Missing option: pull request and target branches must be provided");
|
||||
});
|
||||
|
||||
test("invalid execution with missin mandatory pull request", () => {
|
||||
addProcessArgs([
|
||||
"-tb",
|
||||
"target",
|
||||
]);
|
||||
|
||||
expect(() => parser.parse()).toThrowError("Missing option: pull request and target branches must be provided");
|
||||
});
|
||||
});
|
|
@ -262,4 +262,56 @@ describe("gha args parser", () => {
|
|||
expect(args.squash).toEqual(true);
|
||||
expectArrayEqual(args.comments!,["first comment", "second comment"]);
|
||||
});
|
||||
|
||||
test("valid execution with multiple branches", () => {
|
||||
spyGetInput({
|
||||
"target-branch": "target,old",
|
||||
"pull-request": "https://localhost/whatever/pulls/1"
|
||||
});
|
||||
|
||||
const args: Args = parser.parse();
|
||||
expect(args.dryRun).toEqual(false);
|
||||
expect(args.auth).toEqual(undefined);
|
||||
expect(args.gitUser).toEqual(undefined);
|
||||
expect(args.gitEmail).toEqual(undefined);
|
||||
expect(args.folder).toEqual(undefined);
|
||||
expect(args.targetBranch).toEqual("target,old");
|
||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
||||
expect(args.title).toEqual(undefined);
|
||||
expect(args.body).toEqual(undefined);
|
||||
expect(args.reviewers).toEqual([]);
|
||||
expect(args.assignees).toEqual([]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expect(args.labels).toEqual([]);
|
||||
expect(args.inheritLabels).toEqual(false);
|
||||
expect(args.squash).toEqual(true);
|
||||
expect(args.strategy).toEqual(undefined);
|
||||
expect(args.strategyOption).toEqual(undefined);
|
||||
});
|
||||
|
||||
|
||||
test("invalid execution with empty target branch", () => {
|
||||
spyGetInput({
|
||||
"target-branch": " ",
|
||||
"pull-request": "https://localhost/whatever/pulls/1"
|
||||
});
|
||||
|
||||
expect(() => parser.parse()).toThrowError("Missing option: pull request and target branches must be provided");
|
||||
});
|
||||
|
||||
test("invalid execution with missing mandatory target branch", () => {
|
||||
spyGetInput({
|
||||
"pull-request": "https://localhost/whatever/pulls/1"
|
||||
});
|
||||
|
||||
expect(() => parser.parse()).toThrowError("Missing option: pull request and target branches must be provided");
|
||||
});
|
||||
|
||||
test("invalid execution with missin mandatory pull request", () => {
|
||||
spyGetInput({
|
||||
"target-branch": "target,old",
|
||||
});
|
||||
|
||||
expect(() => parser.parse()).toThrowError("Missing option: pull request and target branches must be provided");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,422 @@
|
|||
import { Args } from "@bp/service/args/args.types";
|
||||
import { Configs } from "@bp/service/configs/configs.types";
|
||||
import PullRequestConfigsParser from "@bp/service/configs/pullrequest/pr-configs-parser";
|
||||
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";
|
||||
import { resetProcessArgs } from "../../../support/utils";
|
||||
import { MERGED_PR_FIXTURE, REPO, TARGET_OWNER, MULT_COMMITS_PR_FIXTURE } from "../../../support/mock/github-data";
|
||||
import GitHubMapper from "@bp/service/git/github/github-mapper";
|
||||
import GitHubClient from "@bp/service/git/github/github-client";
|
||||
|
||||
jest.spyOn(GitHubMapper.prototype, "mapPullRequest");
|
||||
jest.spyOn(GitHubClient.prototype, "getPullRequest");
|
||||
|
||||
describe("github pull request config parser", () => {
|
||||
|
||||
const mergedPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MERGED_PR_FIXTURE.number}`;
|
||||
const multipleCommitsPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MULT_COMMITS_PR_FIXTURE.number}`;
|
||||
|
||||
let configParser: PullRequestConfigsParser;
|
||||
|
||||
beforeAll(() => {
|
||||
GitClientFactory.reset();
|
||||
GitClientFactory.getOrCreate(GitClientType.GITHUB, "whatever", "http://localhost/api/v3");
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
// reset process.env variables
|
||||
resetProcessArgs();
|
||||
|
||||
// mock octokit
|
||||
mockGitHubClient("http://localhost/api/v3");
|
||||
|
||||
// create a fresh new instance every time
|
||||
configParser = new PullRequestConfigsParser();
|
||||
});
|
||||
|
||||
test("multiple backports", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "v1, v2, v3",
|
||||
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: [],
|
||||
};
|
||||
|
||||
const configs: Configs = await configParser.parseAndValidate(args);
|
||||
|
||||
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(), []);
|
||||
|
||||
expect(configs.dryRun).toEqual(false);
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.backportPullRequests.length).toEqual(3);
|
||||
expect(configs.backportPullRequests).toEqual(
|
||||
expect.arrayContaining([
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v1-28f63db",
|
||||
base: "v1",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v2-28f63db",
|
||||
base: "v2",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v3-28f63db",
|
||||
base: "v3",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test("multiple backports ignore duplicates", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "v1, v2, v2, v3",
|
||||
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: [],
|
||||
};
|
||||
|
||||
const configs: Configs = await configParser.parseAndValidate(args);
|
||||
|
||||
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(), []);
|
||||
|
||||
expect(configs.dryRun).toEqual(false);
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.backportPullRequests.length).toEqual(3);
|
||||
expect(configs.backportPullRequests).toEqual(
|
||||
expect.arrayContaining([
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v1-28f63db",
|
||||
base: "v1",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v2-28f63db",
|
||||
base: "v2",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v3-28f63db",
|
||||
base: "v3",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test("multiple backports with custom branch name", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "v1, v2, v3",
|
||||
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: [],
|
||||
bpBranchName: "custom-branch",
|
||||
};
|
||||
|
||||
const configs: Configs = await configParser.parseAndValidate(args);
|
||||
|
||||
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(), []);
|
||||
|
||||
expect(configs.dryRun).toEqual(false);
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.backportPullRequests.length).toEqual(3);
|
||||
expect(configs.backportPullRequests).toEqual(
|
||||
expect.arrayContaining([
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-branch-v1",
|
||||
base: "v1",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-branch-v2",
|
||||
base: "v2",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-branch-v3",
|
||||
base: "v3",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test("multiple backports with multiple custom branch names", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "v1, v2, v3",
|
||||
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: [],
|
||||
bpBranchName: "custom-branch1, custom-branch2, custom-branch3",
|
||||
};
|
||||
|
||||
const configs: Configs = await configParser.parseAndValidate(args);
|
||||
|
||||
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(), []);
|
||||
|
||||
expect(configs.dryRun).toEqual(false);
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.backportPullRequests.length).toEqual(3);
|
||||
expect(configs.backportPullRequests).toEqual(
|
||||
expect.arrayContaining([
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-branch1",
|
||||
base: "v1",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-branch2",
|
||||
base: "v2",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-branch3",
|
||||
base: "v3",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test("multiple backports with incorrect number of bp branch names", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "v1, v2, v3",
|
||||
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: [],
|
||||
bpBranchName: "custom-branch1, custom-branch2",
|
||||
};
|
||||
|
||||
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("The number of backport branch names, if provided, must match the number of target branches or just one, provided 2 branch names instead");
|
||||
});
|
||||
|
||||
test("multiple backports and multiple commits", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: multipleCommitsPRUrl,
|
||||
targetBranch: "v1, v2, v3",
|
||||
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.backportPullRequests.length).toEqual(3);
|
||||
expect(configs.backportPullRequests).toEqual(
|
||||
expect.arrayContaining([
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v1-0404fb9-11da4e3",
|
||||
base: "v1",
|
||||
title: "[v1] 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: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v2-0404fb9-11da4e3",
|
||||
base: "v2",
|
||||
title: "[v2] 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: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v3-0404fb9-11da4e3",
|
||||
base: "v3",
|
||||
title: "[v3] 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: [],
|
||||
comments: [],
|
||||
},
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
});
|
|
@ -5,7 +5,7 @@ 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";
|
||||
import { addProcessArgs, createTestFile, removeTestFile, resetProcessArgs } from "../../../support/utils";
|
||||
import { mergedPullRequestFixture, openPullRequestFixture, notMergedPullRequestFixture, repo, targetOwner, multipleCommitsPullRequestFixture } from "../../../support/mock/github-data";
|
||||
import { MERGED_PR_FIXTURE, OPEN_PR_FIXTURE, NOT_MERGED_PR_FIXTURE, REPO, TARGET_OWNER, MULT_COMMITS_PR_FIXTURE } from "../../../support/mock/github-data";
|
||||
import CLIArgsParser from "@bp/service/args/cli/cli-args-parser";
|
||||
import GitHubMapper from "@bp/service/git/github/github-mapper";
|
||||
import GitHubClient from "@bp/service/git/github/github-client";
|
||||
|
@ -13,14 +13,14 @@ import GitHubClient from "@bp/service/git/github/github-client";
|
|||
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",
|
||||
"pullRequest": `https://github.com/${targetOwner}/${repo}/pull/${mergedPullRequestFixture.number}`,
|
||||
"pullRequest": `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MERGED_PR_FIXTURE.number}`,
|
||||
};
|
||||
|
||||
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",
|
||||
"pullRequest": `https://github.com/${targetOwner}/${repo}/pull/${mergedPullRequestFixture.number}`,
|
||||
"pullRequest": `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MERGED_PR_FIXTURE.number}`,
|
||||
"targetBranch": "prod",
|
||||
"gitUser": "Me",
|
||||
"gitEmail": "me@email.com",
|
||||
|
@ -39,10 +39,10 @@ jest.spyOn(GitHubClient.prototype, "getPullRequest");
|
|||
|
||||
describe("github pull request config parser", () => {
|
||||
|
||||
const mergedPRUrl = `https://github.com/${targetOwner}/${repo}/pull/${mergedPullRequestFixture.number}`;
|
||||
const openPRUrl = `https://github.com/${targetOwner}/${repo}/pull/${openPullRequestFixture.number}`;
|
||||
const notMergedPRUrl = `https://github.com/${targetOwner}/${repo}/pull/${notMergedPullRequestFixture.number}`;
|
||||
const multipleCommitsPRUrl = `https://github.com/${targetOwner}/${repo}/pull/${multipleCommitsPullRequestFixture.number}`;
|
||||
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}`;
|
||||
|
||||
let argsParser: CLIArgsParser;
|
||||
let configParser: PullRequestConfigsParser;
|
||||
|
@ -100,7 +100,6 @@ describe("github pull request config parser", () => {
|
|||
email: "noreply@github.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 2368,
|
||||
|
@ -128,7 +127,8 @@ describe("github pull request config parser", () => {
|
|||
nCommits: 2,
|
||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-prod-28f63db",
|
||||
|
@ -160,7 +160,6 @@ describe("github pull request config parser", () => {
|
|||
|
||||
expect(configs.dryRun).toEqual(true);
|
||||
expect(configs.auth).toEqual("whatever");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual("/tmp/test");
|
||||
expect(configs.git).toEqual({
|
||||
user: "GitHub",
|
||||
|
@ -190,7 +189,6 @@ describe("github pull request config parser", () => {
|
|||
|
||||
expect(configs.dryRun).toEqual(true);
|
||||
expect(configs.auth).toEqual("whatever");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.git).toEqual({
|
||||
user: "GitHub",
|
||||
email: "noreply@github.com"
|
||||
|
@ -271,7 +269,6 @@ describe("github pull request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 2368,
|
||||
|
@ -300,7 +297,8 @@ describe("github pull request config parser", () => {
|
|||
nCommits: 2,
|
||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-branch",
|
||||
|
@ -314,6 +312,48 @@ describe("github pull request config parser", () => {
|
|||
});
|
||||
});
|
||||
|
||||
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);
|
||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
|
||||
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: [],
|
||||
});
|
||||
});
|
||||
|
||||
test("override backport pr reviewers and assignees", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
|
@ -343,7 +383,6 @@ describe("github pull request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 2368,
|
||||
|
@ -372,7 +411,8 @@ describe("github pull request config parser", () => {
|
|||
nCommits: 2,
|
||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-prod-28f63db",
|
||||
|
@ -415,7 +455,6 @@ describe("github pull request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 2368,
|
||||
|
@ -444,7 +483,8 @@ describe("github pull request config parser", () => {
|
|||
nCommits: 2,
|
||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-prod-28f63db",
|
||||
|
@ -489,7 +529,6 @@ describe("github pull request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 2368,
|
||||
|
@ -518,7 +557,8 @@ describe("github pull request config parser", () => {
|
|||
nCommits: 2,
|
||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-prod-28f63db",
|
||||
|
@ -552,7 +592,6 @@ describe("github pull request config parser", () => {
|
|||
email: "noreply@github.com"
|
||||
});
|
||||
expect(configs.auth).toEqual(undefined);
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 2368,
|
||||
|
@ -580,7 +619,8 @@ describe("github pull request config parser", () => {
|
|||
nCommits: 2,
|
||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-prod-28f63db",
|
||||
|
@ -614,7 +654,6 @@ describe("github pull request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("my-auth-token");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 2368,
|
||||
|
@ -643,7 +682,8 @@ describe("github pull request config parser", () => {
|
|||
nCommits: 2,
|
||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-prod-28f63db",
|
||||
|
@ -684,7 +724,6 @@ describe("github pull request config parser", () => {
|
|||
email: "noreply@github.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 8632,
|
||||
|
@ -712,7 +751,8 @@ describe("github pull request config parser", () => {
|
|||
nCommits: 2,
|
||||
commits: ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-prod-0404fb9-11da4e3",
|
||||
|
@ -758,7 +798,6 @@ describe("github pull request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 2368,
|
||||
|
@ -787,7 +826,8 @@ describe("github pull request config parser", () => {
|
|||
nCommits: 2,
|
||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-prod-28f63db",
|
||||
|
|
|
@ -0,0 +1,349 @@
|
|||
import { Args } from "@bp/service/args/args.types";
|
||||
import { Configs } from "@bp/service/configs/configs.types";
|
||||
import PullRequestConfigsParser from "@bp/service/configs/pullrequest/pr-configs-parser";
|
||||
import GitClientFactory from "@bp/service/git/git-client-factory";
|
||||
import { GitClientType } from "@bp/service/git/git.types";
|
||||
import { getAxiosMocked } from "../../../support/mock/git-client-mock-support";
|
||||
import { MERGED_SQUASHED_MR } from "../../../support/mock/gitlab-data";
|
||||
import GitLabClient from "@bp/service/git/gitlab/gitlab-client";
|
||||
import GitLabMapper from "@bp/service/git/gitlab/gitlab-mapper";
|
||||
|
||||
jest.spyOn(GitLabMapper.prototype, "mapPullRequest");
|
||||
jest.spyOn(GitLabClient.prototype, "getPullRequest");
|
||||
|
||||
jest.mock("axios", () => {
|
||||
return {
|
||||
create: jest.fn(() => ({
|
||||
get: getAxiosMocked,
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
describe("gitlab merge request config parser", () => {
|
||||
|
||||
const mergedPRUrl = `https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/${MERGED_SQUASHED_MR.iid}`;
|
||||
|
||||
let configParser: PullRequestConfigsParser;
|
||||
|
||||
beforeAll(() => {
|
||||
GitClientFactory.reset();
|
||||
GitClientFactory.getOrCreate(GitClientType.GITLAB, "whatever", "my.gitlab.host.com");
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
configParser = new PullRequestConfigsParser();
|
||||
});
|
||||
|
||||
test("multiple backports", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "v1, v2, v3",
|
||||
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: [],
|
||||
};
|
||||
|
||||
const configs: Configs = await configParser.parseAndValidate(args);
|
||||
|
||||
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
|
||||
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabMapper.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(3);
|
||||
expect(configs.backportPullRequests).toEqual(
|
||||
expect.arrayContaining([
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-v1-ebb1eca",
|
||||
base: "v1",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-v2-ebb1eca",
|
||||
base: "v2",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-v3-ebb1eca",
|
||||
base: "v3",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
}
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test("multiple backports ignore duplicates", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "v1, v2, v3, v1",
|
||||
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: [],
|
||||
};
|
||||
|
||||
const configs: Configs = await configParser.parseAndValidate(args);
|
||||
|
||||
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
|
||||
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabMapper.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(3);
|
||||
expect(configs.backportPullRequests).toEqual(
|
||||
expect.arrayContaining([
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-v1-ebb1eca",
|
||||
base: "v1",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-v2-ebb1eca",
|
||||
base: "v2",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-v3-ebb1eca",
|
||||
base: "v3",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
}
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test("multiple backports with custom branch name", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "v1, v2, v3",
|
||||
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: [],
|
||||
bpBranchName: "custom-branch"
|
||||
};
|
||||
|
||||
const configs: Configs = await configParser.parseAndValidate(args);
|
||||
|
||||
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
|
||||
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabMapper.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(3);
|
||||
expect(configs.backportPullRequests).toEqual(
|
||||
expect.arrayContaining([
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "custom-branch-v1",
|
||||
base: "v1",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "custom-branch-v2",
|
||||
base: "v2",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "custom-branch-v3",
|
||||
base: "v3",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
}
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test("multiple backports with multiple custom branch names", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "v1, v2, v3",
|
||||
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: [],
|
||||
bpBranchName: "custom1, custom2, custom3"
|
||||
};
|
||||
|
||||
const configs: Configs = await configParser.parseAndValidate(args);
|
||||
|
||||
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
|
||||
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabMapper.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(3);
|
||||
expect(configs.backportPullRequests).toEqual(
|
||||
expect.arrayContaining([
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "custom1",
|
||||
base: "v1",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "custom2",
|
||||
base: "v2",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "custom3",
|
||||
base: "v3",
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
comments: [],
|
||||
}
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test("multiple backports with incorrect number of bp branch names", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "v1, v2, v3",
|
||||
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: [],
|
||||
bpBranchName: "custom-branch1, custom-branch2, custom-branch2, custom-branch3, custom-branch4",
|
||||
};
|
||||
|
||||
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("The number of backport branch names, if provided, must match the number of target branches or just one, provided 4 branch names instead");
|
||||
});
|
||||
});
|
|
@ -100,7 +100,6 @@ describe("gitlab merge request config parser", () => {
|
|||
email: "noreply@gitlab.com"
|
||||
});
|
||||
expect(configs.auth).toEqual(undefined);
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 1,
|
||||
|
@ -128,7 +127,8 @@ describe("gitlab merge request config parser", () => {
|
|||
nCommits: 1,
|
||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-prod-ebb1eca",
|
||||
|
@ -166,7 +166,6 @@ describe("gitlab merge request config parser", () => {
|
|||
|
||||
expect(configs.dryRun).toEqual(true);
|
||||
expect(configs.auth).toEqual("whatever");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual("/tmp/test");
|
||||
expect(configs.git).toEqual({
|
||||
user: "Gitlab",
|
||||
|
@ -196,7 +195,6 @@ describe("gitlab merge request config parser", () => {
|
|||
|
||||
expect(configs.dryRun).toEqual(true);
|
||||
expect(configs.auth).toEqual("whatever");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.git).toEqual({
|
||||
user: "Gitlab",
|
||||
email: "noreply@gitlab.com"
|
||||
|
@ -276,7 +274,6 @@ describe("gitlab merge request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 1,
|
||||
|
@ -304,7 +301,8 @@ describe("gitlab merge request config parser", () => {
|
|||
nCommits: 1,
|
||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-prod-ebb1eca",
|
||||
|
@ -347,7 +345,6 @@ describe("gitlab merge request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 1,
|
||||
|
@ -375,7 +372,8 @@ describe("gitlab merge request config parser", () => {
|
|||
nCommits: 1,
|
||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-prod-ebb1eca",
|
||||
|
@ -418,7 +416,6 @@ describe("gitlab merge request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 1,
|
||||
|
@ -446,7 +443,8 @@ describe("gitlab merge request config parser", () => {
|
|||
nCommits: 1,
|
||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-prod-ebb1eca",
|
||||
|
@ -491,7 +489,6 @@ describe("gitlab merge request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 1,
|
||||
|
@ -519,7 +516,8 @@ describe("gitlab merge request config parser", () => {
|
|||
nCommits: 1,
|
||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-prod-ebb1eca",
|
||||
|
@ -552,7 +550,6 @@ describe("gitlab merge request config parser", () => {
|
|||
email: "noreply@gitlab.com"
|
||||
});
|
||||
expect(configs.auth).toEqual(undefined);
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 1,
|
||||
|
@ -580,7 +577,8 @@ describe("gitlab merge request config parser", () => {
|
|||
nCommits: 1,
|
||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-prod-ebb1eca",
|
||||
|
@ -613,7 +611,6 @@ describe("gitlab merge request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("my-token");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 1,
|
||||
|
@ -641,7 +638,8 @@ describe("gitlab merge request config parser", () => {
|
|||
nCommits: 1,
|
||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-prod-ebb1eca",
|
||||
|
@ -678,7 +676,6 @@ describe("gitlab merge request config parser", () => {
|
|||
|
||||
expect(configs.dryRun).toEqual(true);
|
||||
expect(configs.auth).toEqual("whatever");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.git).toEqual({
|
||||
user: "Gitlab",
|
||||
email: "noreply@gitlab.com"
|
||||
|
@ -710,7 +707,8 @@ describe("gitlab merge request config parser", () => {
|
|||
nCommits: 2,
|
||||
commits: ["e4dd336a4a20f394df6665994df382fb1d193a11", "974519f65c9e0ed65277cd71026657a09fca05e7"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-prod-e4dd336-974519f",
|
||||
|
@ -756,7 +754,6 @@ describe("gitlab merge request config parser", () => {
|
|||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 1,
|
||||
|
@ -784,7 +781,8 @@ describe("gitlab merge request config parser", () => {
|
|||
nCommits: 1,
|
||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
expect(configs.backportPullRequests.length).toEqual(1);
|
||||
expect(configs.backportPullRequests[0]).toEqual({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-prod-ebb1eca",
|
||||
|
|
|
@ -114,4 +114,13 @@ describe("git cli service", () => {
|
|||
const output = spawnSync("git", ["cherry", "-v"], { cwd }).stdout.toString();
|
||||
expect(output.includes(expressionToTest)).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
test("git clone on already created repo", async () => {
|
||||
await git.clone("remote", cwd, "tbranch");
|
||||
|
||||
// use rev-parse to double check the current branch is the expected one
|
||||
const post = spawnSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd }).stdout.toString().trim();
|
||||
expect(post).toEqual("tbranch");
|
||||
});
|
||||
});
|
|
@ -1,7 +1,7 @@
|
|||
import GitClientFactory from "@bp/service/git/git-client-factory";
|
||||
import { GitPullRequest, GitClientType } from "@bp/service/git/git.types";
|
||||
import GitHubClient from "@bp/service/git/github/github-client";
|
||||
import { mergedPullRequestFixture, repo, targetOwner } from "../../../support/mock/github-data";
|
||||
import { MERGED_PR_FIXTURE, REPO, TARGET_OWNER } from "../../../support/mock/github-data";
|
||||
import { mockGitHubClient } from "../../../support/mock/git-client-mock-support";
|
||||
|
||||
describe("github service", () => {
|
||||
|
@ -22,7 +22,7 @@ describe("github service", () => {
|
|||
});
|
||||
|
||||
test("get pull request: success", async () => {
|
||||
const res: GitPullRequest = await gitClient.getPullRequest(targetOwner, repo, mergedPullRequestFixture.number);
|
||||
const res: GitPullRequest = await gitClient.getPullRequest(TARGET_OWNER, REPO, MERGED_PR_FIXTURE.number);
|
||||
expect(res.sourceRepo).toEqual({
|
||||
owner: "fork",
|
||||
project: "reponame",
|
||||
|
|
|
@ -6,7 +6,7 @@ import CLIArgsParser from "@bp/service/args/cli/cli-args-parser";
|
|||
import { addProcessArgs, createTestFile, removeTestFile, resetProcessArgs } from "../../support/utils";
|
||||
import { mockGitHubClient } from "../../support/mock/git-client-mock-support";
|
||||
import GitClientFactory from "@bp/service/git/git-client-factory";
|
||||
import { GitClientType } from "@bp/service/git/git.types";
|
||||
import { BackportPullRequest, GitClientType } from "@bp/service/git/git.types";
|
||||
|
||||
const GITHUB_MERGED_PR_W_OVERRIDES_CONFIG_FILE_CONTENT_PATHNAME = "./cli-github-runner-pr-merged-with-overrides.json";
|
||||
const GITHUB_MERGED_PR_W_OVERRIDES_CONFIG_FILE_CONTENT = {
|
||||
|
@ -236,6 +236,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("same owner", async () => {
|
||||
|
@ -281,6 +282,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("closed and not merged pull request", async () => {
|
||||
|
@ -338,6 +340,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("override backporting pr data", async () => {
|
||||
|
@ -396,6 +399,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("set empty reviewers", async () => {
|
||||
|
@ -453,6 +457,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("set custom labels with inheritance", async () => {
|
||||
|
@ -502,6 +507,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("set custom labels without inheritance", async () => {
|
||||
|
@ -550,6 +556,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("using config file with overrides", async () => {
|
||||
|
@ -594,6 +601,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
// to check: https://github.com/kiegroup/git-backporting/issues/52
|
||||
|
@ -641,6 +649,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("multiple commits pr", async () => {
|
||||
|
@ -688,6 +697,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("too long bp branch name", async () => {
|
||||
|
@ -741,6 +751,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("multiple commits pr with different strategy", async () => {
|
||||
|
@ -792,6 +803,7 @@ describe("cli runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("additional pr comments", async () => {
|
||||
|
@ -841,5 +853,255 @@ describe("cli runner", () => {
|
|||
comments: ["first comment", "second comment"],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("with multiple target branches", async () => {
|
||||
addProcessArgs([
|
||||
"-tb",
|
||||
"v1, v2, v3",
|
||||
"-pr",
|
||||
"https://github.com/owner/reponame/pull/2368",
|
||||
"-f",
|
||||
"/tmp/folder"
|
||||
]);
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = "/tmp/folder";
|
||||
|
||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v1");
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v2");
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v3");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-v1-28f63db");
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-v2-28f63db");
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-v3-28f63db");
|
||||
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-v1-28f63db");
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-v2-28f63db");
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-v3-28f63db");
|
||||
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(3);
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v1-28f63db",
|
||||
base: "v1",
|
||||
title: "[v1] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v2-28f63db",
|
||||
base: "v2",
|
||||
title: "[v2] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v3-28f63db",
|
||||
base: "v3",
|
||||
title: "[v3] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(3);
|
||||
});
|
||||
|
||||
test("with multiple target branches and multiple bp names", async () => {
|
||||
addProcessArgs([
|
||||
"-tb",
|
||||
"v1, v2, v3",
|
||||
"-pr",
|
||||
"https://github.com/owner/reponame/pull/2368",
|
||||
"-f",
|
||||
"/tmp/folder",
|
||||
"--bp-branch-name",
|
||||
"custom1, custom1, custom2, custom3",
|
||||
]);
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = "/tmp/folder";
|
||||
|
||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v1");
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v2");
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v3");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom1");
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom2");
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom3");
|
||||
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom1");
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom2");
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom3");
|
||||
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(3);
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom1",
|
||||
base: "v1",
|
||||
title: "[v1] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom2",
|
||||
base: "v2",
|
||||
title: "[v2] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom3",
|
||||
base: "v3",
|
||||
title: "[v3] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(3);
|
||||
});
|
||||
|
||||
test("with multiple target branches and one failure", async () => {
|
||||
jest.spyOn(GitHubClient.prototype, "createPullRequest").mockImplementation((_backport: BackportPullRequest) => {
|
||||
|
||||
throw new Error("Mocked error");
|
||||
});
|
||||
|
||||
addProcessArgs([
|
||||
"-tb",
|
||||
"v1, v2, v3",
|
||||
"-pr",
|
||||
"https://github.com/owner/reponame/pull/2368",
|
||||
"-f",
|
||||
"/tmp/folder",
|
||||
"--bp-branch-name",
|
||||
"custom-failure-head",
|
||||
]);
|
||||
|
||||
await expect(() => runner.execute()).rejects.toThrowError("Failure occurred during one of the backports: [Error: Mocked error ; Error: Mocked error ; Error: Mocked error]");
|
||||
|
||||
const cwd = "/tmp/folder";
|
||||
|
||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v1");
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v2");
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v3");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom-failure-head-v1");
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom-failure-head-v2");
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom-failure-head-v3");
|
||||
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom-failure-head-v1");
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom-failure-head-v2");
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom-failure-head-v3");
|
||||
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(3);
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-failure-head-v1",
|
||||
base: "v1",
|
||||
title: "[v1] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-failure-head-v2",
|
||||
base: "v2",
|
||||
title: "[v2] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-failure-head-v3",
|
||||
base: "v3",
|
||||
title: "[v3] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toThrowError();
|
||||
});
|
||||
});
|
|
@ -128,6 +128,7 @@ describe("gha runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("closed and not merged pull request", async () => {
|
||||
|
@ -181,6 +182,7 @@ describe("gha runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("override backporting pr data", async () => {
|
||||
|
@ -231,6 +233,7 @@ describe("gha runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("set empty reviewers", async () => {
|
||||
|
@ -282,6 +285,7 @@ describe("gha runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("set custom labels with inheritance", async () => {
|
||||
|
@ -328,6 +332,7 @@ describe("gha runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("set custom labels without inheritance", async () => {
|
||||
|
@ -374,6 +379,7 @@ describe("gha runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("using config file with overrides", async () => {
|
||||
|
@ -417,6 +423,7 @@ describe("gha runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
// to check: https://github.com/kiegroup/git-backporting/issues/52
|
||||
|
@ -462,6 +469,7 @@ describe("gha runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("multiple commits pr", async () => {
|
||||
|
@ -507,6 +515,7 @@ describe("gha runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("using github api url and different strategy", async () => {
|
||||
|
@ -553,6 +562,7 @@ describe("gha runner", () => {
|
|||
comments: [],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("additional pr comments", async () => {
|
||||
|
@ -598,5 +608,161 @@ describe("gha runner", () => {
|
|||
comments: ["first comment", "second comment"],
|
||||
}
|
||||
);
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
||||
});
|
||||
|
||||
test("with multiple target branches", async () => {
|
||||
spyGetInput({
|
||||
"target-branch": "v1, v2, v3",
|
||||
"pull-request": "https://github.com/owner/reponame/pull/2368",
|
||||
"folder": "/tmp/folder",
|
||||
});
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = "/tmp/folder";
|
||||
|
||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v1");
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v2");
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v3");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-v1-28f63db");
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-v2-28f63db");
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-v3-28f63db");
|
||||
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-v1-28f63db");
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-v2-28f63db");
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-v3-28f63db");
|
||||
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(3);
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v1-28f63db",
|
||||
base: "v1",
|
||||
title: "[v1] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v2-28f63db",
|
||||
base: "v2",
|
||||
title: "[v2] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-v3-28f63db",
|
||||
base: "v3",
|
||||
title: "[v3] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(3);
|
||||
});
|
||||
|
||||
test("with multiple target branches and single custom bp branch", async () => {
|
||||
spyGetInput({
|
||||
"target-branch": "v1, v2, v3",
|
||||
"pull-request": "https://github.com/owner/reponame/pull/2368",
|
||||
"folder": "/tmp/folder",
|
||||
"bp-branch-name": "custom"
|
||||
});
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = "/tmp/folder";
|
||||
|
||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v1");
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v2");
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v3");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom-v1");
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom-v2");
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom-v3");
|
||||
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined);
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(3);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom-v1");
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom-v2");
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom-v3");
|
||||
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(3);
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-v1",
|
||||
base: "v1",
|
||||
title: "[v1] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-v2",
|
||||
base: "v2",
|
||||
title: "[v2] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "custom-v3",
|
||||
base: "v3",
|
||||
title: "[v3] 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: [],
|
||||
labels: [],
|
||||
comments: [],
|
||||
});
|
||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(3);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue