@@ -89,9 +89,9 @@ export class CodingServer {
8989 refreshToken : TokenType . RefreshToken ,
9090 ) : Promise < ISessionData > {
9191 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 ) ;
9595 const { data : userInfo } = result ;
9696 const ret : ISessionData = {
9797 id : nanoid ( ) ,
@@ -219,12 +219,12 @@ export class CodingServer {
219219 if ( result . code ) {
220220 console . error ( result . msg ) ;
221221 this . _loggedIn = false ;
222- vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , this . _loggedIn ) ;
222+ await vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , this . _loggedIn ) ;
223223 return Promise . reject ( result . msg ) ;
224224 }
225225
226226 this . _loggedIn = true ;
227- vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , this . _loggedIn ) ;
227+ await vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , this . _loggedIn ) ;
228228 return result ;
229229 } catch ( err ) {
230230 throw Error ( err ) ;
@@ -237,20 +237,21 @@ export class CodingServer {
237237 return result ?. [ 0 ] ;
238238 }
239239
240- public getApiPrefix ( ) {
240+ public async getApiPrefix ( ) {
241241 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 ) {
244246 throw new Error ( `team not exist` ) ;
245247 }
246248
247- vscode . commands . executeCommand ( 'setContext' , 'hasTeam' , true ) ;
248249 return `https://${ repoInfo . team } .coding.net/api/user/${ this . _session ?. user ?. team } /project/${ repoInfo . project } /depot/${ repoInfo . repo } ` ;
249250 }
250251
251252 public async getMRList ( repo ?: string , status ?: string ) : Promise < CodingResponse > {
252253 try {
253- const url = this . getApiPrefix ( ) ;
254+ const url = await this . getApiPrefix ( ) ;
254255 const result : CodingResponse = await got
255256 . get ( `${ url } /git/merges/query` , {
256257 searchParams : {
@@ -301,7 +302,7 @@ export class CodingServer {
301302
302303 public async getMRDiff ( iid : number ) {
303304 try {
304- const url = this . getApiPrefix ( ) ;
305+ const url = await this . getApiPrefix ( ) ;
305306 const diff : IMRDiffResponse = await got
306307 . get ( `${ url } /git/merge/${ iid } /diff` , {
307308 searchParams : {
@@ -320,7 +321,7 @@ export class CodingServer {
320321
321322 public async getMRDetail ( iid : string ) {
322323 try {
323- const url = this . getApiPrefix ( ) ;
324+ const url = await this . getApiPrefix ( ) ;
324325 const resp : IMRDetailResponse = await got
325326 . get ( `${ url } /git/merge/${ iid } /detail` , {
326327 searchParams : {
@@ -341,7 +342,7 @@ export class CodingServer {
341342
342343 public async getMRActivities ( iid : string ) {
343344 try {
344- const url = this . getApiPrefix ( ) ;
345+ const url = await this . getApiPrefix ( ) ;
345346 const result : IMRActivitiesResponse = await got
346347 . get ( `${ url } /git/merge/${ iid } /activities` , {
347348 searchParams : {
@@ -361,7 +362,7 @@ export class CodingServer {
361362
362363 public async getMRReviewers ( iid : string ) {
363364 try {
364- const url = this . getApiPrefix ( ) ;
365+ const url = await this . getApiPrefix ( ) ;
365366 const result : IMRReviewersResponse = await got
366367 . get ( `${ url } /git/merge/${ iid } /reviewers` , {
367368 searchParams : {
@@ -381,7 +382,7 @@ export class CodingServer {
381382
382383 public async getMRComments ( iid : string ) {
383384 try {
384- const url = this . getApiPrefix ( ) ;
385+ const url = await this . getApiPrefix ( ) ;
385386 const result : CodingResponse = await got
386387 . get ( `${ url } /git/merge/${ iid } /comments` , {
387388 searchParams : {
@@ -401,7 +402,7 @@ export class CodingServer {
401402
402403 public async closeMR ( iid : string ) {
403404 try {
404- const url = this . getApiPrefix ( ) ;
405+ const url = await this . getApiPrefix ( ) ;
405406 const result : CodingResponse = await got
406407 . post ( `${ url } /git/merge/${ iid } /refuse` , {
407408 searchParams : {
@@ -421,7 +422,7 @@ export class CodingServer {
421422
422423 public async approveMR ( iid : string ) {
423424 try {
424- const url = this . getApiPrefix ( ) ;
425+ const url = await this . getApiPrefix ( ) ;
425426 const result : CodingResponse = await got
426427 . post ( `${ url } /git/merge/${ iid } /good` , {
427428 searchParams : {
@@ -441,7 +442,7 @@ export class CodingServer {
441442
442443 public async disapproveMR ( iid : string ) {
443444 try {
444- const url = this . getApiPrefix ( ) ;
445+ const url = await this . getApiPrefix ( ) ;
445446 const result : CodingResponse = await got
446447 . delete ( `${ url } /git/merge/${ iid } /good` , {
447448 searchParams : {
@@ -461,7 +462,7 @@ export class CodingServer {
461462
462463 public async mergeMR ( iid : string ) {
463464 try {
464- const url = this . getApiPrefix ( ) ;
465+ const url = await this . getApiPrefix ( ) ;
465466 const result : CodingResponse = await got
466467 . post ( `${ url } /git/merge/${ iid } /merge` , {
467468 searchParams : {
@@ -484,7 +485,7 @@ export class CodingServer {
484485
485486 public async updateMRTitle ( iid : string , title : string ) {
486487 try {
487- const url = this . getApiPrefix ( ) ;
488+ const url = await this . getApiPrefix ( ) ;
488489 const result : CodingResponse = await got
489490 . put ( `${ url } /git/merge/${ iid } /update-title` , {
490491 searchParams : {
@@ -508,7 +509,7 @@ export class CodingServer {
508509
509510 public async commentMR ( mrId : number , comment : string ) {
510511 try {
511- const url = this . getApiPrefix ( ) ;
512+ const url = await this . getApiPrefix ( ) ;
512513 const result : CodingResponse = await got
513514 . post ( `${ url } /git/line_notes` , {
514515 searchParams : {
@@ -558,7 +559,7 @@ export class CodingServer {
558559
559560 public async createMR ( data : ICreateMRBody ) {
560561 try {
561- const url = this . getApiPrefix ( ) ;
562+ const url = await this . getApiPrefix ( ) ;
562563 const resp : ICreateMRResp = await got . post ( `${ url } /git/merge` , {
563564 resolveBodyOnly : true ,
564565 responseType : `json` ,
@@ -578,7 +579,7 @@ export class CodingServer {
578579
579580 public async getBranchList ( ) {
580581 try {
581- const url = this . getApiPrefix ( ) ;
582+ const url = await this . getApiPrefix ( ) ;
582583 const resp : IBranchListResp = await got
583584 . get ( `${ url } /git/list_branches` , {
584585 searchParams : {
@@ -610,7 +611,7 @@ export class CodingServer {
610611 keychain . deleteToken ( TokenType . RefreshToken ) ,
611612 ] ) ;
612613 this . _session = null ;
613- vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , false ) ;
614+ await vscode . commands . executeCommand ( 'setContext' , 'loggedIn' , false ) ;
614615 return true ;
615616 } catch ( e ) {
616617 throw Error ( e ) ;
0 commit comments