@@ -89,9 +89,9 @@ export class CodingServer {
89
89
refreshToken : TokenType . RefreshToken ,
90
90
) : Promise < ISessionData > {
91
91
try {
92
- const repoInfo = this . _context . workspaceState . get ( `repoInfo` ) as IRepoInfo ;
93
- vscode . commands . executeCommand ( 'setContext' , 'hasTeam ' , ! ! repoInfo ?. team ) ;
94
- const result = await this . getUserInfo ( repoInfo . team || `` , accessToken ) ;
92
+ const repoInfo = this . _context . workspaceState . get ( `repoInfo` , { } ) as IRepoInfo ;
93
+ await vscode . commands . executeCommand ( 'setContext' , 'hasRepo ' , ! ! repoInfo ?. repo ) ;
94
+ const result = await this . getUserInfo ( repoInfo ? .team || `` , accessToken ) ;
95
95
const { data : userInfo } = result ;
96
96
const ret : ISessionData = {
97
97
id : nanoid ( ) ,
@@ -219,12 +219,12 @@ export class CodingServer {
219
219
if ( result . code ) {
220
220
console . error ( result . msg ) ;
221
221
this . _loggedIn = false ;
222
- vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , this . _loggedIn ) ;
222
+ await vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , this . _loggedIn ) ;
223
223
return Promise . reject ( result . msg ) ;
224
224
}
225
225
226
226
this . _loggedIn = true ;
227
- vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , this . _loggedIn ) ;
227
+ await vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , this . _loggedIn ) ;
228
228
return result ;
229
229
} catch ( err ) {
230
230
throw Error ( err ) ;
@@ -237,20 +237,21 @@ export class CodingServer {
237
237
return result ?. [ 0 ] ;
238
238
}
239
239
240
- public getApiPrefix ( ) {
240
+ public async getApiPrefix ( ) {
241
241
const repoInfo = this . _context . workspaceState . get ( `repoInfo` ) as IRepoInfo ;
242
- if ( ! repoInfo ?. team ) {
243
- vscode . commands . executeCommand ( 'setContext' , 'hasTeam' , false ) ;
242
+ const hasRepo = ! ! repoInfo ?. repo ;
243
+ await vscode . commands . executeCommand ( 'setContext' , 'hasRepo' , hasRepo ) ;
244
+
245
+ if ( ! hasRepo ) {
244
246
throw new Error ( `team not exist` ) ;
245
247
}
246
248
247
- vscode . commands . executeCommand ( 'setContext' , 'hasTeam' , true ) ;
248
249
return `https://${ repoInfo . team } .coding.net/api/user/${ this . _session ?. user ?. team } /project/${ repoInfo . project } /depot/${ repoInfo . repo } ` ;
249
250
}
250
251
251
252
public async getMRList ( repo ?: string , status ?: string ) : Promise < CodingResponse > {
252
253
try {
253
- const url = this . getApiPrefix ( ) ;
254
+ const url = await this . getApiPrefix ( ) ;
254
255
const result : CodingResponse = await got
255
256
. get ( `${ url } /git/merges/query` , {
256
257
searchParams : {
@@ -301,7 +302,7 @@ export class CodingServer {
301
302
302
303
public async getMRDiff ( iid : number ) {
303
304
try {
304
- const url = this . getApiPrefix ( ) ;
305
+ const url = await this . getApiPrefix ( ) ;
305
306
const diff : IMRDiffResponse = await got
306
307
. get ( `${ url } /git/merge/${ iid } /diff` , {
307
308
searchParams : {
@@ -320,7 +321,7 @@ export class CodingServer {
320
321
321
322
public async getMRDetail ( iid : string ) {
322
323
try {
323
- const url = this . getApiPrefix ( ) ;
324
+ const url = await this . getApiPrefix ( ) ;
324
325
const resp : IMRDetailResponse = await got
325
326
. get ( `${ url } /git/merge/${ iid } /detail` , {
326
327
searchParams : {
@@ -341,7 +342,7 @@ export class CodingServer {
341
342
342
343
public async getMRActivities ( iid : string ) {
343
344
try {
344
- const url = this . getApiPrefix ( ) ;
345
+ const url = await this . getApiPrefix ( ) ;
345
346
const result : IMRActivitiesResponse = await got
346
347
. get ( `${ url } /git/merge/${ iid } /activities` , {
347
348
searchParams : {
@@ -361,7 +362,7 @@ export class CodingServer {
361
362
362
363
public async getMRReviewers ( iid : string ) {
363
364
try {
364
- const url = this . getApiPrefix ( ) ;
365
+ const url = await this . getApiPrefix ( ) ;
365
366
const result : IMRReviewersResponse = await got
366
367
. get ( `${ url } /git/merge/${ iid } /reviewers` , {
367
368
searchParams : {
@@ -381,7 +382,7 @@ export class CodingServer {
381
382
382
383
public async getMRComments ( iid : string ) {
383
384
try {
384
- const url = this . getApiPrefix ( ) ;
385
+ const url = await this . getApiPrefix ( ) ;
385
386
const result : CodingResponse = await got
386
387
. get ( `${ url } /git/merge/${ iid } /comments` , {
387
388
searchParams : {
@@ -401,7 +402,7 @@ export class CodingServer {
401
402
402
403
public async closeMR ( iid : string ) {
403
404
try {
404
- const url = this . getApiPrefix ( ) ;
405
+ const url = await this . getApiPrefix ( ) ;
405
406
const result : CodingResponse = await got
406
407
. post ( `${ url } /git/merge/${ iid } /refuse` , {
407
408
searchParams : {
@@ -421,7 +422,7 @@ export class CodingServer {
421
422
422
423
public async approveMR ( iid : string ) {
423
424
try {
424
- const url = this . getApiPrefix ( ) ;
425
+ const url = await this . getApiPrefix ( ) ;
425
426
const result : CodingResponse = await got
426
427
. post ( `${ url } /git/merge/${ iid } /good` , {
427
428
searchParams : {
@@ -441,7 +442,7 @@ export class CodingServer {
441
442
442
443
public async disapproveMR ( iid : string ) {
443
444
try {
444
- const url = this . getApiPrefix ( ) ;
445
+ const url = await this . getApiPrefix ( ) ;
445
446
const result : CodingResponse = await got
446
447
. delete ( `${ url } /git/merge/${ iid } /good` , {
447
448
searchParams : {
@@ -461,7 +462,7 @@ export class CodingServer {
461
462
462
463
public async mergeMR ( iid : string ) {
463
464
try {
464
- const url = this . getApiPrefix ( ) ;
465
+ const url = await this . getApiPrefix ( ) ;
465
466
const result : CodingResponse = await got
466
467
. post ( `${ url } /git/merge/${ iid } /merge` , {
467
468
searchParams : {
@@ -484,7 +485,7 @@ export class CodingServer {
484
485
485
486
public async updateMRTitle ( iid : string , title : string ) {
486
487
try {
487
- const url = this . getApiPrefix ( ) ;
488
+ const url = await this . getApiPrefix ( ) ;
488
489
const result : CodingResponse = await got
489
490
. put ( `${ url } /git/merge/${ iid } /update-title` , {
490
491
searchParams : {
@@ -508,7 +509,7 @@ export class CodingServer {
508
509
509
510
public async commentMR ( mrId : number , comment : string ) {
510
511
try {
511
- const url = this . getApiPrefix ( ) ;
512
+ const url = await this . getApiPrefix ( ) ;
512
513
const result : CodingResponse = await got
513
514
. post ( `${ url } /git/line_notes` , {
514
515
searchParams : {
@@ -558,7 +559,7 @@ export class CodingServer {
558
559
559
560
public async createMR ( data : ICreateMRBody ) {
560
561
try {
561
- const url = this . getApiPrefix ( ) ;
562
+ const url = await this . getApiPrefix ( ) ;
562
563
const resp : ICreateMRResp = await got . post ( `${ url } /git/merge` , {
563
564
resolveBodyOnly : true ,
564
565
responseType : `json` ,
@@ -578,7 +579,7 @@ export class CodingServer {
578
579
579
580
public async getBranchList ( ) {
580
581
try {
581
- const url = this . getApiPrefix ( ) ;
582
+ const url = await this . getApiPrefix ( ) ;
582
583
const resp : IBranchListResp = await got
583
584
. get ( `${ url } /git/list_branches` , {
584
585
searchParams : {
@@ -610,7 +611,7 @@ export class CodingServer {
610
611
keychain . deleteToken ( TokenType . RefreshToken ) ,
611
612
] ) ;
612
613
this . _session = null ;
613
- vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , false ) ;
614
+ await vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , false ) ;
614
615
return true ;
615
616
} catch ( e ) {
616
617
throw Error ( e ) ;
0 commit comments