@@ -246,14 +246,20 @@ export class CodingServer {
246
246
throw new Error ( `team not exist` ) ;
247
247
}
248
248
249
- return `https://${ repoInfo . team } .coding.net/api/user/${ this . _session ?. user ?. team } /project/${ repoInfo . project } /depot/${ repoInfo . repo } ` ;
249
+ const projectApiPrefix = `https://${ repoInfo . team } .coding.net/api/user/${ this . _session ?. user ?. team } /project/${ repoInfo . project } ` ;
250
+ return {
251
+ projectApiPrefix,
252
+ repoApiPrefix : `${ projectApiPrefix } /depot/${ repoInfo . repo } /git` ,
253
+ userApiPrefix : `https://${ repoInfo . team } .coding.net/api/user/${ this . _session ?. user ?. global_key } ` ,
254
+ rawFilePrefix : `https://${ repoInfo . team } .coding.net/p/${ repoInfo . project } /d/${ repoInfo . repo } /git/raw` ,
255
+ } ;
250
256
}
251
257
252
258
public async getMRList ( repo ?: string , status ?: string ) : Promise < CodingResponse > {
253
259
try {
254
- const url = await this . getApiPrefix ( ) ;
260
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
255
261
const result : CodingResponse = await got
256
- . get ( `${ url } /git /merges/query` , {
262
+ . get ( `${ repoApiPrefix } /merges/query` , {
257
263
searchParams : {
258
264
status,
259
265
sort : `action_at` ,
@@ -272,20 +278,13 @@ export class CodingServer {
272
278
273
279
public async getRepoList ( ) {
274
280
try {
275
- const repoInfo = this . _context . workspaceState . get ( `repoInfo` ) as IRepoInfo ;
276
- if ( ! repoInfo ?. team ) {
277
- throw new Error ( `team not exist` ) ;
278
- }
279
-
281
+ const { userApiPrefix } = await this . getApiPrefix ( ) ;
280
282
const { code, data, msg } : IRepoListResponse = await got
281
- . get (
282
- `https://${ repoInfo . team } .coding.net/api/user/${ this . _session ?. user ?. global_key } /depots` ,
283
- {
284
- searchParams : {
285
- access_token : this . _session ?. accessToken ,
286
- } ,
283
+ . get ( `${ userApiPrefix } /depots` , {
284
+ searchParams : {
285
+ access_token : this . _session ?. accessToken ,
287
286
} ,
288
- )
287
+ } )
289
288
. json ( ) ;
290
289
if ( code ) {
291
290
return Promise . reject ( { code, msg } ) ;
@@ -302,9 +301,9 @@ export class CodingServer {
302
301
303
302
public async getMRDiff ( iid : number ) {
304
303
try {
305
- const url = await this . getApiPrefix ( ) ;
304
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
306
305
const diff : IMRDiffResponse = await got
307
- . get ( `${ url } /git /merge/${ iid } /diff` , {
306
+ . get ( `${ repoApiPrefix } /merge/${ iid } /diff` , {
308
307
searchParams : {
309
308
access_token : this . _session ?. accessToken ,
310
309
} ,
@@ -321,9 +320,9 @@ export class CodingServer {
321
320
322
321
public async getMRDetail ( iid : string ) {
323
322
try {
324
- const url = await this . getApiPrefix ( ) ;
323
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
325
324
const resp : IMRDetailResponse = await got
326
- . get ( `${ url } /git /merge/${ iid } /detail` , {
325
+ . get ( `${ repoApiPrefix } /merge/${ iid } /detail` , {
327
326
searchParams : {
328
327
access_token : this . _session ?. accessToken ,
329
328
} ,
@@ -342,9 +341,9 @@ export class CodingServer {
342
341
343
342
public async getMRActivities ( iid : string ) {
344
343
try {
345
- const url = await this . getApiPrefix ( ) ;
344
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
346
345
const result : IMRActivitiesResponse = await got
347
- . get ( `${ url } /git /merge/${ iid } /activities` , {
346
+ . get ( `${ repoApiPrefix } /merge/${ iid } /activities` , {
348
347
searchParams : {
349
348
access_token : this . _session ?. accessToken ,
350
349
} ,
@@ -362,9 +361,9 @@ export class CodingServer {
362
361
363
362
public async getMRReviewers ( iid : string ) {
364
363
try {
365
- const url = await this . getApiPrefix ( ) ;
364
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
366
365
const result : IMRReviewersResponse = await got
367
- . get ( `${ url } /git /merge/${ iid } /reviewers` , {
366
+ . get ( `${ repoApiPrefix } /merge/${ iid } /reviewers` , {
368
367
searchParams : {
369
368
access_token : this . _session ?. accessToken ,
370
369
} ,
@@ -382,9 +381,9 @@ export class CodingServer {
382
381
383
382
public async getMRComments ( iid : string ) {
384
383
try {
385
- const url = await this . getApiPrefix ( ) ;
384
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
386
385
const result : CodingResponse = await got
387
- . get ( `${ url } /git /merge/${ iid } /comments` , {
386
+ . get ( `${ repoApiPrefix } /merge/${ iid } /comments` , {
388
387
searchParams : {
389
388
access_token : this . _session ?. accessToken ,
390
389
} ,
@@ -402,9 +401,9 @@ export class CodingServer {
402
401
403
402
public async closeMR ( iid : string ) {
404
403
try {
405
- const url = await this . getApiPrefix ( ) ;
404
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
406
405
const result : CodingResponse = await got
407
- . post ( `${ url } /git /merge/${ iid } /refuse` , {
406
+ . post ( `${ repoApiPrefix } /merge/${ iid } /refuse` , {
408
407
searchParams : {
409
408
access_token : this . _session ?. accessToken ,
410
409
} ,
@@ -422,9 +421,9 @@ export class CodingServer {
422
421
423
422
public async approveMR ( iid : string ) {
424
423
try {
425
- const url = await this . getApiPrefix ( ) ;
424
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
426
425
const result : CodingResponse = await got
427
- . post ( `${ url } /git /merge/${ iid } /good` , {
426
+ . post ( `${ repoApiPrefix } /merge/${ iid } /good` , {
428
427
searchParams : {
429
428
access_token : this . _session ?. accessToken ,
430
429
} ,
@@ -442,9 +441,9 @@ export class CodingServer {
442
441
443
442
public async disapproveMR ( iid : string ) {
444
443
try {
445
- const url = await this . getApiPrefix ( ) ;
444
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
446
445
const result : CodingResponse = await got
447
- . delete ( `${ url } /git /merge/${ iid } /good` , {
446
+ . delete ( `${ repoApiPrefix } /merge/${ iid } /good` , {
448
447
searchParams : {
449
448
access_token : this . _session ?. accessToken ,
450
449
} ,
@@ -462,9 +461,9 @@ export class CodingServer {
462
461
463
462
public async mergeMR ( iid : string ) {
464
463
try {
465
- const url = await this . getApiPrefix ( ) ;
464
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
466
465
const result : CodingResponse = await got
467
- . post ( `${ url } /git /merge/${ iid } /merge` , {
466
+ . post ( `${ repoApiPrefix } /merge/${ iid } /merge` , {
468
467
searchParams : {
469
468
access_token : this . _session ?. accessToken ,
470
469
} ,
@@ -485,9 +484,9 @@ export class CodingServer {
485
484
486
485
public async updateMRTitle ( iid : string , title : string ) {
487
486
try {
488
- const url = await this . getApiPrefix ( ) ;
487
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
489
488
const result : CodingResponse = await got
490
- . put ( `${ url } /git /merge/${ iid } /update-title` , {
489
+ . put ( `${ repoApiPrefix } /merge/${ iid } /update-title` , {
491
490
searchParams : {
492
491
access_token : this . _session ?. accessToken ,
493
492
title,
@@ -509,9 +508,9 @@ export class CodingServer {
509
508
510
509
public async commentMR ( mrId : number , comment : string ) {
511
510
try {
512
- const url = await this . getApiPrefix ( ) ;
511
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
513
512
const result : CodingResponse = await got
514
- . post ( `${ url } /git /line_notes` , {
513
+ . post ( `${ repoApiPrefix } /line_notes` , {
515
514
searchParams : {
516
515
access_token : this . _session ?. accessToken ,
517
516
line : 0 ,
@@ -539,12 +538,8 @@ export class CodingServer {
539
538
540
539
public async getRemoteFileContent ( path : string ) {
541
540
try {
542
- const repoInfo = this . _context . workspaceState . get ( `repoInfo` ) as IRepoInfo ;
543
- if ( ! repoInfo ?. team ) {
544
- throw new Error ( `team not exist` ) ;
545
- }
546
-
547
- const url = `https://${ repoInfo . team } .coding.net/p/${ repoInfo . project } /d/${ repoInfo . repo } /git/raw/${ path } ` ;
541
+ const { rawFilePrefix } = await this . getApiPrefix ( ) ;
542
+ const url = `${ rawFilePrefix } /${ path } ` ;
548
543
const { body } = await got . get ( url , {
549
544
searchParams : {
550
545
access_token : this . _session ?. accessToken ,
@@ -559,8 +554,8 @@ export class CodingServer {
559
554
560
555
public async createMR ( data : ICreateMRBody ) {
561
556
try {
562
- const url = await this . getApiPrefix ( ) ;
563
- const resp : ICreateMRResp = await got . post ( `${ url } /git /merge` , {
557
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
558
+ const resp : ICreateMRResp = await got . post ( `${ repoApiPrefix } /merge` , {
564
559
resolveBodyOnly : true ,
565
560
responseType : `json` ,
566
561
searchParams : {
@@ -579,9 +574,9 @@ export class CodingServer {
579
574
580
575
public async getBranchList ( ) {
581
576
try {
582
- const url = await this . getApiPrefix ( ) ;
577
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
583
578
const resp : IBranchListResp = await got
584
- . get ( `${ url } /git /list_branches` , {
579
+ . get ( `${ repoApiPrefix } /list_branches` , {
585
580
searchParams : {
586
581
access_token : this . _session ?. accessToken ,
587
582
} ,
0 commit comments