22
33const fs = require ( "fs-extra" ) ;
44const cp = require ( "child_process" ) ;
5- const Octokit = require ( '@octokit/rest' )
65const path = require ( 'path' ) ;
76const parseGitConfig = require ( 'parse-git-config' ) ;
87
@@ -179,23 +178,21 @@ if (existingUserEmail === undefined) {
179178 cp . execSync ( `git config --local user.email "${ existingUserEmail } "` ) ;
180179}
181180
182- console . log ( `pushing to remove branch (git push -f origin ${ branchName } )` ) ;
181+ console . log ( `pushing to remote branch (git push -f origin ${ branchName } )` ) ;
183182cp . execSync ( `git push -f origin ${ branchName } ` ) ;
184183
185184console . log ( "Checking if there is already a pull request..." ) ;
186- const octokit = new Octokit . Octokit ( { auth : authToken } ) ;
187- octokit . pulls . list ( { owner : repoOwner , repo : repoName } ) . then ( ( { data} ) => {
188- let alreadyHasPullRequest = false ;
189- if ( data ) {
190- data . forEach ( ( pr ) => {
191- alreadyHasPullRequest = alreadyHasPullRequest || ( pr . title === pullRequestTitle ) ;
192- } ) ;
193- }
185+
186+ ( async function ( ) {
187+ const { Octokit } = await import ( "@octokit/rest" ) ;
188+ const octokit = new Octokit ( { auth : authToken } ) ;
189+ const { data } = await octokit . pulls . list ( { owner : repoOwner , repo : repoName } ) ;
190+ let alreadyHasPullRequest = data && data . some ( pr => pr . title === pullRequestTitle ) ;
194191
195192 // If not already present, create a PR against our remote branch.
196193 if ( ! alreadyHasPullRequest ) {
197194 console . log ( "There is not already a pull request. Creating one." ) ;
198- octokit . pulls . create ( { body :"" , owner : repoOwner , repo : repoName , title : pullRequestTitle , head : branchName , base : mergeTo } ) ;
195+ await octokit . pulls . create ( { body :"" , owner : repoOwner , repo : repoName , title : pullRequestTitle , head : branchName , base : mergeTo } ) ;
199196 } else {
200197 console . log ( "There is already a pull request." ) ;
201198 }
@@ -212,4 +209,4 @@ octokit.pulls.list({ owner: repoOwner, repo: repoName }).then(({data}) => {
212209
213210 console . log ( `Remove localization branch (git branch -D localization)` ) ;
214211 cp . execSync ( 'git branch -D localization' ) ;
215- } ) ;
212+ } ) ( ) ;
0 commit comments