mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-06-28 21:53:47 +00:00
feat: config file as option (#42)
Fix https://github.com/lampajr/backporting/issues/37 This enhancement required a huge refactoring where all arguments defaults have been centralized in one single place ArgsParser#parse
This commit is contained in:
parent
a88adeec35
commit
5ead31f606
27 changed files with 1465 additions and 219 deletions
|
@ -4,7 +4,38 @@ import { Args } from "@bp/service/args/args.types";
|
|||
* Abstract arguments parser interface in charge to parse inputs and
|
||||
* produce a common Args object
|
||||
*/
|
||||
export default interface ArgsParser {
|
||||
export default abstract class ArgsParser {
|
||||
|
||||
parse(): Args;
|
||||
abstract readArgs(): Args;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
private getOrDefault(parsedValue: any, defaultValue?: any) {
|
||||
return parsedValue === undefined ? defaultValue : parsedValue;
|
||||
}
|
||||
|
||||
public parse(): Args {
|
||||
const args = this.readArgs();
|
||||
|
||||
// validate and fill with defaults
|
||||
if (!args.pullRequest || !args.targetBranch) {
|
||||
throw new Error("Missing option: pull request and target branch must be provided");
|
||||
}
|
||||
|
||||
return {
|
||||
pullRequest: args.pullRequest,
|
||||
targetBranch: args.targetBranch,
|
||||
dryRun: this.getOrDefault(args.dryRun, false),
|
||||
auth: this.getOrDefault(args.auth),
|
||||
folder: this.getOrDefault(args.folder),
|
||||
gitUser: this.getOrDefault(args.gitUser),
|
||||
gitEmail: this.getOrDefault(args.gitEmail),
|
||||
title: this.getOrDefault(args.title),
|
||||
body: this.getOrDefault(args.body),
|
||||
bodyPrefix: this.getOrDefault(args.bodyPrefix),
|
||||
bpBranchName: this.getOrDefault(args.bpBranchName),
|
||||
reviewers: this.getOrDefault(args.reviewers, []),
|
||||
assignees: this.getOrDefault(args.assignees, []),
|
||||
inheritReviewers: this.getOrDefault(args.inheritReviewers, true),
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue