9
9
IRepoListResponse ,
10
10
IMRDiffResponse ,
11
11
IMRDetailResponse ,
12
+ IMRActivitiesResponse ,
13
+ IMRReviewersResponse ,
12
14
ICreateMRBody ,
13
15
ICreateMRResp ,
14
16
IBranchListResp ,
@@ -41,7 +43,7 @@ export class CodingServer {
41
43
private _pendingStates = new Map < string , string [ ] > ( ) ;
42
44
private _codeExchangePromises = new Map < string , Promise < AuthSuccessResult > > ( ) ;
43
45
44
- private _loggedIn : boolean = false ;
46
+ private _loggedIn = false ;
45
47
private _context : vscode . ExtensionContext ;
46
48
private _session : ISessionData | null = null ;
47
49
@@ -238,6 +240,14 @@ export class CodingServer {
238
240
return result ?. [ 0 ] ;
239
241
}
240
242
243
+ public getApiPrefix ( ) {
244
+ const repoInfo = this . _context . workspaceState . get ( `repoInfo` ) as IRepoInfo ;
245
+ if ( ! repoInfo ?. team ) {
246
+ throw new Error ( `team not exist` ) ;
247
+ }
248
+ return `https://${ repoInfo . team } .coding.net/api/user/${ this . _session ?. user ?. team } /project/${ repoInfo . project } /depot/${ repoInfo . repo } ` ;
249
+ }
250
+
241
251
public async getMRList ( repo ?: string , status ?: string ) : Promise < CodingResponse > {
242
252
try {
243
253
const repoInfo = this . _context . workspaceState . get ( `repoInfo` ) as IRepoInfo ;
@@ -300,20 +310,13 @@ export class CodingServer {
300
310
301
311
public async getMRDiff ( iid : number ) {
302
312
try {
303
- const repoInfo = this . _context . workspaceState . get ( `repoInfo` ) as IRepoInfo ;
304
- if ( ! repoInfo ?. team ) {
305
- throw new Error ( `team not exist` ) ;
306
- }
307
-
313
+ const url = this . getApiPrefix ( ) ;
308
314
const diff : IMRDiffResponse = await got
309
- . get (
310
- `https://${ repoInfo . team } .coding.net/api/user/${ this . _session ?. user ?. team } /project/${ repoInfo . project } /depot/${ repoInfo . repo } /git/merge/${ iid } /diff` ,
311
- {
312
- searchParams : {
313
- access_token : this . _session ?. accessToken ,
314
- } ,
315
+ . get ( `${ url } /git/merge/${ iid } /diff` , {
316
+ searchParams : {
317
+ access_token : this . _session ?. accessToken ,
315
318
} ,
316
- )
319
+ } )
317
320
. json ( ) ;
318
321
if ( diff . code ) {
319
322
return Promise . reject ( diff ) ;
@@ -326,20 +329,13 @@ export class CodingServer {
326
329
327
330
public async getMRDetail ( iid : string ) {
328
331
try {
329
- const repoInfo = this . _context . workspaceState . get ( `repoInfo` ) as IRepoInfo ;
330
- if ( ! repoInfo ?. team ) {
331
- throw new Error ( `team not exist` ) ;
332
- }
333
-
332
+ const url = this . getApiPrefix ( ) ;
334
333
const resp : IMRDetailResponse = await got
335
- . get (
336
- `https://${ repoInfo . team } .coding.net/api/user/${ this . _session ?. user ?. team } /project/${ repoInfo . project } /depot/${ repoInfo . repo } /git/merge/${ iid } /detail` ,
337
- {
338
- searchParams : {
339
- access_token : this . _session ?. accessToken ,
340
- } ,
334
+ . get ( `${ url } /git/merge/${ iid } /detail` , {
335
+ searchParams : {
336
+ access_token : this . _session ?. accessToken ,
341
337
} ,
342
- )
338
+ } )
343
339
. json ( ) ;
344
340
345
341
if ( resp . code ) {
@@ -352,6 +348,203 @@ export class CodingServer {
352
348
}
353
349
}
354
350
351
+ public async getMRActivities ( iid : string ) {
352
+ try {
353
+ const url = this . getApiPrefix ( ) ;
354
+ const result : IMRActivitiesResponse = await got
355
+ . get ( `${ url } /git/merge/${ iid } /activities` , {
356
+ searchParams : {
357
+ access_token : this . _session ?. accessToken ,
358
+ } ,
359
+ } )
360
+ . json ( ) ;
361
+
362
+ if ( result . code ) {
363
+ return Promise . reject ( result ) ;
364
+ }
365
+ return result ;
366
+ } catch ( err ) {
367
+ return Promise . reject ( err ) ;
368
+ }
369
+ }
370
+
371
+ public async getMRReviewers ( iid : string ) {
372
+ try {
373
+ const url = this . getApiPrefix ( ) ;
374
+ const result : IMRReviewersResponse = await got
375
+ . get ( `${ url } /git/merge/${ iid } /reviewers` , {
376
+ searchParams : {
377
+ access_token : this . _session ?. accessToken ,
378
+ } ,
379
+ } )
380
+ . json ( ) ;
381
+
382
+ if ( result . code ) {
383
+ return Promise . reject ( result ) ;
384
+ }
385
+ return result ;
386
+ } catch ( err ) {
387
+ return Promise . reject ( err ) ;
388
+ }
389
+ }
390
+
391
+ public async getMRComments ( iid : string ) {
392
+ try {
393
+ const url = this . getApiPrefix ( ) ;
394
+ const result : CodingResponse = await got
395
+ . get ( `${ url } /git/merge/${ iid } /comments` , {
396
+ searchParams : {
397
+ access_token : this . _session ?. accessToken ,
398
+ } ,
399
+ } )
400
+ . json ( ) ;
401
+
402
+ if ( result . code ) {
403
+ return Promise . reject ( result ) ;
404
+ }
405
+ return result ;
406
+ } catch ( err ) {
407
+ return Promise . reject ( err ) ;
408
+ }
409
+ }
410
+
411
+ public async closeMR ( iid : string ) {
412
+ try {
413
+ const url = this . getApiPrefix ( ) ;
414
+ const result : CodingResponse = await got
415
+ . post ( `${ url } /git/merge/${ iid } /refuse` , {
416
+ searchParams : {
417
+ access_token : this . _session ?. accessToken ,
418
+ } ,
419
+ } )
420
+ . json ( ) ;
421
+
422
+ if ( result . code ) {
423
+ return Promise . reject ( result ) ;
424
+ }
425
+ return result ;
426
+ } catch ( err ) {
427
+ return Promise . reject ( err ) ;
428
+ }
429
+ }
430
+
431
+ public async approveMR ( iid : string ) {
432
+ try {
433
+ const url = this . getApiPrefix ( ) ;
434
+ const result : CodingResponse = await got
435
+ . post ( `${ url } /git/merge/${ iid } /good` , {
436
+ searchParams : {
437
+ access_token : this . _session ?. accessToken ,
438
+ } ,
439
+ } )
440
+ . json ( ) ;
441
+
442
+ if ( result . code ) {
443
+ return Promise . reject ( result ) ;
444
+ }
445
+ return result ;
446
+ } catch ( err ) {
447
+ return Promise . reject ( err ) ;
448
+ }
449
+ }
450
+
451
+ public async disapproveMR ( iid : string ) {
452
+ try {
453
+ const url = this . getApiPrefix ( ) ;
454
+ const result : CodingResponse = await got
455
+ . delete ( `${ url } /git/merge/${ iid } /good` , {
456
+ searchParams : {
457
+ access_token : this . _session ?. accessToken ,
458
+ } ,
459
+ } )
460
+ . json ( ) ;
461
+
462
+ if ( result . code ) {
463
+ return Promise . reject ( result ) ;
464
+ }
465
+ return result ;
466
+ } catch ( err ) {
467
+ return Promise . reject ( err ) ;
468
+ }
469
+ }
470
+
471
+ public async mergeMR ( iid : string ) {
472
+ try {
473
+ const url = this . getApiPrefix ( ) ;
474
+ const result : CodingResponse = await got
475
+ . post ( `${ url } /git/merge/${ iid } /merge` , {
476
+ searchParams : {
477
+ access_token : this . _session ?. accessToken ,
478
+ } ,
479
+ headers : {
480
+ 'content-type' : 'application/x-www-form-urlencoded;charset=UTF-8' ,
481
+ } ,
482
+ } )
483
+ . json ( ) ;
484
+
485
+ if ( result . code ) {
486
+ return Promise . reject ( result ) ;
487
+ }
488
+ return result ;
489
+ } catch ( err ) {
490
+ return Promise . reject ( err ) ;
491
+ }
492
+ }
493
+
494
+ public async updateMRTitle ( iid : string , title : string ) {
495
+ try {
496
+ const url = this . getApiPrefix ( ) ;
497
+ const result : CodingResponse = await got
498
+ . put ( `${ url } /git/merge/${ iid } /update-title` , {
499
+ searchParams : {
500
+ access_token : this . _session ?. accessToken ,
501
+ title,
502
+ } ,
503
+ headers : {
504
+ 'content-type' : 'application/x-www-form-urlencoded;charset=UTF-8' ,
505
+ } ,
506
+ } )
507
+ . json ( ) ;
508
+
509
+ if ( result . code ) {
510
+ return Promise . reject ( result ) ;
511
+ }
512
+ return result ;
513
+ } catch ( err ) {
514
+ return Promise . reject ( err ) ;
515
+ }
516
+ }
517
+
518
+ public async commentMR ( mrId : number , comment : string ) {
519
+ try {
520
+ const url = this . getApiPrefix ( ) ;
521
+ const result : CodingResponse = await got
522
+ . post ( `${ url } /git/line_notes` , {
523
+ searchParams : {
524
+ access_token : this . _session ?. accessToken ,
525
+ line : 0 ,
526
+ change_type : 0 ,
527
+ position : 0 ,
528
+ content : comment ,
529
+ noteable_type : 'MergeRequestBean' ,
530
+ noteable_id : mrId ,
531
+ parent_id : 0 ,
532
+ } ,
533
+ headers : {
534
+ 'content-type' : 'application/x-www-form-urlencoded;charset=UTF-8' ,
535
+ } ,
536
+ } )
537
+ . json ( ) ;
538
+
539
+ if ( result . code ) {
540
+ return Promise . reject ( result ) ;
541
+ }
542
+ return result ;
543
+ } catch ( err ) {
544
+ return Promise . reject ( err ) ;
545
+ }
546
+ }
547
+
355
548
public async getRemoteFileContent ( path : string ) {
356
549
try {
357
550
const repoInfo = this . _context . workspaceState . get ( `repoInfo` ) as IRepoInfo ;
0 commit comments