File tree 2 files changed +56
-1
lines changed 2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change 1
1
"use strict" ;
2
2
3
3
import * as GitHubApi from "@octokit/rest" ;
4
+ import { ReposCreateParams } from "@octokit/rest" ;
4
5
import * as HttpsProxyAgent from "https-proxy-agent" ;
5
6
import * as vscode from "vscode" ;
6
7
import { File } from "./fileService" ;
@@ -154,4 +155,10 @@ export class GitHubService {
154
155
await this . github . gists . edit ( gistObject ) ;
155
156
return true ;
156
157
}
158
+
159
+ public async MakeRepository (
160
+ options : GitHubApi . ReposCreateParams
161
+ ) : Promise < GitHubApi . Response < GitHubApi . ReposCreateResponse > > {
162
+ return await this . github . repos . create ( options ) ;
163
+ }
157
164
}
Original file line number Diff line number Diff line change @@ -262,7 +262,55 @@ export class Sync {
262
262
await localgit . Add ( allSettingFiles ) ;
263
263
await localgit . Commit ( dateNow . toString ( ) ) ;
264
264
if ( syncSetting . repoUrl && customSettings . repoPush ) {
265
- await localgit . Push ( ) ;
265
+ try {
266
+ await localgit . Push ( ) ;
267
+ } catch ( err ) {
268
+ if ( err . message . indexOf ( "Repository not found" ) ) {
269
+ if ( customSettings . token === "" ) {
270
+ if ( customSettings . openTokenLink ) {
271
+ vscode . commands . executeCommand (
272
+ "vscode.open" ,
273
+ vscode . Uri . parse ( "https://github.com/settings/tokens" )
274
+ ) ;
275
+ }
276
+ await common . GetTokenAndSave ( customSettings ) ;
277
+ }
278
+
279
+ const repoName = (
280
+ ( await vscode . window . showInputBox ( {
281
+ placeHolder :
282
+ "Enter repository name, for ex. vscode-settings" ,
283
+ password : false ,
284
+ prompt :
285
+ "Enter name for repository which will be created on your account before changes will be pushed." ,
286
+ ignoreFocusOut : true
287
+ } ) ) || ""
288
+ ) . trim ( ) ;
289
+
290
+ const uriFormat = (
291
+ ( await vscode . window . showQuickPick ( [ "ssh" , "https" ] , {
292
+ ignoreFocusOut : true
293
+ } ) ) || ""
294
+ ) . trim ( ) ;
295
+
296
+ if ( uriFormat !== "" ) {
297
+ const res = await github . MakeRepository ( {
298
+ name : repoName
299
+ } ) ;
300
+
301
+ syncSetting . repoUrl =
302
+ uriFormat === "https"
303
+ ? res . data . html_url
304
+ : res . data . ssh_url ;
305
+ await common . SaveSettings ( syncSetting ) ;
306
+
307
+ await localgit . Init ( syncSetting . repoUrl ) ;
308
+ await localgit . Push ( ) ;
309
+ }
310
+ } else {
311
+ throw err ;
312
+ }
313
+ }
266
314
}
267
315
completed = true ;
268
316
} else {
You can’t perform that action at this time.
0 commit comments