diff --git a/action/src/flows/pull-request.ts b/action/src/flows/pull-request.ts index c4ac306bb..ab199177c 100644 --- a/action/src/flows/pull-request.ts +++ b/action/src/flows/pull-request.ts @@ -61,7 +61,7 @@ export class PullRequestFlow extends InBranchFlow { private async ensureFreshPr(i18nBranchName: string) { // Check if PR exists this.ora.start( - `Checking for existing PR with head ${i18nBranchName} and base ${this.platformKit.platformConfig.baseBranchName}`, + `Checking for existing PR with head ${i18nBranchName} and base ${this.platformKit.platformConfig.baseBranchName}` ); const existingPrNumber = await this.platformKit.getOpenPullRequestNumber({ branch: i18nBranchName, @@ -91,7 +91,9 @@ export class PullRequestFlow extends InBranchFlow { this.ora.start(`Posting comment about outdated PR ${existingPrNumber}`); await this.platformKit.commentOnPullRequest({ pullRequestNumber: existingPrNumber, - body: `This PR is now outdated. A new version has been created at ${this.platformKit.buildPullRequestUrl(newPrNumber)}`, + body: `This PR is now outdated. A new version has been created at ${this.platformKit.buildPullRequestUrl( + newPrNumber + )}`, }); this.ora.succeed(`Posted comment about outdated PR ${existingPrNumber}`); } @@ -107,10 +109,22 @@ export class PullRequestFlow extends InBranchFlow { } private createI18nBranch(i18nBranchName: string) { - execSync(`git fetch origin ${this.platformKit.platformConfig.baseBranchName}`, { stdio: "inherit" }); - execSync(`git checkout -b ${i18nBranchName} origin/${this.platformKit.platformConfig.baseBranchName}`, { - stdio: "inherit", - }); + try { + execSync(`git fetch origin ${this.platformKit.platformConfig.baseBranchName}`, { stdio: "inherit" }); + execSync(`git checkout -b ${i18nBranchName} origin/${this.platformKit.platformConfig.baseBranchName}`, { + stdio: "inherit", + }); + } catch (error) { + const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; + this.ora.fail(`Failed to create branch: ${errorMessage}`); + this.ora.info(` + Troubleshooting tips: + 1. Make sure you have permission to create branches + 2. Check if the branch already exists locally (try 'git branch -a') + 3. Verify connectivity to remote repository + `); + throw new Error(`Branch creation failed: ${errorMessage}`); + } } private syncI18nBranch() { @@ -141,7 +155,7 @@ export class PullRequestFlow extends InBranchFlow { const targetFiles = ["i18n.lock"]; const targetFileNames = execSync( `npx lingo.dev@latest show files --target ${this.platformKit.platformConfig.baseBranchName}`, - { encoding: "utf8" }, + { encoding: "utf8" } ) .split("\n") .filter(Boolean); diff --git a/action/src/platforms/bitbucket.ts b/action/src/platforms/bitbucket.ts index 04f1058fc..817e2d5c8 100644 --- a/action/src/platforms/bitbucket.ts +++ b/action/src/platforms/bitbucket.ts @@ -49,7 +49,7 @@ export class BitbucketPlatformKit extends PlatformKit { // https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-get return values?.find( ({ source, destination }) => - source?.branch?.name === branch && destination?.branch?.name === this.platformConfig.baseBranchName, + source?.branch?.name === branch && destination?.branch?.name === this.platformConfig.baseBranchName ); }) .then((pr) => pr?.id); diff --git a/action/src/platforms/github.ts b/action/src/platforms/github.ts index 461241603..0ebf355e2 100644 --- a/action/src/platforms/github.ts +++ b/action/src/platforms/github.ts @@ -1,6 +1,7 @@ import { Octokit } from "octokit"; import { PlatformKit } from "./_base.js"; import Z from "zod"; + import { execSync } from "child_process"; export class GitHubPlatformKit extends PlatformKit { @@ -76,7 +77,9 @@ export class GitHubPlatformKit extends PlatformKit { if (ghToken && processOwnCommits) { console.log("Using provided GH_TOKEN. This will trigger your CI/CD pipeline to run again."); - execSync(`git remote set-url origin https://${ghToken}@github.com/${repositoryOwner}/${repositoryName}.git`, { + const url = `https://${ghToken}@github.com/${repositoryOwner}/${repositoryName}.git`; + + execSync(`git remote set-url origin ${url}`, { stdio: "inherit", }); } diff --git a/action/src/platforms/gitlab.ts b/action/src/platforms/gitlab.ts index f2be0adf1..bff85084b 100644 --- a/action/src/platforms/gitlab.ts +++ b/action/src/platforms/gitlab.ts @@ -81,7 +81,7 @@ export class GitlabPlatformKit extends PlatformKit { title, { description: body, - }, + } ); return mr.iid; } @@ -92,6 +92,7 @@ export class GitlabPlatformKit extends PlatformKit { gitConfig(): Promise | void { const url = `https://oauth2:${this.platformConfig.glToken}@gitlab.com/${this.platformConfig.repositoryOwner}/${this.platformConfig.repositoryName}.git`; + execSync(`git remote set-url origin ${url}`, { stdio: "inherit", });