Skip to content

Commit 730968a

Browse files
SXsidmaxprilutskiy
andauthored
refactor: move gitConfig logic to parent and call it in child using super.gitConfig() (#590)
* fix(git): add more robust error handling for Git operation * revert: multi-platform refactoring to align with issue changes requested * fix(action): refactor gitConfig to reduce redundancy for GitHub, GitLab, and BitBucket * refactor: remove unnecessary imports --------- Co-authored-by: Max Prilutskiy <[email protected]>
1 parent 919d037 commit 730968a

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

action/src/platforms/_base.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { execSync } from "child_process";
12
import Z from "zod";
23

34
const defaultMessage = "feat: update translations via @lingodotdev";
@@ -23,7 +24,13 @@ export abstract class PlatformKit<PlatformConfig extends BasePlatformConfig = Ba
2324

2425
abstract buildPullRequestUrl(pullRequestNumber: number): string;
2526

26-
gitConfig(): Promise<void> | void {}
27+
gitConfig(token?: string, repoUrl?: string) {
28+
if (token && repoUrl) {
29+
execSync(`git remote set-url origin ${repoUrl}`, {
30+
stdio: "inherit",
31+
});
32+
}
33+
}
2734

2835
get config() {
2936
const env = Z.object({

action/src/platforms/github.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { Octokit } from "octokit";
22
import { PlatformKit } from "./_base.js";
33
import Z from "zod";
44

5-
import { execSync } from "child_process";
6-
75
export class GitHubPlatformKit extends PlatformKit {
86
private _octokit?: Octokit;
97

@@ -79,9 +77,7 @@ export class GitHubPlatformKit extends PlatformKit {
7977

8078
const url = `https://${ghToken}@github.com/${repositoryOwner}/${repositoryName}.git`;
8179

82-
execSync(`git remote set-url origin ${url}`, {
83-
stdio: "inherit",
84-
});
80+
super.gitConfig(ghToken, url);
8581
}
8682
}
8783

action/src/platforms/gitlab.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Gitlab } from "@gitbeaker/rest";
22
import Z from "zod";
33
import { PlatformKit } from "./_base.js";
4-
import { execSync } from "child_process";
54

65
const gl = new Gitlab({ token: "" });
76

@@ -91,11 +90,10 @@ export class GitlabPlatformKit extends PlatformKit {
9190
}
9291

9392
gitConfig(): Promise<void> | void {
94-
const url = `https://oauth2:${this.platformConfig.glToken}@gitlab.com/${this.platformConfig.repositoryOwner}/${this.platformConfig.repositoryName}.git`;
93+
const glToken = this.platformConfig.glToken;
94+
const url = `https://oauth2:${glToken}@gitlab.com/${this.platformConfig.repositoryOwner}/${this.platformConfig.repositoryName}.git`;
9595

96-
execSync(`git remote set-url origin ${url}`, {
97-
stdio: "inherit",
98-
});
96+
super.gitConfig(glToken, url);
9997
}
10098

10199
buildPullRequestUrl(pullRequestNumber: number): string {

0 commit comments

Comments
 (0)