Skip to content

Commit 1e69d1a

Browse files
committed
fix(action): refactor gitConfig to reduce redundancy for GitHub, GitLab, and BitBucket
1 parent 71471a7 commit 1e69d1a

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ export class GitHubPlatformKit extends PlatformKit {
7979

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

82-
execSync(`git remote set-url origin ${url}`, {
83-
stdio: "inherit",
84-
});
82+
super.gitConfig(ghToken, url);
8583
}
8684
}
8785

action/src/platforms/gitlab.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ export class GitlabPlatformKit extends PlatformKit {
9191
}
9292

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

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

101100
buildPullRequestUrl(pullRequestNumber: number): string {

0 commit comments

Comments
 (0)