@@ -5,7 +5,7 @@ import got from 'got';
55import {
66 AuthFailResult ,
77 AuthSuccessResult ,
8- CodingResponse ,
8+ ICodingResponse ,
99 IRepoListResponse ,
1010 IMRDiffResponse ,
1111 IMRDetailResponse ,
@@ -18,14 +18,20 @@ import {
1818 IMRContentResp ,
1919 ICreateCommentResp ,
2020 IMRStatusResp ,
21+ IMRCommentResp ,
22+ IFileDiffParam ,
23+ IFileDiffResp ,
24+ ILineNoteResp ,
25+ ILineNoteForm ,
2126} from 'src/typings/respResult' ;
27+
2228import { PromiseAdapter , promiseFromEvent , parseQuery , parseCloneUrl } from 'src/common/utils' ;
2329import { GitService } from 'src/common/gitService' ;
2430import { IRepoInfo , ISessionData , TokenType } from 'src/typings/commonTypes' ;
2531import { keychain } from 'src/common/keychain' ;
2632import Logger from 'src/common/logger' ;
2733
28- const AUTH_SERVER = `https://x5p7m.csb.app` ;
34+ const AUTH_SERVER = `https://x5p7m.csb.app/ ` ;
2935const ClientId = `ff768664c96d04235b1cc4af1e3b37a8` ;
3036const ClientSecret = `d29ebb32cab8b5f0a643b5da7dcad8d1469312c7` ;
3137
@@ -219,7 +225,7 @@ export class CodingServer {
219225
220226 public async getUserInfo ( team : string , token : string = this . _session ?. accessToken || `` ) {
221227 try {
222- const result : CodingResponse = await got
228+ const result : ICodingResponse = await got
223229 . get ( `https://${ team || `codingcorp` } .coding.net/api/current_user` , {
224230 searchParams : {
225231 access_token : token ,
@@ -266,10 +272,10 @@ export class CodingServer {
266272 } ;
267273 }
268274
269- public async getMRList ( repo ?: string , status ?: string ) : Promise < CodingResponse > {
275+ public async getMRList ( repo ?: string , status ?: string ) : Promise < ICodingResponse > {
270276 try {
271277 const { repoApiPrefix } = await this . getApiPrefix ( ) ;
272- const result : CodingResponse = await got
278+ const result : ICodingResponse = await got
273279 . get ( `${ repoApiPrefix } /merges/query` , {
274280 searchParams : {
275281 status,
@@ -390,10 +396,10 @@ export class CodingServer {
390396 }
391397 }
392398
393- public async getMRComments ( iid : string ) {
399+ public async getMRComments ( iid : string | number ) {
394400 try {
395401 const { repoApiPrefix } = await this . getApiPrefix ( ) ;
396- const result : CodingResponse = await got
402+ const result : IMRCommentResp = await got
397403 . get ( `${ repoApiPrefix } /merge/${ iid } /comments` , {
398404 searchParams : {
399405 access_token : this . _session ?. accessToken ,
@@ -413,7 +419,7 @@ export class CodingServer {
413419 public async closeMR ( iid : string ) {
414420 try {
415421 const { repoApiPrefix } = await this . getApiPrefix ( ) ;
416- const result : CodingResponse = await got
422+ const result : ICodingResponse = await got
417423 . post ( `${ repoApiPrefix } /merge/${ iid } /refuse` , {
418424 searchParams : {
419425 access_token : this . _session ?. accessToken ,
@@ -433,7 +439,7 @@ export class CodingServer {
433439 public async approveMR ( iid : string ) {
434440 try {
435441 const { repoApiPrefix } = await this . getApiPrefix ( ) ;
436- const result : CodingResponse = await got
442+ const result : ICodingResponse = await got
437443 . post ( `${ repoApiPrefix } /merge/${ iid } /good` , {
438444 searchParams : {
439445 access_token : this . _session ?. accessToken ,
@@ -453,7 +459,7 @@ export class CodingServer {
453459 public async disapproveMR ( iid : string ) {
454460 try {
455461 const { repoApiPrefix } = await this . getApiPrefix ( ) ;
456- const result : CodingResponse = await got
462+ const result : ICodingResponse = await got
457463 . delete ( `${ repoApiPrefix } /merge/${ iid } /good` , {
458464 searchParams : {
459465 access_token : this . _session ?. accessToken ,
@@ -473,7 +479,7 @@ export class CodingServer {
473479 public async mergeMR ( iid : string ) {
474480 try {
475481 const { repoApiPrefix } = await this . getApiPrefix ( ) ;
476- const result : CodingResponse = await got
482+ const result : ICodingResponse = await got
477483 . post ( `${ repoApiPrefix } /merge/${ iid } /merge` , {
478484 searchParams : {
479485 access_token : this . _session ?. accessToken ,
@@ -496,7 +502,7 @@ export class CodingServer {
496502 public async updateMRTitle ( iid : string , title : string ) {
497503 try {
498504 const { repoApiPrefix } = await this . getApiPrefix ( ) ;
499- const result : CodingResponse = await got
505+ const result : ICodingResponse = await got
500506 . put ( `${ repoApiPrefix } /merge/${ iid } /update-title` , {
501507 searchParams : {
502508 access_token : this . _session ?. accessToken ,
@@ -626,7 +632,7 @@ export class CodingServer {
626632
627633 public async addMRReviewers ( iid : string , ids : number [ ] ) : Promise < number [ ] > {
628634 const { repoApiPrefix } = await this . getApiPrefix ( ) ;
629- const tasks : Promise < CodingResponse > [ ] = ids . map ( ( id ) => {
635+ const tasks : Promise < ICodingResponse > [ ] = ids . map ( ( id ) => {
630636 return got
631637 . post ( `${ repoApiPrefix } /merge/${ iid } /reviewers` , {
632638 searchParams : {
@@ -636,7 +642,7 @@ export class CodingServer {
636642 } )
637643 . json ( ) ;
638644 } ) ;
639- const result : PromiseSettledResult < CodingResponse > [ ] = await Promise . allSettled ( tasks ) ;
645+ const result : PromiseSettledResult < ICodingResponse > [ ] = await Promise . allSettled ( tasks ) ;
640646 const fulfilled = ids . reduce ( ( res , cur , idx ) => {
641647 if ( result [ idx ] . status === `fulfilled` ) {
642648 res = res . concat ( cur ) ;
@@ -649,7 +655,7 @@ export class CodingServer {
649655
650656 public async removeMRReviewers ( iid : string , ids : number [ ] ) : Promise < number [ ] > {
651657 const { repoApiPrefix } = await this . getApiPrefix ( ) ;
652- const tasks : Promise < CodingResponse > [ ] = ids . map ( ( id ) => {
658+ const tasks : Promise < ICodingResponse > [ ] = ids . map ( ( id ) => {
653659 return got
654660 . delete ( `${ repoApiPrefix } /merge/${ iid } /reviewers` , {
655661 searchParams : {
@@ -659,7 +665,7 @@ export class CodingServer {
659665 } )
660666 . json ( ) ;
661667 } ) ;
662- const result : PromiseSettledResult < CodingResponse > [ ] = await Promise . allSettled ( tasks ) ;
668+ const result : PromiseSettledResult < ICodingResponse > [ ] = await Promise . allSettled ( tasks ) ;
663669 const fulfilled = ids . reduce ( ( res , cur , idx ) => {
664670 if ( result [ idx ] . status === `fulfilled` ) {
665671 res = res . concat ( cur ) ;
@@ -715,6 +721,52 @@ export class CodingServer {
715721 }
716722 }
717723
724+ public async fetchFileDiffs ( param : IFileDiffParam ) {
725+ try {
726+ const { repoApiPrefix } = await this . getApiPrefix ( ) ;
727+ const resp : IFileDiffResp = await got
728+ . get ( `${ repoApiPrefix } /compare_with_path` , {
729+ searchParams : {
730+ access_token : this . _session ?. accessToken ,
731+ base : param . base ,
732+ compare : param . compare ,
733+ path : encodeURIComponent ( param . path ) ,
734+ mergeRequestId : param . mergeRequestId ,
735+ } ,
736+ } )
737+ . json ( ) ;
738+
739+ if ( resp . code ) {
740+ return Promise . reject ( resp ) ;
741+ }
742+
743+ return resp ;
744+ } catch ( e ) {
745+ return Promise . reject ( e ) ;
746+ }
747+ }
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+
718770 get loggedIn ( ) {
719771 return this . _loggedIn ;
720772 }
0 commit comments