From 265955dda77a8191fd1f64517fec20e8d5f8c5b4 Mon Sep 17 00:00:00 2001 From: Andrea Lamparelli Date: Wed, 12 Jul 2023 13:50:59 +0200 Subject: [PATCH] feat(issue-62): make cherry-pick strategy configurable (#63) fix https://github.com/kiegroup/git-backporting/issues/62 --- README.md | 8 +- action.yml | 8 ++ dist/cli/index.js | 24 +++++- dist/gha/index.js | 22 ++++- src/service/args/args-parser.ts | 2 + src/service/args/args.types.ts | 2 + src/service/args/cli/cli-args-parser.ts | 4 + src/service/args/gha/gha-args-parser.ts | 2 + src/service/configs/configs.types.ts | 2 + .../configs/pullrequest/pr-configs-parser.ts | 2 + src/service/git/git-cli.ts | 15 +++- src/service/runner/runner.ts | 2 +- test/service/args/cli/cli-args-parser.test.ts | 50 +++++++++++ test/service/args/gha/gha-args-parser.test.ts | 36 ++++++++ test/service/runner/cli-github-runner.test.ts | 82 +++++++++++++++---- test/service/runner/cli-gitlab-runner.test.ts | 22 ++--- test/service/runner/gha-github-runner.test.ts | 67 ++++++++++++--- test/service/runner/gha-gitlab-runner.test.ts | 20 ++--- 18 files changed, 312 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index a1815e7..32955ae 100644 --- a/README.md +++ b/README.md @@ -81,11 +81,15 @@ By default the tool will try to cherry-pick the single squashed/merged commit in Based on the original pull request, creates a new one containing the backporting to the target branch. Note that most of these information can be overridden with appropriate CLI options or GHA inputs. -Right now all commits are cherry-picked using the following git-equivalent command: +#### Default cherry-pick strategy + +The default cherry-pick strategy is `recursive` with `theirs` option for automatic conflicts resolution. Therefore, by default, all commits are cherry-picked using the following git-equivalent command: ```bash $ git cherry-pick -m 1 --strategy=recursive --strategy-option=theirs ``` +From version `v4.2.0` we made both `strategy` and `strategy-option` fully configurable from CLI or GitHub action, so if users need a specific strategy which differs from the default one please consider using either `--strategy` or `--strategy-option`, or their equivalent GitHub action inputs, more details in [inputs](#inputs) section. + > **NOTE**: If there are any conflicts, the tool will block the process and exit signalling the failure as there are still no ways to interactively resolve them. In these cases a manual cherry-pick is needed, or alternatively users could manually resume the process in the cloned repository (here the user will have to resolve the conflicts, push the branch and create the pull request - all manually). ### Inputs @@ -113,6 +117,8 @@ This tool comes with some inputs that allow users to override the default behavi | Labels | --labels | N | Provide custom labels to be added to the backporting pull request | [] | | Inherit labels | --inherit-labels | N | If enabled inherit lables from the original pull request | false | | No squash | --no-squash | N | If provided the backporting will try to backport all pull request commits without squashing | false | +| Strategy | --strategy | N | Cherry pick merging strategy, see [git-merge](https://git-scm.com/docs/git-merge#_merge_strategies) doc for all possible values | "recursive" | +| Strategy Option | --strategy-option | N | Cherry pick merging strategy option, see [git-merge](https://git-scm.com/docs/git-merge#_merge_strategies) doc for all possible values | "theirs" | | Dry Run | -d, --dry-run | N | If enabled the tool does not push nor create anything remotely, use this to skip PR creation | false | > **NOTE**: `pull request` and `target branch` are *mandatory*, they must be provided as CLI options or as part of the configuration file (if used). diff --git a/action.yml b/action.yml index d774a98..90bc2d5 100644 --- a/action.yml +++ b/action.yml @@ -59,6 +59,14 @@ inputs: description: "If set to true the tool will backport all commits as part of the pull request instead of the suqashed one" required: false default: "false" + strategy: + description: "Cherry-pick merge strategy" + required: false + default: "recursive" + strategy-option: + description: "Cherry-pick merge strategy option" + required: false + default: "theirs" runs: using: node16 diff --git a/dist/cli/index.js b/dist/cli/index.js index 3929d5d..10fa964 100755 --- a/dist/cli/index.js +++ b/dist/cli/index.js @@ -61,6 +61,8 @@ class ArgsParser { labels: this.getOrDefault(args.labels, []), inheritLabels: this.getOrDefault(args.inheritLabels, false), squash: this.getOrDefault(args.squash, true), + strategy: this.getOrDefault(args.strategy), + strategyOption: this.getOrDefault(args.strategyOption), }; } } @@ -187,6 +189,8 @@ class CLIArgsParser extends args_parser_1.default { .option("--labels ", "comma separated list of labels to be assigned to the backported pull request", args_utils_1.getAsCommaSeparatedList) .option("--inherit-labels", "if true the backported pull request will inherit labels from the original one") .option("--no-squash", "if provided the tool will backport all commits as part of the pull request") + .option("--strategy ", "cherry-pick merge strategy, default to 'recursive'", undefined) + .option("--strategy-option ", "cherry-pick merge strategy option, default to 'theirs'") .option("-cf, --config-file ", "configuration file containing all valid options, the json must match Args interface"); } readArgs() { @@ -217,6 +221,8 @@ class CLIArgsParser extends args_parser_1.default { labels: opts.labels, inheritLabels: opts.inheritLabels, squash: opts.squash, + strategy: opts.strategy, + strategyOption: opts.strategyOption, }; } return args; @@ -295,6 +301,8 @@ class PullRequestConfigsParser extends configs_parser_1.default { auth: args.auth, folder: `${folder.startsWith("/") ? "" : process.cwd() + "/"}${args.folder ?? this.getDefaultFolder()}`, targetBranch: args.targetBranch, + mergeStrategy: args.strategy, + mergeStrategyOption: args.strategyOption, originalPullRequest: pr, backportPullRequest: this.getDefaultBackportPullRequest(pr, args), git: { @@ -446,9 +454,19 @@ class GitCLIService { * @param cwd repository in which the sha should be cherry picked to * @param sha commit sha */ - async cherryPick(cwd, sha) { + async cherryPick(cwd, sha, strategy = "recursive", strategyOption = "theirs") { this.logger.info(`Cherry picking ${sha}.`); - await this.git(cwd).raw(["cherry-pick", "-m", "1", "--strategy=recursive", "--strategy-option=theirs", sha]); + const options = ["cherry-pick", "-m", "1", `--strategy=${strategy}`, `--strategy-option=${strategyOption}`, sha]; + try { + await this.git(cwd).raw(options); + } + catch (error) { + const diff = await this.git(cwd).diff(); + if (diff) { + throw new Error(`${error}\r\nShowing git diff:\r\n` + diff); + } + throw error; + } } /** * Push a branch to a remote @@ -1213,7 +1231,7 @@ class Runner { // 7. apply all changes to the new branch this.logger.debug("Cherry picking commits.."); for (const sha of originalPR.commits) { - await git.cherryPick(configs.folder, sha); + await git.cherryPick(configs.folder, sha, configs.mergeStrategy, configs.mergeStrategyOption); } const backport = { owner: originalPR.targetRepo.owner, diff --git a/dist/gha/index.js b/dist/gha/index.js index df80f9f..5778dce 100755 --- a/dist/gha/index.js +++ b/dist/gha/index.js @@ -61,6 +61,8 @@ class ArgsParser { labels: this.getOrDefault(args.labels, []), inheritLabels: this.getOrDefault(args.inheritLabels, false), squash: this.getOrDefault(args.squash, true), + strategy: this.getOrDefault(args.strategy), + strategyOption: this.getOrDefault(args.strategyOption), }; } } @@ -190,6 +192,8 @@ class GHAArgsParser extends args_parser_1.default { labels: (0, args_utils_1.getAsCommaSeparatedList)((0, core_1.getInput)("labels")), inheritLabels: (0, args_utils_1.getAsBooleanOrDefault)((0, core_1.getInput)("inherit-labels")), squash: !(0, args_utils_1.getAsBooleanOrDefault)((0, core_1.getInput)("no-squash")), + strategy: (0, args_utils_1.getOrUndefined)((0, core_1.getInput)("strategy")), + strategyOption: (0, args_utils_1.getOrUndefined)((0, core_1.getInput)("strategy-option")), }; } return args; @@ -268,6 +272,8 @@ class PullRequestConfigsParser extends configs_parser_1.default { auth: args.auth, folder: `${folder.startsWith("/") ? "" : process.cwd() + "/"}${args.folder ?? this.getDefaultFolder()}`, targetBranch: args.targetBranch, + mergeStrategy: args.strategy, + mergeStrategyOption: args.strategyOption, originalPullRequest: pr, backportPullRequest: this.getDefaultBackportPullRequest(pr, args), git: { @@ -419,9 +425,19 @@ class GitCLIService { * @param cwd repository in which the sha should be cherry picked to * @param sha commit sha */ - async cherryPick(cwd, sha) { + async cherryPick(cwd, sha, strategy = "recursive", strategyOption = "theirs") { this.logger.info(`Cherry picking ${sha}.`); - await this.git(cwd).raw(["cherry-pick", "-m", "1", "--strategy=recursive", "--strategy-option=theirs", sha]); + const options = ["cherry-pick", "-m", "1", `--strategy=${strategy}`, `--strategy-option=${strategyOption}`, sha]; + try { + await this.git(cwd).raw(options); + } + catch (error) { + const diff = await this.git(cwd).diff(); + if (diff) { + throw new Error(`${error}\r\nShowing git diff:\r\n` + diff); + } + throw error; + } } /** * Push a branch to a remote @@ -1186,7 +1202,7 @@ class Runner { // 7. apply all changes to the new branch this.logger.debug("Cherry picking commits.."); for (const sha of originalPR.commits) { - await git.cherryPick(configs.folder, sha); + await git.cherryPick(configs.folder, sha, configs.mergeStrategy, configs.mergeStrategyOption); } const backport = { owner: originalPR.targetRepo.owner, diff --git a/src/service/args/args-parser.ts b/src/service/args/args-parser.ts index 265db2b..d70fa27 100644 --- a/src/service/args/args-parser.ts +++ b/src/service/args/args-parser.ts @@ -39,6 +39,8 @@ export default abstract class ArgsParser { labels: this.getOrDefault(args.labels, []), inheritLabels: this.getOrDefault(args.inheritLabels, false), squash: this.getOrDefault(args.squash, true), + strategy: this.getOrDefault(args.strategy), + strategyOption: this.getOrDefault(args.strategyOption), }; } } \ No newline at end of file diff --git a/src/service/args/args.types.ts b/src/service/args/args.types.ts index 6596bc3..b3c1860 100644 --- a/src/service/args/args.types.ts +++ b/src/service/args/args.types.ts @@ -19,4 +19,6 @@ export interface Args { labels?: string[], // backport pr labels inheritLabels?: boolean, // if true inherit labels from original pr squash?: boolean, // if false use squashed/merged commit otherwise backport all commits as part of the pr + strategy?: string, // cherry-pick merge strategy + strategyOption?: string, // cherry-pick merge strategy option } \ No newline at end of file diff --git a/src/service/args/cli/cli-args-parser.ts b/src/service/args/cli/cli-args-parser.ts index f37eee4..a6065dc 100644 --- a/src/service/args/cli/cli-args-parser.ts +++ b/src/service/args/cli/cli-args-parser.ts @@ -27,6 +27,8 @@ export default class CLIArgsParser extends ArgsParser { .option("--labels ", "comma separated list of labels to be assigned to the backported pull request", getAsCommaSeparatedList) .option("--inherit-labels", "if true the backported pull request will inherit labels from the original one") .option("--no-squash", "if provided the tool will backport all commits as part of the pull request") + .option("--strategy ", "cherry-pick merge strategy, default to 'recursive'", undefined) + .option("--strategy-option ", "cherry-pick merge strategy option, default to 'theirs'") .option("-cf, --config-file ", "configuration file containing all valid options, the json must match Args interface"); } @@ -58,6 +60,8 @@ export default class CLIArgsParser extends ArgsParser { labels: opts.labels, inheritLabels: opts.inheritLabels, squash: opts.squash, + strategy: opts.strategy, + strategyOption: opts.strategyOption, }; } diff --git a/src/service/args/gha/gha-args-parser.ts b/src/service/args/gha/gha-args-parser.ts index 18a6b3c..e3d5ba0 100644 --- a/src/service/args/gha/gha-args-parser.ts +++ b/src/service/args/gha/gha-args-parser.ts @@ -30,6 +30,8 @@ export default class GHAArgsParser extends ArgsParser { labels: getAsCommaSeparatedList(getInput("labels")), inheritLabels: getAsBooleanOrDefault(getInput("inherit-labels")), squash: !getAsBooleanOrDefault(getInput("no-squash")), + strategy: getOrUndefined(getInput("strategy")), + strategyOption: getOrUndefined(getInput("strategy-option")), }; } diff --git a/src/service/configs/configs.types.ts b/src/service/configs/configs.types.ts index ff28a78..0f82cfc 100644 --- a/src/service/configs/configs.types.ts +++ b/src/service/configs/configs.types.ts @@ -16,6 +16,8 @@ export interface Configs { git: LocalGit, folder: string, targetBranch: string, + mergeStrategy?: string, // cherry-pick merge strategy + mergeStrategyOption?: string, // cherry-pick merge strategy option originalPullRequest: GitPullRequest, backportPullRequest: GitPullRequest, } diff --git a/src/service/configs/pullrequest/pr-configs-parser.ts b/src/service/configs/pullrequest/pr-configs-parser.ts index 057912b..d83d9cd 100644 --- a/src/service/configs/pullrequest/pr-configs-parser.ts +++ b/src/service/configs/pullrequest/pr-configs-parser.ts @@ -30,6 +30,8 @@ export default class PullRequestConfigsParser extends ConfigsParser { auth: args.auth, folder: `${folder.startsWith("/") ? "" : process.cwd() + "/"}${args.folder ?? this.getDefaultFolder()}`, targetBranch: args.targetBranch, + mergeStrategy: args.strategy, + mergeStrategyOption: args.strategyOption, originalPullRequest: pr, backportPullRequest: this.getDefaultBackportPullRequest(pr, args), git: { diff --git a/src/service/git/git-cli.ts b/src/service/git/git-cli.ts index 9e639df..c0b439e 100644 --- a/src/service/git/git-cli.ts +++ b/src/service/git/git-cli.ts @@ -105,9 +105,20 @@ export default class GitCLIService { * @param cwd repository in which the sha should be cherry picked to * @param sha commit sha */ - async cherryPick(cwd: string, sha: string): Promise { + async cherryPick(cwd: string, sha: string, strategy = "recursive", strategyOption = "theirs"): Promise { this.logger.info(`Cherry picking ${sha}.`); - await this.git(cwd).raw(["cherry-pick", "-m", "1", "--strategy=recursive", "--strategy-option=theirs", sha]); + + const options = ["cherry-pick", "-m", "1", `--strategy=${strategy}`, `--strategy-option=${strategyOption}`, sha]; + try { + await this.git(cwd).raw(options); + } catch(error) { + const diff = await this.git(cwd).diff(); + if (diff) { + throw new Error(`${error}\r\nShowing git diff:\r\n` + diff); + } + + throw error; + } } /** diff --git a/src/service/runner/runner.ts b/src/service/runner/runner.ts index 7b0db39..2060e30 100644 --- a/src/service/runner/runner.ts +++ b/src/service/runner/runner.ts @@ -99,7 +99,7 @@ export default class Runner { // 7. apply all changes to the new branch this.logger.debug("Cherry picking commits.."); for (const sha of originalPR.commits!) { - await git.cherryPick(configs.folder, sha); + await git.cherryPick(configs.folder, sha, configs.mergeStrategy, configs.mergeStrategyOption); } const backport: BackportPullRequest = { diff --git a/test/service/args/cli/cli-args-parser.test.ts b/test/service/args/cli/cli-args-parser.test.ts index b38d669..4f64187 100644 --- a/test/service/args/cli/cli-args-parser.test.ts +++ b/test/service/args/cli/cli-args-parser.test.ts @@ -77,6 +77,8 @@ describe("cli args parser", () => { 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("with config file [default, short]", () => { @@ -103,6 +105,8 @@ describe("cli args parser", () => { 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("valid execution [default, long]", () => { @@ -131,6 +135,8 @@ describe("cli args parser", () => { 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("with config file [default, long]", () => { @@ -157,6 +163,8 @@ describe("cli args parser", () => { 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("valid execution [override, short]", () => { @@ -192,6 +200,8 @@ describe("cli args parser", () => { 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("valid execution [override, long]", () => { @@ -243,6 +253,8 @@ describe("cli args parser", () => { expectArrayEqual(args.labels!, ["cherry-pick :cherries:", "another spaced label"]); expect(args.inheritLabels).toEqual(true); expect(args.squash).toEqual(true); + expect(args.strategy).toEqual(undefined); + expect(args.strategyOption).toEqual(undefined); }); test("override using config file", () => { @@ -269,6 +281,8 @@ describe("cli args parser", () => { expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]); expect(args.inheritLabels).toEqual(true); expect(args.squash).toEqual(true); + expect(args.strategy).toEqual(undefined); + expect(args.strategyOption).toEqual(undefined); }); test("ignore custom option when config file is set", () => { @@ -322,6 +336,8 @@ describe("cli args parser", () => { expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]); expect(args.inheritLabels).toEqual(true); expect(args.squash).toEqual(true); + expect(args.strategy).toEqual(undefined); + expect(args.strategyOption).toEqual(undefined); }); test("override squash to false", () => { @@ -352,4 +368,38 @@ describe("cli args parser", () => { expect(args.inheritLabels).toEqual(false); expect(args.squash).toEqual(false); }); + + test("override cherry pick strategies", () => { + addProcessArgs([ + "--target-branch", + "target", + "--pull-request", + "https://localhost/whatever/pulls/1", + "--strategy", + "ort", + "--strategy-option", + "ours", + ]); + + 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"); + 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("ort"); + expect(args.strategyOption).toEqual("ours"); + }); }); \ No newline at end of file diff --git a/test/service/args/gha/gha-args-parser.test.ts b/test/service/args/gha/gha-args-parser.test.ts index 61a04bc..ebe6e81 100644 --- a/test/service/args/gha/gha-args-parser.test.ts +++ b/test/service/args/gha/gha-args-parser.test.ts @@ -70,6 +70,8 @@ describe("gha args parser", () => { 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("valid execution [override]", () => { @@ -109,6 +111,8 @@ describe("gha args parser", () => { expectArrayEqual(args.labels!, ["cherry-pick :cherries:", "another spaced label"]); expect(args.inheritLabels).toEqual(true); expect(args.squash).toEqual(true); + expect(args.strategy).toEqual(undefined); + expect(args.strategyOption).toEqual(undefined); }); test("using config file", () => { @@ -134,6 +138,8 @@ describe("gha args parser", () => { expectArrayEqual(args.labels!, []); expect(args.inheritLabels).toEqual(false); expect(args.squash).toEqual(true); + expect(args.strategy).toEqual(undefined); + expect(args.strategyOption).toEqual(undefined); }); test("ignore custom options when using config file", () => { @@ -174,6 +180,8 @@ describe("gha args parser", () => { expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]); expect(args.inheritLabels).toEqual(true); expect(args.squash).toEqual(true); + expect(args.strategy).toEqual(undefined); + expect(args.strategyOption).toEqual(undefined); }); test("override squash to false", () => { @@ -200,4 +208,32 @@ describe("gha args parser", () => { expect(args.inheritLabels).toEqual(false); expect(args.squash).toEqual(false); }); + + test("override cherry pick strategy", () => { + spyGetInput({ + "target-branch": "target", + "pull-request": "https://localhost/whatever/pulls/1", + "strategy": "ort", + "strategy-option": "ours", + }); + + 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"); + 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("ort"); + expect(args.strategyOption).toEqual("ours"); + }); }); \ No newline at end of file diff --git a/test/service/runner/cli-github-runner.test.ts b/test/service/runner/cli-github-runner.test.ts index 0c203e7..39b5e83 100644 --- a/test/service/runner/cli-github-runner.test.ts +++ b/test/service/runner/cli-github-runner.test.ts @@ -86,7 +86,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(0); expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(0); @@ -115,7 +115,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(0); expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(0); @@ -149,7 +149,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.addRemote).toBeCalledTimes(0); expect(GitCLIService.prototype.addRemote).toBeCalledTimes(0); @@ -186,7 +186,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(0); expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(0); @@ -217,7 +217,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db"); @@ -261,7 +261,7 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db"); @@ -317,7 +317,7 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/4444/head:pr/4444"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "91748965051fae1330ad58d15cf694e103267c87"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "91748965051fae1330ad58d15cf694e103267c87", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9174896"); @@ -374,7 +374,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name"); @@ -430,7 +430,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name"); @@ -478,7 +478,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db"); @@ -525,7 +525,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db"); @@ -568,7 +568,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name"); @@ -614,7 +614,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db"); @@ -659,8 +659,8 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695"); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", undefined, undefined); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3"); @@ -712,7 +712,7 @@ describe("cli runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, truncatedBranch); @@ -731,4 +731,54 @@ describe("cli runner", () => { } ); }); + + test("multiple commits pr with different strategy", async () => { + addProcessArgs([ + "-tb", + "target", + "-pr", + "https://github.com/owner/reponame/pull/8632", + "--no-squash", + "--strategy", + "ort", + "--strategy-option", + "find-renames", + ]); + + await runner.execute(); + + const cwd = process.cwd() + "/bp"; + + expect(GitClientFactory.getOrCreate).toBeCalledTimes(1); + expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com"); + + 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-0404fb9-11da4e3"); + + expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); + + expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", "ort", "find-renames"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151", "ort", "find-renames"); + + expect(GitCLIService.prototype.push).toBeCalledTimes(1); + expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3"); + + expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1); + expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({ + owner: "owner", + repo: "reponame", + head: "bp-target-0404fb9-11da4e3", + base: "target", + title: "[target] PR Title", + body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/8632"), + reviewers: ["gh-user", "that-s-a-user"], + assignees: [], + labels: [], + } + ); + }); }); \ No newline at end of file diff --git a/test/service/runner/cli-gitlab-runner.test.ts b/test/service/runner/cli-gitlab-runner.test.ts index 6db8612..c07e46d 100644 --- a/test/service/runner/cli-gitlab-runner.test.ts +++ b/test/service/runner/cli-gitlab-runner.test.ts @@ -97,7 +97,7 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(0); expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(0); @@ -131,7 +131,7 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined); expect(GitCLIService.prototype.addRemote).toBeCalledTimes(0); expect(GitCLIService.prototype.addRemote).toBeCalledTimes(0); @@ -165,7 +165,7 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9e15674"); @@ -222,7 +222,7 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca"); @@ -280,7 +280,7 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name"); @@ -336,7 +336,7 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name"); @@ -385,7 +385,7 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca"); @@ -433,7 +433,7 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca"); @@ -477,7 +477,7 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-prod-ebb1eca"); @@ -523,8 +523,8 @@ describe("cli runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11"); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "974519f65c9e0ed65277cd71026657a09fca05e7"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "974519f65c9e0ed65277cd71026657a09fca05e7", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336-974519f"); diff --git a/test/service/runner/gha-github-runner.test.ts b/test/service/runner/gha-github-runner.test.ts index bafcf0e..9cbeeb9 100644 --- a/test/service/runner/gha-github-runner.test.ts +++ b/test/service/runner/gha-github-runner.test.ts @@ -80,7 +80,7 @@ describe("gha runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(0); expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(0); @@ -109,7 +109,7 @@ describe("gha runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db"); @@ -161,7 +161,7 @@ describe("gha runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/4444/head:pr/4444"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "91748965051fae1330ad58d15cf694e103267c87"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "91748965051fae1330ad58d15cf694e103267c87", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9174896"); @@ -210,7 +210,7 @@ describe("gha runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name"); @@ -260,7 +260,7 @@ describe("gha runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name"); @@ -305,7 +305,7 @@ describe("gha runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db"); @@ -350,7 +350,7 @@ describe("gha runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db"); @@ -392,7 +392,7 @@ describe("gha runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name"); @@ -436,7 +436,7 @@ describe("gha runner", () => { 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.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db"); @@ -479,8 +479,8 @@ describe("gha runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695"); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", undefined, undefined); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3"); @@ -499,4 +499,49 @@ describe("gha runner", () => { } ); }); + + test("using github api url and different strategy", async () => { + spyGetInput({ + "target-branch": "target", + "pull-request": "https://api.github.com/repos/owner/reponame/pulls/2368", + "strategy": "ort", + "strategy-option": "ours", + }); + + await runner.execute(); + + const cwd = process.cwd() + "/bp"; + + expect(GitClientFactory.getOrCreate).toBeCalledTimes(1); + expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com"); + + 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-28f63db"); + + 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", "ort", "ours"); + + expect(GitCLIService.prototype.push).toBeCalledTimes(1); + expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db"); + + expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1); + expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({ + owner: "owner", + repo: "reponame", + head: "bp-target-28f63db", + 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: [], + } + ); + }); }); \ No newline at end of file diff --git a/test/service/runner/gha-gitlab-runner.test.ts b/test/service/runner/gha-gitlab-runner.test.ts index 65bc3a2..b408c2b 100644 --- a/test/service/runner/gha-gitlab-runner.test.ts +++ b/test/service/runner/gha-gitlab-runner.test.ts @@ -91,7 +91,7 @@ describe("gha runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(0); expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(0); @@ -120,7 +120,7 @@ describe("gha runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9e15674"); @@ -171,7 +171,7 @@ describe("gha runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca"); @@ -220,7 +220,7 @@ describe("gha runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name"); @@ -270,7 +270,7 @@ describe("gha runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name"); @@ -314,7 +314,7 @@ describe("gha runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca"); @@ -357,7 +357,7 @@ describe("gha runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca"); @@ -400,7 +400,7 @@ describe("gha runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledTimes(0); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-prod-ebb1eca"); @@ -444,8 +444,8 @@ describe("gha runner", () => { expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2"); expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11"); - expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "974519f65c9e0ed65277cd71026657a09fca05e7"); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined); + expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "974519f65c9e0ed65277cd71026657a09fca05e7", undefined, undefined); expect(GitCLIService.prototype.push).toBeCalledTimes(1); expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336-974519f");