@@ -5,7 +5,7 @@ import got from 'got';
5
5
import {
6
6
AuthFailResult ,
7
7
AuthSuccessResult ,
8
- CodingResponse ,
8
+ ICodingResponse ,
9
9
IRepoListResponse ,
10
10
IMRDiffResponse ,
11
11
IMRDetailResponse ,
@@ -21,6 +21,8 @@ import {
21
21
IMRCommentResp ,
22
22
IFileDiffParam ,
23
23
IFileDiffResp ,
24
+ ILineNoteResp ,
25
+ ILineNoteForm ,
24
26
} from 'src/typings/respResult' ;
25
27
26
28
import { PromiseAdapter , promiseFromEvent , parseQuery , parseCloneUrl } from 'src/common/utils' ;
@@ -223,7 +225,7 @@ export class CodingServer {
223
225
224
226
public async getUserInfo ( team : string , token : string = this . _session ?. accessToken || `` ) {
225
227
try {
226
- const result : CodingResponse = await got
228
+ const result : ICodingResponse = await got
227
229
. get ( `https://${ team || `codingcorp` } .coding.net/api/current_user` , {
228
230
searchParams : {
229
231
access_token : token ,
@@ -270,10 +272,10 @@ export class CodingServer {
270
272
} ;
271
273
}
272
274
273
- public async getMRList ( repo ?: string , status ?: string ) : Promise < CodingResponse > {
275
+ public async getMRList ( repo ?: string , status ?: string ) : Promise < ICodingResponse > {
274
276
try {
275
277
const { repoApiPrefix } = await this . getApiPrefix ( ) ;
276
- const result : CodingResponse = await got
278
+ const result : ICodingResponse = await got
277
279
. get ( `${ repoApiPrefix } /merges/query` , {
278
280
searchParams : {
279
281
status,
@@ -417,7 +419,7 @@ export class CodingServer {
417
419
public async closeMR ( iid : string ) {
418
420
try {
419
421
const { repoApiPrefix } = await this . getApiPrefix ( ) ;
420
- const result : CodingResponse = await got
422
+ const result : ICodingResponse = await got
421
423
. post ( `${ repoApiPrefix } /merge/${ iid } /refuse` , {
422
424
searchParams : {
423
425
access_token : this . _session ?. accessToken ,
@@ -437,7 +439,7 @@ export class CodingServer {
437
439
public async approveMR ( iid : string ) {
438
440
try {
439
441
const { repoApiPrefix } = await this . getApiPrefix ( ) ;
440
- const result : CodingResponse = await got
442
+ const result : ICodingResponse = await got
441
443
. post ( `${ repoApiPrefix } /merge/${ iid } /good` , {
442
444
searchParams : {
443
445
access_token : this . _session ?. accessToken ,
@@ -457,7 +459,7 @@ export class CodingServer {
457
459
public async disapproveMR ( iid : string ) {
458
460
try {
459
461
const { repoApiPrefix } = await this . getApiPrefix ( ) ;
460
- const result : CodingResponse = await got
462
+ const result : ICodingResponse = await got
461
463
. delete ( `${ repoApiPrefix } /merge/${ iid } /good` , {
462
464
searchParams : {
463
465
access_token : this . _session ?. accessToken ,
@@ -477,7 +479,7 @@ export class CodingServer {
477
479
public async mergeMR ( iid : string ) {
478
480
try {
479
481
const { repoApiPrefix } = await this . getApiPrefix ( ) ;
480
- const result : CodingResponse = await got
482
+ const result : ICodingResponse = await got
481
483
. post ( `${ repoApiPrefix } /merge/${ iid } /merge` , {
482
484
searchParams : {
483
485
access_token : this . _session ?. accessToken ,
@@ -500,7 +502,7 @@ export class CodingServer {
500
502
public async updateMRTitle ( iid : string , title : string ) {
501
503
try {
502
504
const { repoApiPrefix } = await this . getApiPrefix ( ) ;
503
- const result : CodingResponse = await got
505
+ const result : ICodingResponse = await got
504
506
. put ( `${ repoApiPrefix } /merge/${ iid } /update-title` , {
505
507
searchParams : {
506
508
access_token : this . _session ?. accessToken ,
@@ -630,7 +632,7 @@ export class CodingServer {
630
632
631
633
public async addMRReviewers ( iid : string , ids : number [ ] ) : Promise < number [ ] > {
632
634
const { repoApiPrefix } = await this . getApiPrefix ( ) ;
633
- const tasks : Promise < CodingResponse > [ ] = ids . map ( ( id ) => {
635
+ const tasks : Promise < ICodingResponse > [ ] = ids . map ( ( id ) => {
634
636
return got
635
637
. post ( `${ repoApiPrefix } /merge/${ iid } /reviewers` , {
636
638
searchParams : {
@@ -640,7 +642,7 @@ export class CodingServer {
640
642
} )
641
643
. json ( ) ;
642
644
} ) ;
643
- const result : PromiseSettledResult < CodingResponse > [ ] = await Promise . allSettled ( tasks ) ;
645
+ const result : PromiseSettledResult < ICodingResponse > [ ] = await Promise . allSettled ( tasks ) ;
644
646
const fulfilled = ids . reduce ( ( res , cur , idx ) => {
645
647
if ( result [ idx ] . status === `fulfilled` ) {
646
648
res = res . concat ( cur ) ;
@@ -653,7 +655,7 @@ export class CodingServer {
653
655
654
656
public async removeMRReviewers ( iid : string , ids : number [ ] ) : Promise < number [ ] > {
655
657
const { repoApiPrefix } = await this . getApiPrefix ( ) ;
656
- const tasks : Promise < CodingResponse > [ ] = ids . map ( ( id ) => {
658
+ const tasks : Promise < ICodingResponse > [ ] = ids . map ( ( id ) => {
657
659
return got
658
660
. delete ( `${ repoApiPrefix } /merge/${ iid } /reviewers` , {
659
661
searchParams : {
@@ -663,7 +665,7 @@ export class CodingServer {
663
665
} )
664
666
. json ( ) ;
665
667
} ) ;
666
- const result : PromiseSettledResult < CodingResponse > [ ] = await Promise . allSettled ( tasks ) ;
668
+ const result : PromiseSettledResult < ICodingResponse > [ ] = await Promise . allSettled ( tasks ) ;
667
669
const fulfilled = ids . reduce ( ( res , cur , idx ) => {
668
670
if ( result [ idx ] . status === `fulfilled` ) {
669
671
res = res . concat ( cur ) ;
@@ -744,6 +746,27 @@ export class CodingServer {
744
746
}
745
747
}
746
748
749
+ public async postLineNote ( data : ILineNoteForm ) {
750
+ try {
751
+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
752
+ const resp : ILineNoteResp = await got . post ( `${ repoApiPrefix } /line_notes` , {
753
+ resolveBodyOnly : true ,
754
+ responseType : `json` ,
755
+ searchParams : {
756
+ access_token : this . _session ?. accessToken ,
757
+ } ,
758
+ form : data ,
759
+ } ) ;
760
+
761
+ if ( resp . code ) {
762
+ return Promise . reject ( resp ) ;
763
+ }
764
+ return resp ;
765
+ } catch ( e ) {
766
+ return Promise . reject ( e ) ;
767
+ }
768
+ }
769
+
747
770
get loggedIn ( ) {
748
771
return this . _loggedIn ;
749
772
}
0 commit comments