mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-07-01 23:23:46 +00: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
|
@ -36,6 +36,8 @@ export default abstract class ArgsParser {
|
|||
reviewers: this.getOrDefault(args.reviewers, []),
|
||||
assignees: this.getOrDefault(args.assignees, []),
|
||||
inheritReviewers: this.getOrDefault(args.inheritReviewers, true),
|
||||
labels: this.getOrDefault(args.labels, []),
|
||||
inheritLabels: this.getOrDefault(args.inheritLabels, false),
|
||||
};
|
||||
}
|
||||
}
|
|
@ -19,4 +19,32 @@ export function parseArgs(configFileContent: string): Args {
|
|||
export function readConfigFile(pathToFile: string): Args {
|
||||
const asString: string = fs.readFileSync(pathToFile, "utf-8");
|
||||
return parseArgs(asString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the input only if it is not a blank or null string, otherwise returns undefined
|
||||
* @param key input key
|
||||
* @returns the value or undefined
|
||||
*/
|
||||
export function getOrUndefined(value: string): string | undefined {
|
||||
return value !== "" ? value : undefined;
|
||||
}
|
||||
|
||||
// get rid of inner spaces too
|
||||
export function getAsCleanedCommaSeparatedList(value: string): string[] | undefined {
|
||||
// trim the value
|
||||
const trimmed: string = value.trim();
|
||||
return trimmed !== "" ? trimmed.replace(/\s/g, "").split(",") : undefined;
|
||||
}
|
||||
|
||||
// preserve inner spaces
|
||||
export function getAsCommaSeparatedList(value: string): string[] | undefined {
|
||||
// trim the value
|
||||
const trimmed: string = value.trim();
|
||||
return trimmed !== "" ? trimmed.split(",").map(v => v.trim()) : undefined;
|
||||
}
|
||||
|
||||
export function getAsBooleanOrDefault(value: string): boolean | undefined {
|
||||
const trimmed = value.trim();
|
||||
return trimmed !== "" ? trimmed.toLowerCase() === "true" : undefined;
|
||||
}
|
|
@ -16,4 +16,6 @@ export interface Args {
|
|||
reviewers?: string[], // backport pr reviewers
|
||||
assignees?: string[], // backport pr assignees
|
||||
inheritReviewers?: boolean, // if true and reviewers == [] then inherit reviewers from original pr
|
||||
labels?: string[], // backport pr labels
|
||||
inheritLabels?: boolean, // if true inherit labels from original pr
|
||||
}
|
|
@ -2,13 +2,7 @@ import ArgsParser from "@bp/service/args/args-parser";
|
|||
import { Args } from "@bp/service/args/args.types";
|
||||
import { Command } from "commander";
|
||||
import { name, version, description } from "@bp/../package.json";
|
||||
import { readConfigFile } from "@bp/service/args/args-utils";
|
||||
|
||||
function commaSeparatedList(value: string, _prev: unknown): string[] {
|
||||
// remove all whitespaces
|
||||
const cleanedValue: string = value.trim();
|
||||
return cleanedValue !== "" ? cleanedValue.replace(/\s/g, "").split(",") : [];
|
||||
}
|
||||
import { getAsCleanedCommaSeparatedList, getAsCommaSeparatedList, readConfigFile } from "@bp/service/args/args-utils";
|
||||
|
||||
export default class CLIArgsParser extends ArgsParser {
|
||||
|
||||
|
@ -16,21 +10,23 @@ export default class CLIArgsParser extends ArgsParser {
|
|||
return new Command(name)
|
||||
.version(version)
|
||||
.description(description)
|
||||
.option("-tb, --target-branch <branch>", "branch where changes must be backported to.")
|
||||
.option("-pr, --pull-request <pr-url>", "pull request url, e.g., https://github.com/kiegroup/git-backporting/pull/1.")
|
||||
.option("-tb, --target-branch <branch>", "branch where changes must be backported to")
|
||||
.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 service authentication string, e.g., github token.")
|
||||
.option("-gu, --git-user <git-user>", "local git user name, default is 'GitHub'.")
|
||||
.option("-ge, --git-email <git-email>", "local git user email, default is 'noreply@github.com'.")
|
||||
.option("-f, --folder <folder>", "local folder where the repo will be checked out, e.g., /tmp/folder.")
|
||||
.option("--title <bp-title>", "backport pr title, default original pr title prefixed by target branch.")
|
||||
.option("--body <bp-body>", "backport pr title, default original pr body prefixed by bodyPrefix.")
|
||||
.option("--body-prefix <bp-body-prefix>", "backport pr body prefix, default `backport <original-pr-link>`.")
|
||||
.option("--bp-branch-name <bp-branch-name>", "backport pr branch name, default auto-generated by the commit.")
|
||||
.option("--reviewers <reviewers>", "comma separated list of reviewers for the backporting pull request.", commaSeparatedList)
|
||||
.option("--assignees <assignees>", "comma separated list of assignees for the backporting pull request.", commaSeparatedList)
|
||||
.option("-a, --auth <auth>", "git service authentication string, e.g., github token")
|
||||
.option("-gu, --git-user <git-user>", "local git user name, default is 'GitHub'")
|
||||
.option("-ge, --git-email <git-email>", "local git user email, default is 'noreply@github.com'")
|
||||
.option("-f, --folder <folder>", "local folder where the repo will be checked out, e.g., /tmp/folder")
|
||||
.option("--title <bp-title>", "backport pr title, default original pr title prefixed by target branch")
|
||||
.option("--body <bp-body>", "backport pr title, default original pr body prefixed by bodyPrefix")
|
||||
.option("--body-prefix <bp-body-prefix>", "backport pr body prefix, default `backport <original-pr-link>`")
|
||||
.option("--bp-branch-name <bp-branch-name>", "backport pr branch name, default auto-generated by the commit")
|
||||
.option("--reviewers <reviewers>", "comma separated list of reviewers for the backporting pull request", getAsCleanedCommaSeparatedList)
|
||||
.option("--assignees <assignees>", "comma separated list of assignees for the backporting pull request", getAsCleanedCommaSeparatedList)
|
||||
.option("--no-inherit-reviewers", "if provided and reviewers option is empty then inherit them from original pull request")
|
||||
.option("-cf, --config-file <config-file>", "configuration file containing all valid options, the json must match Args interface.");
|
||||
.option("--labels <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("-cf, --config-file <config-file>", "configuration file containing all valid options, the json must match Args interface");
|
||||
}
|
||||
|
||||
readArgs(): Args {
|
||||
|
@ -58,6 +54,8 @@ export default class CLIArgsParser extends ArgsParser {
|
|||
reviewers: opts.reviewers,
|
||||
assignees: opts.assignees,
|
||||
inheritReviewers: opts.inheritReviewers,
|
||||
labels: opts.labels,
|
||||
inheritLabels: opts.inheritLabels,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,53 +1,34 @@
|
|||
import ArgsParser from "@bp/service/args/args-parser";
|
||||
import { Args } from "@bp/service/args/args.types";
|
||||
import { getInput } from "@actions/core";
|
||||
import { readConfigFile } from "@bp/service/args/args-utils";
|
||||
import { getAsBooleanOrDefault, getAsCleanedCommaSeparatedList, getAsCommaSeparatedList, getOrUndefined, readConfigFile } from "@bp/service/args/args-utils";
|
||||
|
||||
export default class GHAArgsParser extends ArgsParser {
|
||||
|
||||
/**
|
||||
* Return the input only if it is not a blank or null string, otherwise returns undefined
|
||||
* @param key input key
|
||||
* @returns the value or undefined
|
||||
*/
|
||||
public getOrUndefined(key: string): string | undefined {
|
||||
const value = getInput(key);
|
||||
return value !== "" ? value : undefined;
|
||||
}
|
||||
|
||||
public getAsCommaSeparatedList(key: string): string[] | undefined {
|
||||
// trim the value
|
||||
const value: string = (getInput(key) ?? "").trim();
|
||||
return value !== "" ? value.replace(/\s/g, "").split(",") : undefined;
|
||||
}
|
||||
|
||||
private getAsBooleanOrDefault(key: string): boolean | undefined {
|
||||
const value = getInput(key).trim();
|
||||
return value !== "" ? value.toLowerCase() === "true" : undefined;
|
||||
}
|
||||
|
||||
readArgs(): Args {
|
||||
const configFile = this.getOrUndefined("config-file");
|
||||
const configFile = getOrUndefined(getInput("config-file"));
|
||||
|
||||
let args: Args;
|
||||
if (configFile) {
|
||||
args = readConfigFile(configFile);
|
||||
} else {
|
||||
args = {
|
||||
dryRun: this.getAsBooleanOrDefault("dry-run"),
|
||||
auth: this.getOrUndefined("auth"),
|
||||
dryRun: getAsBooleanOrDefault(getInput("dry-run")),
|
||||
auth: getOrUndefined(getInput("auth")),
|
||||
pullRequest: getInput("pull-request"),
|
||||
targetBranch: getInput("target-branch"),
|
||||
folder: this.getOrUndefined("folder"),
|
||||
gitUser: this.getOrUndefined("git-user"),
|
||||
gitEmail: this.getOrUndefined("git-email"),
|
||||
title: this.getOrUndefined("title"),
|
||||
body: this.getOrUndefined("body"),
|
||||
bodyPrefix: this.getOrUndefined("body-prefix"),
|
||||
bpBranchName: this.getOrUndefined("bp-branch-name"),
|
||||
reviewers: this.getAsCommaSeparatedList("reviewers"),
|
||||
assignees: this.getAsCommaSeparatedList("assignees"),
|
||||
inheritReviewers: !this.getAsBooleanOrDefault("no-inherit-reviewers"),
|
||||
folder: getOrUndefined(getInput("folder")),
|
||||
gitUser: getOrUndefined(getInput("git-user")),
|
||||
gitEmail: getOrUndefined(getInput("git-email")),
|
||||
title: getOrUndefined(getInput("title")),
|
||||
body: getOrUndefined(getInput("body")),
|
||||
bodyPrefix: getOrUndefined(getInput("body-prefix")),
|
||||
bpBranchName: getOrUndefined(getInput("bp-branch-name")),
|
||||
reviewers: getAsCleanedCommaSeparatedList(getInput("reviewers")),
|
||||
assignees: getAsCleanedCommaSeparatedList(getInput("assignees")),
|
||||
inheritReviewers: !getAsBooleanOrDefault(getInput("no-inherit-reviewers")),
|
||||
labels: getAsCommaSeparatedList(getInput("labels")),
|
||||
inheritLabels: getAsBooleanOrDefault(getInput("inherit-labels")),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue