diff --git a/action/src/platforms/_base.ts b/action/src/platforms/_base.ts index d1e1fe7b2..8a58a9aa0 100644 --- a/action/src/platforms/_base.ts +++ b/action/src/platforms/_base.ts @@ -1,3 +1,4 @@ +import { execSync } from "child_process"; import Z from "zod"; const defaultMessage = "feat: update translations via @lingodotdev"; @@ -23,7 +24,13 @@ export abstract class PlatformKit | void {} + gitConfig(token?: string, repoUrl?: string) { + if (token && repoUrl) { + execSync(`git remote set-url origin ${repoUrl}`, { + stdio: "inherit", + }); + } + } get config() { const env = Z.object({ diff --git a/action/src/platforms/github.ts b/action/src/platforms/github.ts index 313eab55a..89391bff9 100644 --- a/action/src/platforms/github.ts +++ b/action/src/platforms/github.ts @@ -2,8 +2,6 @@ import { Octokit } from "octokit"; import { PlatformKit } from "./_base.js"; import Z from "zod"; -import { execSync } from "child_process"; - export class GitHubPlatformKit extends PlatformKit { private _octokit?: Octokit; @@ -79,9 +77,7 @@ export class GitHubPlatformKit extends PlatformKit { const url = `https://${ghToken}@github.com/${repositoryOwner}/${repositoryName}.git`; - execSync(`git remote set-url origin ${url}`, { - stdio: "inherit", - }); + super.gitConfig(ghToken, url); } } diff --git a/action/src/platforms/gitlab.ts b/action/src/platforms/gitlab.ts index 8e52e7700..1b49f0836 100644 --- a/action/src/platforms/gitlab.ts +++ b/action/src/platforms/gitlab.ts @@ -1,7 +1,6 @@ import { Gitlab } from "@gitbeaker/rest"; import Z from "zod"; import { PlatformKit } from "./_base.js"; -import { execSync } from "child_process"; const gl = new Gitlab({ token: "" }); @@ -91,11 +90,10 @@ export class GitlabPlatformKit extends PlatformKit { } gitConfig(): Promise | void { - const url = `https://oauth2:${this.platformConfig.glToken}@gitlab.com/${this.platformConfig.repositoryOwner}/${this.platformConfig.repositoryName}.git`; + const glToken = this.platformConfig.glToken; + const url = `https://oauth2:${glToken}@gitlab.com/${this.platformConfig.repositoryOwner}/${this.platformConfig.repositoryName}.git`; - execSync(`git remote set-url origin ${url}`, { - stdio: "inherit", - }); + super.gitConfig(glToken, url); } buildPullRequestUrl(pullRequestNumber: number): string {