mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-07-01 23:23:46 +00:00
feat(gh75): extract target branched from pr labels (#112)
This commit is contained in:
parent
b2e2e271b9
commit
53cc505f17
20 changed files with 523 additions and 83 deletions
|
@ -16,14 +16,18 @@ export default abstract class ArgsParser {
|
|||
public parse(): Args {
|
||||
const args = this.readArgs();
|
||||
|
||||
if (!args.pullRequest) {
|
||||
throw new Error("Missing option: pull request must be provided");
|
||||
}
|
||||
// validate and fill with defaults
|
||||
if (!args.pullRequest || !args.targetBranch || args.targetBranch.trim().length == 0) {
|
||||
throw new Error("Missing option: pull request and target branches must be provided");
|
||||
if ((!args.targetBranch || args.targetBranch.trim().length == 0) && !args.targetBranchPattern) {
|
||||
throw new Error("Missing option: target branch(es) or target regular expression must be provided");
|
||||
}
|
||||
|
||||
return {
|
||||
pullRequest: args.pullRequest,
|
||||
targetBranch: args.targetBranch,
|
||||
targetBranchPattern: args.targetBranchPattern,
|
||||
dryRun: this.getOrDefault(args.dryRun, false),
|
||||
auth: this.getOrDefault(args.auth),
|
||||
folder: this.getOrDefault(args.folder),
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
*/
|
||||
export interface Args {
|
||||
// NOTE: keep targetBranch as singular and of type string for backward compatibilities
|
||||
targetBranch: string, // comma separated list of branches on the target repo where the change should be backported to
|
||||
targetBranch?: string, // comma separated list of branches on the target repo where the change should be backported to
|
||||
targetBranchPattern?: string, // regular expression to extract target branch(es) from pull request labels
|
||||
pullRequest: string, // url of the pull request to backport
|
||||
dryRun?: boolean, // if enabled do not push anything remotely
|
||||
auth?: string, // git service auth, like github token
|
||||
|
|
|
@ -11,6 +11,7 @@ export default class CLIArgsParser extends ArgsParser {
|
|||
.version(version)
|
||||
.description(description)
|
||||
.option("-tb, --target-branch <branches>", "comma separated list of branches where changes must be backported to")
|
||||
.option("-tbp, --target-branch-pattern <pattern>", "regular expression pattern to extract target branch(es) from pr labels, the branches will be extracted from the pattern's required `target` named capturing group")
|
||||
.option("-pr, --pull-request <pr-url>", "pull request url, e.g., https://github.com/kiegroup/git-backporting/pull/1")
|
||||
.option("-d, --dry-run", "if enabled the tool does not create any pull request nor push anything remotely")
|
||||
.option("-a, --auth <auth>", "git authentication string, if not provided fallback by looking for existing env variables like GITHUB_TOKEN")
|
||||
|
@ -49,6 +50,7 @@ export default class CLIArgsParser extends ArgsParser {
|
|||
auth: opts.auth,
|
||||
pullRequest: opts.pullRequest,
|
||||
targetBranch: opts.targetBranch,
|
||||
targetBranchPattern: opts.targetBranchPattern,
|
||||
folder: opts.folder,
|
||||
gitClient: opts.gitClient,
|
||||
gitUser: opts.gitUser,
|
||||
|
|
|
@ -16,7 +16,8 @@ export default class GHAArgsParser extends ArgsParser {
|
|||
dryRun: getAsBooleanOrDefault(getInput("dry-run")),
|
||||
auth: getOrUndefined(getInput("auth")),
|
||||
pullRequest: getInput("pull-request"),
|
||||
targetBranch: getInput("target-branch"),
|
||||
targetBranch: getOrUndefined(getInput("target-branch")),
|
||||
targetBranchPattern: getOrUndefined(getInput("target-reg-exp")),
|
||||
folder: getOrUndefined(getInput("folder")),
|
||||
gitClient: getOrUndefined(getInput("git-client")),
|
||||
gitUser: getOrUndefined(getInput("git-user")),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue