mirror of
https://code.forgejo.org/actions/git-backporting.git
synced 2025-05-17 02:59:13 -04:00
feat: add --cherry-pick-options to add to all cherry-pick run (#116)
Fixes: https://github.com/kiegroup/git-backporting/issues/111
This commit is contained in:
parent
53cc505f17
commit
fe6be83074
18 changed files with 179 additions and 81 deletions
|
@ -46,6 +46,7 @@ export default abstract class ArgsParser {
|
|||
squash: this.getOrDefault(args.squash, true),
|
||||
strategy: this.getOrDefault(args.strategy),
|
||||
strategyOption: this.getOrDefault(args.strategyOption),
|
||||
cherryPickOptions: this.getOrDefault(args.cherryPickOptions),
|
||||
comments: this.getOrDefault(args.comments)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -25,5 +25,6 @@ export interface Args {
|
|||
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
|
||||
cherryPickOptions?: string, // additional cherry-pick options
|
||||
comments?: string[], // additional comments to be posted
|
||||
}
|
|
@ -31,6 +31,7 @@ export default class CLIArgsParser extends ArgsParser {
|
|||
.option("--no-squash", "if provided the tool will backport all commits as part of the pull request")
|
||||
.option("--strategy <strategy>", "cherry-pick merge strategy, default to 'recursive'", undefined)
|
||||
.option("--strategy-option <strategy-option>", "cherry-pick merge strategy option, default to 'theirs'")
|
||||
.option("--cherry-pick-options <options>", "additional cherry-pick options")
|
||||
.option("--comments <comments>", "semicolon separated list of additional comments to be posted to the backported pull request", getAsSemicolonSeparatedList)
|
||||
.option("-cf, --config-file <config-file>", "configuration file containing all valid options, the json must match Args interface");
|
||||
}
|
||||
|
@ -67,6 +68,7 @@ export default class CLIArgsParser extends ArgsParser {
|
|||
squash: opts.squash,
|
||||
strategy: opts.strategy,
|
||||
strategyOption: opts.strategyOption,
|
||||
cherryPickOptions: opts.cherryPickOptions,
|
||||
comments: opts.comments,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ export default class GHAArgsParser extends ArgsParser {
|
|||
squash: !getAsBooleanOrDefault(getInput("no-squash")),
|
||||
strategy: getOrUndefined(getInput("strategy")),
|
||||
strategyOption: getOrUndefined(getInput("strategy-option")),
|
||||
cherryPickOptions: getOrUndefined(getInput("cherry-pick-options")),
|
||||
comments: getAsSemicolonSeparatedList(getInput("comments")),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ export interface Configs {
|
|||
folder: string,
|
||||
mergeStrategy?: string, // cherry-pick merge strategy
|
||||
mergeStrategyOption?: string, // cherry-pick merge strategy option
|
||||
cherryPickOptions?: string, // additional cherry-pick options
|
||||
originalPullRequest: GitPullRequest,
|
||||
backportPullRequests: BackportPullRequest[],
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ export default class PullRequestConfigsParser extends ConfigsParser {
|
|||
folder: `${folder.startsWith("/") ? "" : process.cwd() + "/"}${args.folder ?? this.getDefaultFolder()}`,
|
||||
mergeStrategy: args.strategy,
|
||||
mergeStrategyOption: args.strategyOption,
|
||||
cherryPickOptions: args.cherryPickOptions,
|
||||
originalPullRequest: pr,
|
||||
backportPullRequests: this.generateBackportPullRequestsData(pr, args, targetBranches, bpBranchNames),
|
||||
git: {
|
||||
|
|
|
@ -110,10 +110,15 @@ 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, strategy = "recursive", strategyOption = "theirs"): Promise<void> {
|
||||
async cherryPick(cwd: string, sha: string, strategy = "recursive", strategyOption = "theirs", cherryPickOptions: string | undefined): Promise<void> {
|
||||
this.logger.info(`Cherry picking ${sha}`);
|
||||
|
||||
const options = ["cherry-pick", "-m", "1", `--strategy=${strategy}`, `--strategy-option=${strategyOption}`, sha];
|
||||
let options = ["cherry-pick", "-m", "1", `--strategy=${strategy}`, `--strategy-option=${strategyOption}`];
|
||||
if (cherryPickOptions !== undefined) {
|
||||
options = options.concat(cherryPickOptions.split(" "));
|
||||
}
|
||||
options.push(sha);
|
||||
this.logger.debug(`Cherry picking command git ${options}`);
|
||||
try {
|
||||
await this.git(cwd).raw(options);
|
||||
} catch(error) {
|
||||
|
|
|
@ -147,7 +147,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.gitCli.cherryPick(configs.folder, sha, configs.mergeStrategy, configs.mergeStrategyOption);
|
||||
await git.gitCli.cherryPick(configs.folder, sha, configs.mergeStrategy, configs.mergeStrategyOption, configs.cherryPickOptions);
|
||||
}
|
||||
|
||||
if (!configs.dryRun) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue