2
2
3
3
const fs = require ( "fs-extra" ) ;
4
4
const cp = require ( "child_process" ) ;
5
- const Octokit = require ( '@octokit/rest' )
6
5
const path = require ( 'path' ) ;
7
6
const parseGitConfig = require ( 'parse-git-config' ) ;
8
7
@@ -179,23 +178,21 @@ if (existingUserEmail === undefined) {
179
178
cp . execSync ( `git config --local user.email "${ existingUserEmail } "` ) ;
180
179
}
181
180
182
- console . log ( `pushing to remove branch (git push -f origin ${ branchName } )` ) ;
181
+ console . log ( `pushing to remote branch (git push -f origin ${ branchName } )` ) ;
183
182
cp . execSync ( `git push -f origin ${ branchName } ` ) ;
184
183
185
184
console . 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 ) ;
194
191
195
192
// If not already present, create a PR against our remote branch.
196
193
if ( ! alreadyHasPullRequest ) {
197
194
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 } ) ;
199
196
} else {
200
197
console . log ( "There is already a pull request." ) ;
201
198
}
@@ -212,4 +209,4 @@ octokit.pulls.list({ owner: repoOwner, repo: repoName }).then(({data}) => {
212
209
213
210
console . log ( `Remove localization branch (git branch -D localization)` ) ;
214
211
cp . execSync ( 'git branch -D localization' ) ;
215
- } ) ;
212
+ } ) ( ) ;
0 commit comments