22
33const fs = require ( "fs-extra" ) ;
44const cp = require ( "child_process" ) ;
5- let Octokit ;
6- import ( '@octokit/rest' ) . then ( module => {
7- Octokit = module . Octokit ;
8- } ) ;
95const path = require ( 'path' ) ;
106const parseGitConfig = require ( 'parse-git-config' ) ;
117
@@ -186,19 +182,17 @@ console.log(`pushing to remote branch (git push -f origin ${branchName})`);
186182cp . execSync ( `git push -f origin ${ branchName } ` ) ;
187183
188184console . log ( "Checking if there is already a pull request..." ) ;
189- const octokit = new Octokit . Octokit ( { auth : authToken } ) ;
190- octokit . pulls . list ( { owner : repoOwner , repo : repoName } ) . then ( ( { data} ) => {
191- let alreadyHasPullRequest = false ;
192- if ( data ) {
193- data . forEach ( ( pr ) => {
194- alreadyHasPullRequest = alreadyHasPullRequest || ( pr . title === pullRequestTitle ) ;
195- } ) ;
196- }
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 ) ;
197191
198192 // If not already present, create a PR against our remote branch.
199193 if ( ! alreadyHasPullRequest ) {
200194 console . log ( "There is not already a pull request. Creating one." ) ;
201- 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 } ) ;
202196 } else {
203197 console . log ( "There is already a pull request." ) ;
204198 }
@@ -215,4 +209,4 @@ octokit.pulls.list({ owner: repoOwner, repo: repoName }).then(({data}) => {
215209
216210 console . log ( `Remove localization branch (git branch -D localization)` ) ;
217211 cp . execSync ( 'git branch -D localization' ) ;
218- } ) ;
212+ } ) ( ) ;
0 commit comments