11import { execSync } from "child_process" ;
2- import { InBranchFlow } from "./in-branch.js " ;
2+ import { InBranchFlow } from "./in-branch" ;
33
44export class PullRequestFlow extends InBranchFlow {
55 async preRun ( ) {
@@ -10,7 +10,9 @@ export class PullRequestFlow extends InBranchFlow {
1010
1111 this . ora . start ( "Calculating automated branch name" ) ;
1212 this . i18nBranchName = this . calculatePrBranchName ( ) ;
13- this . ora . succeed ( `Automated branch name calculated: ${ this . i18nBranchName } ` ) ;
13+ this . ora . succeed (
14+ `Automated branch name calculated: ${ this . i18nBranchName } ` ,
15+ ) ;
1416
1517 this . ora . start ( "Checking if branch exists" ) ;
1618 const branchExists = await this . checkBranchExistance ( this . i18nBranchName ) ;
@@ -21,7 +23,9 @@ export class PullRequestFlow extends InBranchFlow {
2123 this . checkoutI18nBranch ( this . i18nBranchName ) ;
2224 this . ora . succeed ( `Checked out branch ${ this . i18nBranchName } ` ) ;
2325
24- this . ora . start ( `Syncing with ${ this . platformKit . platformConfig . baseBranchName } ` ) ;
26+ this . ora . start (
27+ `Syncing with ${ this . platformKit . platformConfig . baseBranchName } ` ,
28+ ) ;
2529 this . syncI18nBranch ( ) ;
2630 this . ora . succeed ( `Checked out and synced branch ${ this . i18nBranchName } ` ) ;
2731 } else {
@@ -39,13 +43,17 @@ export class PullRequestFlow extends InBranchFlow {
3943
4044 async postRun ( ) {
4145 if ( ! this . i18nBranchName ) {
42- throw new Error ( "i18nBranchName is not set. Did you forget to call preRun?" ) ;
46+ throw new Error (
47+ "i18nBranchName is not set. Did you forget to call preRun?" ,
48+ ) ;
4349 }
4450
4551 this . ora . start ( "Checking if PR already exists" ) ;
4652 const pullRequestNumber = await this . ensureFreshPr ( this . i18nBranchName ) ;
4753 // await this.createLabelIfNotExists(pullRequestNumber, 'lingo.dev/i18n', false);
48- this . ora . succeed ( `Pull request ready: ${ this . platformKit . buildPullRequestUrl ( pullRequestNumber ) } ` ) ;
54+ this . ora . succeed (
55+ `Pull request ready: ${ this . platformKit . buildPullRequestUrl ( pullRequestNumber ) } ` ,
56+ ) ;
4957 }
5058
5159 private calculatePrBranchName ( ) : string {
@@ -61,7 +69,7 @@ export class PullRequestFlow extends InBranchFlow {
6169 private async ensureFreshPr ( i18nBranchName : string ) {
6270 // Check if PR exists
6371 this . ora . start (
64- `Checking for existing PR with head ${ i18nBranchName } and base ${ this . platformKit . platformConfig . baseBranchName } `
72+ `Checking for existing PR with head ${ i18nBranchName } and base ${ this . platformKit . platformConfig . baseBranchName } ` ,
6573 ) ;
6674 let prNumber = await this . platformKit . getOpenPullRequestNumber ( {
6775 branch : i18nBranchName ,
@@ -92,12 +100,19 @@ export class PullRequestFlow extends InBranchFlow {
92100
93101 private createI18nBranch ( i18nBranchName : string ) {
94102 try {
95- execSync ( `git fetch origin ${ this . platformKit . platformConfig . baseBranchName } ` , { stdio : "inherit" } ) ;
96- execSync ( `git checkout -b ${ i18nBranchName } origin/${ this . platformKit . platformConfig . baseBranchName } ` , {
97- stdio : "inherit" ,
98- } ) ;
103+ execSync (
104+ `git fetch origin ${ this . platformKit . platformConfig . baseBranchName } ` ,
105+ { stdio : "inherit" } ,
106+ ) ;
107+ execSync (
108+ `git checkout -b ${ i18nBranchName } origin/${ this . platformKit . platformConfig . baseBranchName } ` ,
109+ {
110+ stdio : "inherit" ,
111+ } ,
112+ ) ;
99113 } catch ( error ) {
100- const errorMessage = error instanceof Error ? error . message : "Unknown error occurred" ;
114+ const errorMessage =
115+ error instanceof Error ? error . message : "Unknown error occurred" ;
101116 this . ora . fail ( `Failed to create branch: ${ errorMessage } ` ) ;
102117 this . ora . info ( `
103118 Troubleshooting tips:
@@ -114,13 +129,23 @@ export class PullRequestFlow extends InBranchFlow {
114129 throw new Error ( "i18nBranchName is not set" ) ;
115130 }
116131
117- this . ora . start ( `Fetching latest changes from ${ this . platformKit . platformConfig . baseBranchName } ` ) ;
118- execSync ( `git fetch origin ${ this . platformKit . platformConfig . baseBranchName } ` , { stdio : "inherit" } ) ;
119- this . ora . succeed ( `Fetched latest changes from ${ this . platformKit . platformConfig . baseBranchName } ` ) ;
132+ this . ora . start (
133+ `Fetching latest changes from ${ this . platformKit . platformConfig . baseBranchName } ` ,
134+ ) ;
135+ execSync (
136+ `git fetch origin ${ this . platformKit . platformConfig . baseBranchName } ` ,
137+ { stdio : "inherit" } ,
138+ ) ;
139+ this . ora . succeed (
140+ `Fetched latest changes from ${ this . platformKit . platformConfig . baseBranchName } ` ,
141+ ) ;
120142
121143 try {
122144 this . ora . start ( "Attempting to rebase branch" ) ;
123- execSync ( `git rebase origin/${ this . platformKit . platformConfig . baseBranchName } ` , { stdio : "inherit" } ) ;
145+ execSync (
146+ `git rebase origin/${ this . platformKit . platformConfig . baseBranchName } ` ,
147+ { stdio : "inherit" } ,
148+ ) ;
124149 this . ora . succeed ( "Successfully rebased branch" ) ;
125150 } catch ( error ) {
126151 this . ora . warn ( "Rebase failed, falling back to alternative sync method" ) ;
@@ -129,15 +154,22 @@ export class PullRequestFlow extends InBranchFlow {
129154 execSync ( "git rebase --abort" , { stdio : "inherit" } ) ;
130155 this . ora . succeed ( "Aborted failed rebase" ) ;
131156
132- this . ora . start ( `Resetting to ${ this . platformKit . platformConfig . baseBranchName } ` ) ;
133- execSync ( `git reset --hard origin/${ this . platformKit . platformConfig . baseBranchName } ` , { stdio : "inherit" } ) ;
134- this . ora . succeed ( `Reset to ${ this . platformKit . platformConfig . baseBranchName } ` ) ;
157+ this . ora . start (
158+ `Resetting to ${ this . platformKit . platformConfig . baseBranchName } ` ,
159+ ) ;
160+ execSync (
161+ `git reset --hard origin/${ this . platformKit . platformConfig . baseBranchName } ` ,
162+ { stdio : "inherit" } ,
163+ ) ;
164+ this . ora . succeed (
165+ `Reset to ${ this . platformKit . platformConfig . baseBranchName } ` ,
166+ ) ;
135167
136168 this . ora . start ( "Restoring target files" ) ;
137169 const targetFiles = [ "i18n.lock" ] ;
138170 const targetFileNames = execSync (
139171 `npx lingo.dev@latest show files --target ${ this . platformKit . platformConfig . baseBranchName } ` ,
140- { encoding : "utf8" }
172+ { encoding : "utf8" } ,
141173 )
142174 . split ( "\n" )
143175 . filter ( Boolean ) ;
@@ -160,9 +192,12 @@ export class PullRequestFlow extends InBranchFlow {
160192 const hasChanges = this . checkCommitableChanges ( ) ;
161193 if ( hasChanges ) {
162194 execSync ( "git add ." , { stdio : "inherit" } ) ;
163- execSync ( `git commit -m "chore: sync with ${ this . platformKit . platformConfig . baseBranchName } "` , {
164- stdio : "inherit" ,
165- } ) ;
195+ execSync (
196+ `git commit -m "chore: sync with ${ this . platformKit . platformConfig . baseBranchName } "` ,
197+ {
198+ stdio : "inherit" ,
199+ } ,
200+ ) ;
166201 this . ora . succeed ( "Committed additional changes" ) ;
167202 } else {
168203 this . ora . succeed ( "No changes to commit" ) ;
0 commit comments