refactor: changed method name and removed useless data

This commit is contained in:
Andrea Lamparelli 2023-06-22 17:57:49 +02:00
parent 99fbcc39cc
commit a30b6d6290
8 changed files with 19 additions and 34 deletions

View file

@ -65,8 +65,8 @@ export default class PullRequestConfigsParser extends ConfigsParser {
targetRepo: originalPullRequest.targetRepo,
sourceRepo: originalPullRequest.targetRepo,
branchName: args.bpBranchName,
nCommits: 0, // TODO: needed?
commits: [] // TODO needed?
// nCommits: 0, // not needed, but required by the
// commits: [] // not needed
};
}
}

View file

@ -25,8 +25,7 @@ export default class GitServiceFactory {
* @param type git management service type
* @param auth authentication, like github token
*/
// TODO rename to getOrCreate
public static init(type: GitServiceType, auth: string): void {
public static getOrCreate(type: GitServiceType, auth: string): void {
if (GitServiceFactory.instance) {
GitServiceFactory.logger.warn("Git service already initialized!");

View file

@ -12,8 +12,8 @@ export interface GitPullRequest {
assignees: string[],
targetRepo: GitRepository,
sourceRepo: GitRepository,
nCommits: number, // number of commits in the pr
commits: string[], // merge commit or last one
nCommits?: number, // number of commits in the pr
commits?: string[], // merge commit or last one
branchName?: string,
}

View file

@ -42,8 +42,6 @@ export default class Runner {
* Entry point invoked by the command line or gha
*/
async run(): Promise<void> {
this.logger.info("Starting process.");
try {
await this.execute();
@ -71,7 +69,7 @@ export default class Runner {
}
// 2. init git service
GitServiceFactory.init(this.inferRemoteGitService(args.pullRequest), args.auth);
GitServiceFactory.getOrCreate(this.inferRemoteGitService(args.pullRequest), args.auth);
const gitApi: GitService = GitServiceFactory.getService();
// 3. parse configs
@ -86,7 +84,7 @@ export default class Runner {
await git.clone(configs.originalPullRequest.targetRepo.cloneUrl, configs.folder, configs.targetBranch);
// 5. create new branch from target one and checkout
const backportBranch = backportPR.branchName ?? `bp-${configs.targetBranch}-${originalPR.commits.join("-")}`;
const backportBranch = backportPR.branchName ?? `bp-${configs.targetBranch}-${originalPR.commits!.join("-")}`;
await git.createLocalBranch(configs.folder, backportBranch);
// 6. fetch pull request remote if source owner != target owner or pull request still open
@ -96,7 +94,7 @@ export default class Runner {
}
// 7. apply all changes to the new branch
for (const sha of originalPR.commits) {
for (const sha of originalPR.commits!) {
await git.cherryPick(configs.folder, sha);
}