mirror of
https://code.forgejo.org/actions/git-backporting.git
synced 2025-05-17 11:09:13 -04:00
feat(issue-41): set and inherit labels (#48)
fix https://github.com/kiegroup/git-backporting/issues/41
This commit is contained in:
parent
f923f7f4c2
commit
fcc01673f4
28 changed files with 962 additions and 140 deletions
|
@ -1,5 +1,6 @@
|
|||
import { parseArgs, readConfigFile } from "@bp/service/args/args-utils";
|
||||
import { createTestFile, removeTestFile } from "../../support/utils";
|
||||
import { getAsCleanedCommaSeparatedList, getAsCommaSeparatedList, getOrUndefined, parseArgs, readConfigFile } from "@bp/service/args/args-utils";
|
||||
import { createTestFile, expectArrayEqual, removeTestFile, spyGetInput } from "../../support/utils";
|
||||
import { getInput } from "@actions/core";
|
||||
|
||||
const RANDOM_CONFIG_FILE_CONTENT_PATHNAME = "./args-utils-test-random-config-file.json";
|
||||
const RANDOM_CONFIG_FILE_CONTENT = {
|
||||
|
@ -39,4 +40,39 @@ describe("args utils test suite", () => {
|
|||
test("check readConfigFile function", () => {
|
||||
expect(readConfigFile(RANDOM_CONFIG_FILE_CONTENT_PATHNAME)).toStrictEqual(RANDOM_CONFIG_FILE_CONTENT);
|
||||
});
|
||||
|
||||
test("gha getOrUndefined", () => {
|
||||
spyGetInput({
|
||||
"present": "value",
|
||||
"empty": "",
|
||||
});
|
||||
expect(getOrUndefined(getInput("empty"))).toStrictEqual(undefined);
|
||||
expect(getOrUndefined(getInput("present"))).toStrictEqual("value");
|
||||
});
|
||||
|
||||
test("gha getAsCleanedCommaSeparatedList", () => {
|
||||
spyGetInput({
|
||||
"present": "value1, value2 , value3",
|
||||
"empty": "",
|
||||
"blank": " ",
|
||||
"inner": " inner spaces ",
|
||||
});
|
||||
expectArrayEqual(getAsCleanedCommaSeparatedList(getInput("present"))!, ["value1", "value2", "value3"]);
|
||||
expect(getAsCleanedCommaSeparatedList(getInput("empty"))).toStrictEqual(undefined);
|
||||
expect(getAsCleanedCommaSeparatedList(getInput("blank"))).toStrictEqual(undefined);
|
||||
expect(getAsCleanedCommaSeparatedList(getInput("inner"))).toStrictEqual(["innerspaces"]);
|
||||
});
|
||||
|
||||
test("gha getAsCommaSeparatedList", () => {
|
||||
spyGetInput({
|
||||
"present": "value1, value2 , value3",
|
||||
"empty": "",
|
||||
"blank": " ",
|
||||
"inner": " inner spaces ",
|
||||
});
|
||||
expectArrayEqual(getAsCommaSeparatedList(getInput("present"))!, ["value1", "value2", "value3"]);
|
||||
expect(getAsCommaSeparatedList(getInput("empty"))).toStrictEqual(undefined);
|
||||
expect(getAsCommaSeparatedList(getInput("blank"))).toStrictEqual(undefined);
|
||||
expectArrayEqual(getAsCommaSeparatedList(getInput("inner"))!, ["inner spaces"]);
|
||||
});
|
||||
});
|
|
@ -24,6 +24,8 @@ const RANDOM_CONFIG_FILE_CONTENT = {
|
|||
"reviewers": ["reviewer1", "reviewer2"],
|
||||
"assignees": ["assignee1", "assignee2"],
|
||||
"inheritReviewers": true,
|
||||
"labels": ["cherry-pick :cherries:"],
|
||||
"inheritLabels": true,
|
||||
};
|
||||
|
||||
describe("cli args parser", () => {
|
||||
|
@ -72,6 +74,8 @@ describe("cli args parser", () => {
|
|||
expect(args.reviewers).toEqual([]);
|
||||
expect(args.assignees).toEqual([]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expect(args.labels).toEqual([]);
|
||||
expect(args.inheritLabels).toEqual(false);
|
||||
});
|
||||
|
||||
test("with config file [default, short]", () => {
|
||||
|
@ -95,6 +99,8 @@ describe("cli args parser", () => {
|
|||
expect(args.reviewers).toEqual([]);
|
||||
expect(args.assignees).toEqual([]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expect(args.labels).toEqual([]);
|
||||
expect(args.inheritLabels).toEqual(false);
|
||||
});
|
||||
|
||||
test("valid execution [default, long]", () => {
|
||||
|
@ -120,6 +126,8 @@ describe("cli args parser", () => {
|
|||
expect(args.reviewers).toEqual([]);
|
||||
expect(args.assignees).toEqual([]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expect(args.labels).toEqual([]);
|
||||
expect(args.inheritLabels).toEqual(false);
|
||||
});
|
||||
|
||||
test("with config file [default, long]", () => {
|
||||
|
@ -143,6 +151,8 @@ describe("cli args parser", () => {
|
|||
expect(args.reviewers).toEqual([]);
|
||||
expect(args.assignees).toEqual([]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expect(args.labels).toEqual([]);
|
||||
expect(args.inheritLabels).toEqual(false);
|
||||
});
|
||||
|
||||
test("valid execution [override, short]", () => {
|
||||
|
@ -175,6 +185,8 @@ describe("cli args parser", () => {
|
|||
expect(args.reviewers).toEqual([]);
|
||||
expect(args.assignees).toEqual([]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expect(args.labels).toEqual([]);
|
||||
expect(args.inheritLabels).toEqual(false);
|
||||
});
|
||||
|
||||
test("valid execution [override, long]", () => {
|
||||
|
@ -203,6 +215,9 @@ describe("cli args parser", () => {
|
|||
"--assignees",
|
||||
" pippo,pluto, paperino",
|
||||
"--no-inherit-reviewers",
|
||||
"--labels",
|
||||
"cherry-pick :cherries:, another spaced label",
|
||||
"--inherit-labels",
|
||||
]);
|
||||
|
||||
const args: Args = parser.parse();
|
||||
|
@ -220,6 +235,8 @@ describe("cli args parser", () => {
|
|||
expectArrayEqual(args.reviewers!, ["al", "john", "jack"]);
|
||||
expectArrayEqual(args.assignees!, ["pippo", "pluto", "paperino"]);
|
||||
expect(args.inheritReviewers).toEqual(false);
|
||||
expectArrayEqual(args.labels!, ["cherry-pick :cherries:", "another spaced label"]);
|
||||
expect(args.inheritLabels).toEqual(true);
|
||||
});
|
||||
|
||||
test("override using config file", () => {
|
||||
|
@ -243,6 +260,8 @@ describe("cli args parser", () => {
|
|||
expectArrayEqual(args.reviewers!, ["reviewer1", "reviewer2"]);
|
||||
expectArrayEqual(args.assignees!,["assignee1", "assignee2"]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]);
|
||||
expect(args.inheritLabels).toEqual(true);
|
||||
});
|
||||
|
||||
test("ignore custom option when config file is set", () => {
|
||||
|
@ -273,6 +292,9 @@ describe("cli args parser", () => {
|
|||
"--assignees",
|
||||
" pippo,pluto, paperino",
|
||||
"--no-inherit-reviewers",
|
||||
"--labels",
|
||||
"cherry-pick :cherries:, another spaced label",
|
||||
"--inherit-labels",
|
||||
]);
|
||||
|
||||
const args: Args = parser.parse();
|
||||
|
@ -290,5 +312,7 @@ describe("cli args parser", () => {
|
|||
expectArrayEqual(args.reviewers!, ["reviewer1", "reviewer2"]);
|
||||
expectArrayEqual(args.assignees!,["assignee1", "assignee2"]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]);
|
||||
expect(args.inheritLabels).toEqual(true);
|
||||
});
|
||||
});
|
|
@ -24,6 +24,8 @@ const RANDOM_CONFIG_FILE_CONTENT = {
|
|||
"reviewers": ["reviewer1", "reviewer2"],
|
||||
"assignees": ["assignee1", "assignee2"],
|
||||
"inheritReviewers": true,
|
||||
"labels": ["cherry-pick :cherries:"],
|
||||
"inheritLabels": true,
|
||||
};
|
||||
|
||||
describe("gha args parser", () => {
|
||||
|
@ -50,26 +52,6 @@ describe("gha args parser", () => {
|
|||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test("getOrUndefined", () => {
|
||||
spyGetInput({
|
||||
"present": "value",
|
||||
"empty": "",
|
||||
});
|
||||
expect(parser.getOrUndefined("empty")).toStrictEqual(undefined);
|
||||
expect(parser.getOrUndefined("present")).toStrictEqual("value");
|
||||
});
|
||||
|
||||
test("getAsCommaSeparatedList", () => {
|
||||
spyGetInput({
|
||||
"present": "value1, value2 , value3",
|
||||
"empty": "",
|
||||
"blank": " ",
|
||||
});
|
||||
expectArrayEqual(parser.getAsCommaSeparatedList("present")!, ["value1", "value2", "value3"]);
|
||||
expect(parser.getAsCommaSeparatedList("empty")).toStrictEqual(undefined);
|
||||
expect(parser.getAsCommaSeparatedList("blank")).toStrictEqual(undefined);
|
||||
});
|
||||
|
||||
test("valid execution [default]", () => {
|
||||
spyGetInput({
|
||||
"target-branch": "target",
|
||||
|
@ -89,6 +71,8 @@ describe("gha args parser", () => {
|
|||
expect(args.reviewers).toEqual([]);
|
||||
expect(args.assignees).toEqual([]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expect(args.labels).toEqual([]);
|
||||
expect(args.inheritLabels).toEqual(false);
|
||||
});
|
||||
|
||||
test("valid execution [override]", () => {
|
||||
|
@ -106,6 +90,8 @@ describe("gha args parser", () => {
|
|||
"reviewers": "al , john, jack",
|
||||
"assignees": " pippo,pluto, paperino",
|
||||
"no-inherit-reviewers": "true",
|
||||
"labels": "cherry-pick :cherries:, another spaced label",
|
||||
"inherit-labels": "true"
|
||||
});
|
||||
|
||||
const args: Args = parser.parse();
|
||||
|
@ -123,6 +109,8 @@ describe("gha args parser", () => {
|
|||
expectArrayEqual(args.reviewers!, ["al", "john", "jack"]);
|
||||
expectArrayEqual(args.assignees!, ["pippo", "pluto", "paperino"]);
|
||||
expect(args.inheritReviewers).toEqual(false);
|
||||
expectArrayEqual(args.labels!, ["cherry-pick :cherries:", "another spaced label"]);
|
||||
expect(args.inheritLabels).toEqual(true);
|
||||
});
|
||||
|
||||
test("using config file", () => {
|
||||
|
@ -145,6 +133,8 @@ describe("gha args parser", () => {
|
|||
expect(args.reviewers).toEqual([]);
|
||||
expect(args.assignees).toEqual([]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expectArrayEqual(args.labels!, []);
|
||||
expect(args.inheritLabels).toEqual(false);
|
||||
});
|
||||
|
||||
test("ignore custom options when using config file", () => {
|
||||
|
@ -163,6 +153,8 @@ describe("gha args parser", () => {
|
|||
"reviewers": "al , john, jack",
|
||||
"assignees": " pippo,pluto, paperino",
|
||||
"no-inherit-reviewers": "true",
|
||||
"labels": "cherry-pick :cherries:, another spaced label",
|
||||
"inherit-labels": "false"
|
||||
});
|
||||
|
||||
const args: Args = parser.parse();
|
||||
|
@ -180,5 +172,7 @@ describe("gha args parser", () => {
|
|||
expectArrayEqual(args.reviewers!, ["reviewer1", "reviewer2"]);
|
||||
expectArrayEqual(args.assignees!,["assignee1", "assignee2"]);
|
||||
expect(args.inheritReviewers).toEqual(true);
|
||||
expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]);
|
||||
expect(args.inheritLabels).toEqual(true);
|
||||
});
|
||||
});
|
|
@ -28,6 +28,8 @@ const GITHUB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT = {
|
|||
"reviewers": ["user1", "user2"],
|
||||
"assignees": ["user3", "user4"],
|
||||
"inheritReviewers": true, // not taken into account
|
||||
"labels": ["cherry-pick :cherries:"],
|
||||
"inheritLabels": true,
|
||||
};
|
||||
|
||||
describe("github pull request config parser", () => {
|
||||
|
@ -104,6 +106,7 @@ describe("github pull request config parser", () => {
|
|||
body: "Please review and merge",
|
||||
reviewers: ["requested-gh-user", "gh-user"],
|
||||
assignees: [],
|
||||
labels: ["original-label"],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -125,6 +128,7 @@ describe("github pull request config parser", () => {
|
|||
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: [],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -199,6 +203,7 @@ describe("github pull request config parser", () => {
|
|||
body: "Please review and merge",
|
||||
reviewers: ["gh-user"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -233,7 +238,7 @@ describe("github pull request config parser", () => {
|
|||
});
|
||||
|
||||
|
||||
test("override backport pr data inherting reviewers", async () => {
|
||||
test("override backport pr data inheriting reviewers", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
|
@ -271,6 +276,7 @@ describe("github pull request config parser", () => {
|
|||
body: "Please review and merge",
|
||||
reviewers: ["requested-gh-user", "gh-user"],
|
||||
assignees: [],
|
||||
labels: ["original-label"],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -293,6 +299,7 @@ describe("github pull request config parser", () => {
|
|||
body: "New Body Prefix -New Body",
|
||||
reviewers: ["gh-user", "that-s-a-user"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -345,6 +352,7 @@ describe("github pull request config parser", () => {
|
|||
body: "Please review and merge",
|
||||
reviewers: ["requested-gh-user", "gh-user"],
|
||||
assignees: [],
|
||||
labels: ["original-label"],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -367,6 +375,7 @@ describe("github pull request config parser", () => {
|
|||
body: "New Body Prefix -New Body",
|
||||
reviewers: ["user1", "user2"],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -419,6 +428,7 @@ describe("github pull request config parser", () => {
|
|||
body: "Please review and merge",
|
||||
reviewers: ["requested-gh-user", "gh-user"],
|
||||
assignees: [],
|
||||
labels: ["original-label"],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -441,6 +451,85 @@ describe("github pull request config parser", () => {
|
|||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
cloneUrl: "https://github.com/owner/reponame.git"
|
||||
},
|
||||
sourceRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
cloneUrl: "https://github.com/owner/reponame.git"
|
||||
},
|
||||
bpBranchName: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
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,
|
||||
labels: ["custom-label", "original-label"], // also include the one inherited
|
||||
inheritLabels: true,
|
||||
};
|
||||
|
||||
const configs: Configs = await configParser.parseAndValidate(args);
|
||||
|
||||
expect(configs.dryRun).toEqual(false);
|
||||
expect(configs.git).toEqual({
|
||||
user: "Me",
|
||||
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,
|
||||
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: ["original-label"],
|
||||
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.backportPullRequest).toEqual({
|
||||
author: "Me",
|
||||
url: undefined,
|
||||
htmlUrl: undefined,
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: ["custom-label", "original-label"],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -484,6 +573,7 @@ describe("github pull request config parser", () => {
|
|||
body: "Please review and merge",
|
||||
reviewers: ["requested-gh-user", "gh-user"],
|
||||
assignees: [],
|
||||
labels: ["original-label"],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -505,6 +595,7 @@ describe("github pull request config parser", () => {
|
|||
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: [],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -548,6 +639,7 @@ describe("github pull request config parser", () => {
|
|||
body: "Please review and merge",
|
||||
reviewers: ["requested-gh-user", "gh-user"],
|
||||
assignees: [],
|
||||
labels: ["original-label"],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
@ -570,6 +662,7 @@ describe("github pull request config parser", () => {
|
|||
body: "New Body Prefix -New Body",
|
||||
reviewers: ["user1", "user2"],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: ["cherry-pick :cherries:", "original-label"],
|
||||
targetRepo: {
|
||||
owner: "owner",
|
||||
project: "reponame",
|
||||
|
|
|
@ -28,6 +28,8 @@ const GITLAB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT = {
|
|||
"reviewers": [],
|
||||
"assignees": ["user3", "user4"],
|
||||
"inheritReviewers": false,
|
||||
"labels": ["cherry-pick :cherries:"],
|
||||
"inheritLabels": true,
|
||||
};
|
||||
|
||||
|
||||
|
@ -107,6 +109,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "This is the body",
|
||||
reviewers: ["superuser1", "superuser2"],
|
||||
assignees: ["superuser"],
|
||||
labels: ["gitlab-original-label"],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -128,6 +131,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1\r\n\r\nThis is the body",
|
||||
reviewers: ["superuser"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -203,6 +207,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "Still opened mr body",
|
||||
reviewers: ["superuser"],
|
||||
assignees: ["superuser"],
|
||||
labels: [],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -236,7 +241,7 @@ describe("gitlab merge request config parser", () => {
|
|||
expect(async () => await configParser.parseAndValidate(args)).rejects.toThrow("Provided pull request is closed and not merged!");
|
||||
});
|
||||
|
||||
test("override backport pr data inherting reviewers", async () => {
|
||||
test("override backport pr data inheriting reviewers", async () => {
|
||||
const args: Args = {
|
||||
dryRun: false,
|
||||
auth: "",
|
||||
|
@ -274,6 +279,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "This is the body",
|
||||
reviewers: ["superuser1", "superuser2"],
|
||||
assignees: ["superuser"],
|
||||
labels: ["gitlab-original-label"],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -295,6 +301,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "New Body Prefix -New Body",
|
||||
reviewers: ["superuser"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -347,6 +354,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "This is the body",
|
||||
reviewers: ["superuser1", "superuser2"],
|
||||
assignees: ["superuser"],
|
||||
labels: ["gitlab-original-label"],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -368,6 +376,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "New Body Prefix -New Body",
|
||||
reviewers: ["user1", "user2"],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -420,6 +429,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "This is the body",
|
||||
reviewers: ["superuser1", "superuser2"],
|
||||
assignees: ["superuser"],
|
||||
labels: ["gitlab-original-label"],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -441,6 +451,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -455,6 +466,82 @@ describe("gitlab merge request config parser", () => {
|
|||
});
|
||||
});
|
||||
|
||||
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,
|
||||
labels: ["custom-label", "gitlab-original-label"], // also include the one inherited
|
||||
inheritLabels: true,
|
||||
};
|
||||
|
||||
const configs: Configs = await configParser.parseAndValidate(args);
|
||||
|
||||
expect(configs.dryRun).toEqual(false);
|
||||
expect(configs.git).toEqual({
|
||||
user: "Me",
|
||||
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,
|
||||
author: "superuser",
|
||||
url: "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
||||
htmlUrl: "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
||||
state: "merged",
|
||||
merged: true,
|
||||
mergedBy: "superuser",
|
||||
title: "Update test.txt",
|
||||
body: "This is the body",
|
||||
reviewers: ["superuser1", "superuser2"],
|
||||
assignees: ["superuser"],
|
||||
labels: ["gitlab-original-label"],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||
},
|
||||
sourceRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||
},
|
||||
nCommits: 1,
|
||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
author: "Me",
|
||||
url: undefined,
|
||||
htmlUrl: undefined,
|
||||
title: "New Title",
|
||||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: ["custom-label", "gitlab-original-label"],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||
},
|
||||
sourceRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||
},
|
||||
bpBranchName: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
test("using simple config file", async () => {
|
||||
spyGetInput({
|
||||
|
@ -484,6 +571,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "This is the body",
|
||||
reviewers: ["superuser1", "superuser2"],
|
||||
assignees: ["superuser"],
|
||||
labels: ["gitlab-original-label"],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -505,6 +593,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1\r\n\r\nThis is the body",
|
||||
reviewers: ["superuser"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -547,6 +636,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "This is the body",
|
||||
reviewers: ["superuser1", "superuser2"],
|
||||
assignees: ["superuser"],
|
||||
labels: ["gitlab-original-label"],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -568,6 +658,7 @@ describe("gitlab merge request config parser", () => {
|
|||
body: "New Body Prefix -New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: ["cherry-pick :cherries:", "gitlab-original-label"],
|
||||
targetRepo: {
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
|
|
@ -92,6 +92,7 @@ describe("github service", () => {
|
|||
head: "bp-branch",
|
||||
reviewers: [],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
};
|
||||
|
||||
const url: string = await gitClient.createPullRequest(backport);
|
||||
|
@ -121,6 +122,7 @@ describe("github service", () => {
|
|||
head: "bp-branch",
|
||||
reviewers: ["superuser", "invalid"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
};
|
||||
|
||||
const url: string = await gitClient.createPullRequest(backport);
|
||||
|
@ -155,6 +157,7 @@ describe("github service", () => {
|
|||
head: "bp-branch",
|
||||
reviewers: [],
|
||||
assignees: ["superuser", "invalid"],
|
||||
labels: [],
|
||||
};
|
||||
|
||||
const url: string = await gitClient.createPullRequest(backport);
|
||||
|
@ -189,6 +192,7 @@ describe("github service", () => {
|
|||
head: "bp-branch-2",
|
||||
reviewers: ["superuser", "invalid"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
};
|
||||
|
||||
const url: string = await gitClient.createPullRequest(backport);
|
||||
|
@ -223,6 +227,7 @@ describe("github service", () => {
|
|||
head: "bp-branch-2",
|
||||
reviewers: [],
|
||||
assignees: ["superuser", "invalid"],
|
||||
labels: [],
|
||||
};
|
||||
|
||||
const url: string = await gitClient.createPullRequest(backport);
|
||||
|
@ -246,4 +251,37 @@ describe("github service", () => {
|
|||
assignee_ids: [14041],
|
||||
});
|
||||
});
|
||||
|
||||
test("create backport pull request with custom labels", async () => {
|
||||
const backport: BackportPullRequest = {
|
||||
title: "Backport Title",
|
||||
body: "Backport Body",
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
base: "old/branch",
|
||||
head: "bp-branch-2",
|
||||
reviewers: [],
|
||||
assignees: [],
|
||||
labels: ["label1", "label2"],
|
||||
};
|
||||
|
||||
const url: string = await gitClient.createPullRequest(backport);
|
||||
expect(url).toStrictEqual("https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/" + SECOND_NEW_GITLAB_MR_ID);
|
||||
|
||||
// check axios invocation
|
||||
expect(axiosInstanceSpy.post).toBeCalledTimes(1);
|
||||
expect(axiosInstanceSpy.post).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
|
||||
source_branch: "bp-branch-2",
|
||||
target_branch: "old/branch",
|
||||
title: "Backport Title",
|
||||
description: "Backport Body",
|
||||
reviewer_ids: [],
|
||||
assignee_ids: [],
|
||||
}));
|
||||
expect(axiosInstanceSpy.get).toBeCalledTimes(0);
|
||||
expect(axiosInstanceSpy.put).toBeCalledTimes(1); // just labels
|
||||
expect(axiosInstanceSpy.put).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + SECOND_NEW_GITLAB_MR_ID, {
|
||||
labels: "label1,label2",
|
||||
});
|
||||
});
|
||||
});
|
|
@ -21,6 +21,8 @@ const GITHUB_MERGED_PR_W_OVERRIDES_CONFIG_FILE_CONTENT = {
|
|||
"reviewers": [],
|
||||
"assignees": ["user3", "user4"],
|
||||
"inheritReviewers": false,
|
||||
"labels": ["cli github cherry pick :cherries:"],
|
||||
"inheritLabels": true,
|
||||
};
|
||||
|
||||
jest.mock("@bp/service/git/git-cli");
|
||||
|
@ -218,6 +220,7 @@ describe("cli runner", () => {
|
|||
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
|
||||
reviewers: ["gh-user", "that-s-a-user"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -258,6 +261,7 @@ describe("cli runner", () => {
|
|||
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/8632"),
|
||||
reviewers: ["gh-user", "that-s-a-user"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -310,6 +314,7 @@ describe("cli runner", () => {
|
|||
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/4444"),
|
||||
reviewers: ["gh-user"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -331,7 +336,7 @@ describe("cli runner", () => {
|
|||
"--reviewers",
|
||||
"user1,user2",
|
||||
"--assignees",
|
||||
"user3,user4"
|
||||
"user3,user4",
|
||||
]);
|
||||
|
||||
await runner.execute();
|
||||
|
@ -363,6 +368,7 @@ describe("cli runner", () => {
|
|||
body: "New Body Prefix - New Body",
|
||||
reviewers: ["user1", "user2"],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -415,6 +421,96 @@ describe("cli runner", () => {
|
|||
body: "New Body Prefix - New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("set custom labels with inheritance", async () => {
|
||||
addProcessArgs([
|
||||
"-tb",
|
||||
"target",
|
||||
"-pr",
|
||||
"https://github.com/owner/reponame/pull/2368",
|
||||
"--labels",
|
||||
"cherry-pick :cherries:, original-label",
|
||||
"--inherit-labels",
|
||||
]);
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = process.cwd() + "/bp";
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc",
|
||||
base: "target",
|
||||
title: "[target] PR Title",
|
||||
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
|
||||
reviewers: ["gh-user", "that-s-a-user"],
|
||||
assignees: [],
|
||||
labels: ["cherry-pick :cherries:", "original-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("set custom lables without inheritance", async () => {
|
||||
addProcessArgs([
|
||||
"-tb",
|
||||
"target",
|
||||
"-pr",
|
||||
"https://github.com/owner/reponame/pull/2368",
|
||||
"--labels",
|
||||
"first-label, second-label ",
|
||||
]);
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = process.cwd() + "/bp";
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc",
|
||||
base: "target",
|
||||
title: "[target] PR Title",
|
||||
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
|
||||
reviewers: ["gh-user", "that-s-a-user"],
|
||||
assignees: [],
|
||||
labels: ["first-label", "second-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -454,6 +550,7 @@ describe("cli runner", () => {
|
|||
body: "New Body Prefix - New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: ["cli github cherry pick :cherries:", "original-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -21,6 +21,8 @@ const GITLAB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT = {
|
|||
"reviewers": [],
|
||||
"assignees": ["user3", "user4"],
|
||||
"inheritReviewers": false,
|
||||
"labels": ["cli gitlab cherry pick :cherries:"],
|
||||
"inheritLabels": true,
|
||||
};
|
||||
|
||||
jest.mock("axios", () => {
|
||||
|
@ -171,6 +173,7 @@ describe("cli runner", () => {
|
|||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"),
|
||||
reviewers: ["superuser"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -224,6 +227,7 @@ describe("cli runner", () => {
|
|||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||
reviewers: ["superuser"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -278,6 +282,7 @@ describe("cli runner", () => {
|
|||
body: "New Body Prefix - New Body",
|
||||
reviewers: ["user1", "user2"],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -330,6 +335,98 @@ describe("cli runner", () => {
|
|||
body: "New Body Prefix - New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("set custom labels with inheritance", async () => {
|
||||
addProcessArgs([
|
||||
"-tb",
|
||||
"target",
|
||||
"-pr",
|
||||
"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
||||
"--labels",
|
||||
"cherry-pick :cherries:, another-label",
|
||||
"--inherit-labels",
|
||||
]);
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = process.cwd() + "/bp";
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
// 0 occurrences as the mr is already merged and the owner is the same for
|
||||
// both source and target repositories
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||
base: "target",
|
||||
title: "[target] Update test.txt",
|
||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||
reviewers: ["superuser"],
|
||||
assignees: [],
|
||||
labels: ["cherry-pick :cherries:", "another-label", "gitlab-original-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("set custom labels without inheritance", async () => {
|
||||
addProcessArgs([
|
||||
"-tb",
|
||||
"target",
|
||||
"-pr",
|
||||
"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
||||
"--labels",
|
||||
"cherry-pick :cherries:, another-label",
|
||||
]);
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = process.cwd() + "/bp";
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
// 0 occurrences as the mr is already merged and the owner is the same for
|
||||
// both source and target repositories
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||
base: "target",
|
||||
title: "[target] Update test.txt",
|
||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||
reviewers: ["superuser"],
|
||||
assignees: [],
|
||||
labels: ["cherry-pick :cherries:", "another-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -370,6 +467,7 @@ describe("cli runner", () => {
|
|||
body: expect.stringContaining("**This is a backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: ["cli gitlab cherry pick :cherries:", "gitlab-original-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -21,6 +21,8 @@ const GITHUB_MERGED_PR_W_OVERRIDES_CONFIG_FILE_CONTENT = {
|
|||
"reviewers": [],
|
||||
"assignees": ["user3", "user4"],
|
||||
"inheritReviewers": false,
|
||||
"labels": ["gha github cherry pick :cherries:"],
|
||||
"inheritLabels": true,
|
||||
};
|
||||
|
||||
|
||||
|
@ -117,6 +119,7 @@ describe("gha runner", () => {
|
|||
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
|
||||
reviewers: ["gh-user", "that-s-a-user"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -165,6 +168,7 @@ describe("gha runner", () => {
|
|||
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/4444"),
|
||||
reviewers: ["gh-user"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -210,6 +214,7 @@ describe("gha runner", () => {
|
|||
body: "New Body Prefix - New Body",
|
||||
reviewers: ["user1", "user2"],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -256,6 +261,91 @@ describe("gha runner", () => {
|
|||
body: "New Body Prefix - New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("set custom labels with inheritance", async () => {
|
||||
spyGetInput({
|
||||
"target-branch": "target",
|
||||
"pull-request": "https://github.com/owner/reponame/pull/2368",
|
||||
"labels": "cherry-pick :cherries:, another-label",
|
||||
"inherit-labels": "true",
|
||||
});
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = process.cwd() + "/bp";
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc",
|
||||
base: "target",
|
||||
title: "[target] PR Title",
|
||||
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
|
||||
reviewers: ["gh-user", "that-s-a-user"],
|
||||
assignees: [],
|
||||
labels: ["cherry-pick :cherries:", "another-label", "original-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("set custom labels without inheritance", async () => {
|
||||
spyGetInput({
|
||||
"target-branch": "target",
|
||||
"pull-request": "https://github.com/owner/reponame/pull/2368",
|
||||
"labels": "cherry-pick :cherries:, another-label",
|
||||
"inherit-labels": "false",
|
||||
});
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = process.cwd() + "/bp";
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "owner",
|
||||
repo: "reponame",
|
||||
head: "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc",
|
||||
base: "target",
|
||||
title: "[target] PR Title",
|
||||
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
|
||||
reviewers: ["gh-user", "that-s-a-user"],
|
||||
assignees: [],
|
||||
labels: ["cherry-pick :cherries:", "another-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -294,6 +384,7 @@ describe("gha runner", () => {
|
|||
body: "New Body Prefix - New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: ["gha github cherry pick :cherries:", "original-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -21,6 +21,8 @@ const GITLAB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT = {
|
|||
"reviewers": [],
|
||||
"assignees": ["user3", "user4"],
|
||||
"inheritReviewers": false,
|
||||
"labels": ["gha gitlab cherry pick :cherries:"],
|
||||
"inheritLabels": true,
|
||||
};
|
||||
|
||||
jest.mock("axios", () => {
|
||||
|
@ -128,6 +130,7 @@ describe("gha runner", () => {
|
|||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"),
|
||||
reviewers: ["superuser"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -175,6 +178,7 @@ describe("gha runner", () => {
|
|||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||
reviewers: ["superuser"],
|
||||
assignees: [],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -220,6 +224,7 @@ describe("gha runner", () => {
|
|||
body: "New Body Prefix - New Body",
|
||||
reviewers: ["user1", "user2"],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -266,6 +271,88 @@ describe("gha runner", () => {
|
|||
body: "New Body Prefix - New Body",
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: [],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("set custom labels with inheritance", async () => {
|
||||
spyGetInput({
|
||||
"target-branch": "target",
|
||||
"pull-request": "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
||||
"labels": "cherry-pick :cherries:, another-label",
|
||||
"inherit-labels": "true",
|
||||
});
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = process.cwd() + "/bp";
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||
base: "target",
|
||||
title: "[target] Update test.txt",
|
||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||
reviewers: ["superuser"],
|
||||
assignees: [],
|
||||
labels: ["cherry-pick :cherries:", "another-label", "gitlab-original-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("set custom labels without inheritance", async () => {
|
||||
spyGetInput({
|
||||
"target-branch": "target",
|
||||
"pull-request": "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
||||
"labels": "cherry-pick :cherries:, another-label",
|
||||
});
|
||||
|
||||
await runner.execute();
|
||||
|
||||
const cwd = process.cwd() + "/bp";
|
||||
|
||||
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||
|
||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||
owner: "superuser",
|
||||
repo: "backporting-example",
|
||||
head: "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||
base: "target",
|
||||
title: "[target] Update test.txt",
|
||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||
reviewers: ["superuser"],
|
||||
assignees: [],
|
||||
labels: ["cherry-pick :cherries:", "another-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -305,6 +392,7 @@ describe("gha runner", () => {
|
|||
body: expect.stringContaining("**This is a backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||
reviewers: [],
|
||||
assignees: ["user3", "user4"],
|
||||
labels: ["gha gitlab cherry pick :cherries:", "gitlab-original-label"],
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue