@@ -246,14 +246,20 @@ export class CodingServer {
246246 throw new Error ( `team not exist` ) ;
247247 }
248248
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+ } ;
250256 }
251257
252258 public async getMRList ( repo ?: string , status ?: string ) : Promise < CodingResponse > {
253259 try {
254- const url = await this . getApiPrefix ( ) ;
260+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
255261 const result : CodingResponse = await got
256- . get ( `${ url } /git /merges/query` , {
262+ . get ( `${ repoApiPrefix } /merges/query` , {
257263 searchParams : {
258264 status,
259265 sort : `action_at` ,
@@ -272,20 +278,13 @@ export class CodingServer {
272278
273279 public async getRepoList ( ) {
274280 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 ( ) ;
280282 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 ,
287286 } ,
288- )
287+ } )
289288 . json ( ) ;
290289 if ( code ) {
291290 return Promise . reject ( { code, msg } ) ;
@@ -302,9 +301,9 @@ export class CodingServer {
302301
303302 public async getMRDiff ( iid : number ) {
304303 try {
305- const url = await this . getApiPrefix ( ) ;
304+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
306305 const diff : IMRDiffResponse = await got
307- . get ( `${ url } /git /merge/${ iid } /diff` , {
306+ . get ( `${ repoApiPrefix } /merge/${ iid } /diff` , {
308307 searchParams : {
309308 access_token : this . _session ?. accessToken ,
310309 } ,
@@ -321,9 +320,9 @@ export class CodingServer {
321320
322321 public async getMRDetail ( iid : string ) {
323322 try {
324- const url = await this . getApiPrefix ( ) ;
323+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
325324 const resp : IMRDetailResponse = await got
326- . get ( `${ url } /git /merge/${ iid } /detail` , {
325+ . get ( `${ repoApiPrefix } /merge/${ iid } /detail` , {
327326 searchParams : {
328327 access_token : this . _session ?. accessToken ,
329328 } ,
@@ -342,9 +341,9 @@ export class CodingServer {
342341
343342 public async getMRActivities ( iid : string ) {
344343 try {
345- const url = await this . getApiPrefix ( ) ;
344+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
346345 const result : IMRActivitiesResponse = await got
347- . get ( `${ url } /git /merge/${ iid } /activities` , {
346+ . get ( `${ repoApiPrefix } /merge/${ iid } /activities` , {
348347 searchParams : {
349348 access_token : this . _session ?. accessToken ,
350349 } ,
@@ -362,9 +361,9 @@ export class CodingServer {
362361
363362 public async getMRReviewers ( iid : string ) {
364363 try {
365- const url = await this . getApiPrefix ( ) ;
364+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
366365 const result : IMRReviewersResponse = await got
367- . get ( `${ url } /git /merge/${ iid } /reviewers` , {
366+ . get ( `${ repoApiPrefix } /merge/${ iid } /reviewers` , {
368367 searchParams : {
369368 access_token : this . _session ?. accessToken ,
370369 } ,
@@ -382,9 +381,9 @@ export class CodingServer {
382381
383382 public async getMRComments ( iid : string ) {
384383 try {
385- const url = await this . getApiPrefix ( ) ;
384+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
386385 const result : CodingResponse = await got
387- . get ( `${ url } /git /merge/${ iid } /comments` , {
386+ . get ( `${ repoApiPrefix } /merge/${ iid } /comments` , {
388387 searchParams : {
389388 access_token : this . _session ?. accessToken ,
390389 } ,
@@ -402,9 +401,9 @@ export class CodingServer {
402401
403402 public async closeMR ( iid : string ) {
404403 try {
405- const url = await this . getApiPrefix ( ) ;
404+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
406405 const result : CodingResponse = await got
407- . post ( `${ url } /git /merge/${ iid } /refuse` , {
406+ . post ( `${ repoApiPrefix } /merge/${ iid } /refuse` , {
408407 searchParams : {
409408 access_token : this . _session ?. accessToken ,
410409 } ,
@@ -422,9 +421,9 @@ export class CodingServer {
422421
423422 public async approveMR ( iid : string ) {
424423 try {
425- const url = await this . getApiPrefix ( ) ;
424+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
426425 const result : CodingResponse = await got
427- . post ( `${ url } /git /merge/${ iid } /good` , {
426+ . post ( `${ repoApiPrefix } /merge/${ iid } /good` , {
428427 searchParams : {
429428 access_token : this . _session ?. accessToken ,
430429 } ,
@@ -442,9 +441,9 @@ export class CodingServer {
442441
443442 public async disapproveMR ( iid : string ) {
444443 try {
445- const url = await this . getApiPrefix ( ) ;
444+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
446445 const result : CodingResponse = await got
447- . delete ( `${ url } /git /merge/${ iid } /good` , {
446+ . delete ( `${ repoApiPrefix } /merge/${ iid } /good` , {
448447 searchParams : {
449448 access_token : this . _session ?. accessToken ,
450449 } ,
@@ -462,9 +461,9 @@ export class CodingServer {
462461
463462 public async mergeMR ( iid : string ) {
464463 try {
465- const url = await this . getApiPrefix ( ) ;
464+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
466465 const result : CodingResponse = await got
467- . post ( `${ url } /git /merge/${ iid } /merge` , {
466+ . post ( `${ repoApiPrefix } /merge/${ iid } /merge` , {
468467 searchParams : {
469468 access_token : this . _session ?. accessToken ,
470469 } ,
@@ -485,9 +484,9 @@ export class CodingServer {
485484
486485 public async updateMRTitle ( iid : string , title : string ) {
487486 try {
488- const url = await this . getApiPrefix ( ) ;
487+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
489488 const result : CodingResponse = await got
490- . put ( `${ url } /git /merge/${ iid } /update-title` , {
489+ . put ( `${ repoApiPrefix } /merge/${ iid } /update-title` , {
491490 searchParams : {
492491 access_token : this . _session ?. accessToken ,
493492 title,
@@ -509,9 +508,9 @@ export class CodingServer {
509508
510509 public async commentMR ( mrId : number , comment : string ) {
511510 try {
512- const url = await this . getApiPrefix ( ) ;
511+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
513512 const result : CodingResponse = await got
514- . post ( `${ url } /git /line_notes` , {
513+ . post ( `${ repoApiPrefix } /line_notes` , {
515514 searchParams : {
516515 access_token : this . _session ?. accessToken ,
517516 line : 0 ,
@@ -539,12 +538,8 @@ export class CodingServer {
539538
540539 public async getRemoteFileContent ( path : string ) {
541540 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 } ` ;
548543 const { body } = await got . get ( url , {
549544 searchParams : {
550545 access_token : this . _session ?. accessToken ,
@@ -559,8 +554,8 @@ export class CodingServer {
559554
560555 public async createMR ( data : ICreateMRBody ) {
561556 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` , {
564559 resolveBodyOnly : true ,
565560 responseType : `json` ,
566561 searchParams : {
@@ -579,9 +574,9 @@ export class CodingServer {
579574
580575 public async getBranchList ( ) {
581576 try {
582- const url = await this . getApiPrefix ( ) ;
577+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
583578 const resp : IBranchListResp = await got
584- . get ( `${ url } /git /list_branches` , {
579+ . get ( `${ repoApiPrefix } /list_branches` , {
585580 searchParams : {
586581 access_token : this . _session ?. accessToken ,
587582 } ,
0 commit comments