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:
Andrea Lamparelli 2023-07-05 22:11:23 +02:00 committed by GitHub
parent a88adeec35
commit 5ead31f606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 1465 additions and 219 deletions

View file

@ -7,17 +7,17 @@ import { GitPullRequest } from "@bp/service/git/git.types";
export default class PullRequestConfigsParser extends ConfigsParser {
private gitService: GitClient;
private gitClient: GitClient;
constructor() {
super();
this.gitService = GitClientFactory.getClient();
this.gitClient = GitClientFactory.getClient();
}
public async parse(args: Args): Promise<Configs> {
let pr: GitPullRequest;
try {
pr = await this.gitService.getPullRequestFromUrl(args.pullRequest);
pr = await this.gitClient.getPullRequestFromUrl(args.pullRequest);
} catch(error) {
this.logger.error("Something went wrong retrieving pull request");
throw error;
@ -26,15 +26,15 @@ export default class PullRequestConfigsParser extends ConfigsParser {
const folder: string = args.folder ?? this.getDefaultFolder();
return {
dryRun: args.dryRun,
dryRun: args.dryRun!,
auth: args.auth,
folder: `${folder.startsWith("/") ? "" : process.cwd() + "/"}${args.folder ?? this.getDefaultFolder()}`,
targetBranch: args.targetBranch,
originalPullRequest: pr,
backportPullRequest: this.getDefaultBackportPullRequest(pr, args),
git: {
user: args.gitUser,
email: args.gitEmail,
user: args.gitUser ?? this.gitClient.getDefaultGitUser(),
email: args.gitEmail ?? this.gitClient.getDefaultGitEmail(),
}
};
}
@ -64,7 +64,7 @@ export default class PullRequestConfigsParser extends ConfigsParser {
const body = args.body ?? `${originalPullRequest.body}`;
return {
author: args.gitUser,
author: args.gitUser ?? this.gitClient.getDefaultGitUser(),
title: args.title ?? `[${args.targetBranch}] ${originalPullRequest.title}`,
body: `${bodyPrefix}${body}`,
reviewers: [...new Set(reviewers)],