mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-04-25 21:02:13 +00:00
37 lines
No EOL
1.2 KiB
TypeScript
37 lines
No EOL
1.2 KiB
TypeScript
import { Args } from "@bp/service/args/args.types";
|
|
import { Configs } from "@bp/service/configs/configs.types";
|
|
import LoggerService from "../logger/logger-service";
|
|
import LoggerServiceFactory from "../logger/logger-service-factory";
|
|
|
|
/**
|
|
* Abstract configuration parser class in charge to parse
|
|
* Args and produces a common Configs object
|
|
*/
|
|
export default abstract class ConfigsParser {
|
|
|
|
private readonly logger: LoggerService;
|
|
|
|
constructor() {
|
|
this.logger = LoggerServiceFactory.getLogger();
|
|
}
|
|
|
|
abstract parse(args: Args): Promise<Configs>;
|
|
|
|
async parseAndValidate(args: Args): Promise<Configs> {
|
|
const configs: Configs = await this.parse(args);
|
|
|
|
// apply validation, throw errors if something is wrong
|
|
|
|
// if pr is opened check if the there exists one single commit
|
|
if (configs.originalPullRequest.state == "open") {
|
|
this.logger.warn("Trying to backport an open pull request!");
|
|
}
|
|
|
|
// if PR is closed and not merged log a warning
|
|
if (configs.originalPullRequest.state == "closed" && !configs.originalPullRequest.merged) {
|
|
throw new Error("Provided pull request is closed and not merged!");
|
|
}
|
|
|
|
return Promise.resolve(configs);
|
|
}
|
|
} |