@@ -71,10 +71,16 @@ export class AntCodeAPIService implements ICodeAPIService {
7171 return `${ this . config . origin } /${ repo . owner } /${ repo . name } /raw/${ repo . commit } /${ path } ` ;
7272 }
7373
74- protected async request < T > ( path : string , options ?: RequestOptions ) : Promise < T > {
74+ protected async request < T > (
75+ path : string ,
76+ options ?: RequestOptions ,
77+ responseOptions ?: API . RequestResponseOptions
78+ ) : Promise < T > {
7579 const { platform, origin, endpoint } = this . config ;
76- const privateToken = this . PRIVATE_TOKEN ;
77-
80+ let privateToken = this . PRIVATE_TOKEN ;
81+ if ( path . startsWith ( '/webapi/' ) ) {
82+ privateToken = '' ;
83+ }
7884 try {
7985 const data = await request ( path , {
8086 baseURL : endpoint ,
@@ -91,7 +97,7 @@ export class AntCodeAPIService implements ICodeAPIService {
9197 : options ) ,
9298 } ) ;
9399 return data ;
94- } catch ( err : unknown ) {
100+ } catch ( err : any ) {
95101 if ( isResponseError ( err ) ) {
96102 const { status } = err . response ;
97103 this . reporter . point ( REPORT_NAME . CODE_SERVICE_REQUEST_ERROR , err . message , {
@@ -118,24 +124,17 @@ export class AntCodeAPIService implements ICodeAPIService {
118124 window . open ( origin ) ;
119125 }
120126 } ) ;
121- } else if ( status === 403 ) {
122- this . helper . showMessage ( CodePlatform . antcode , {
123- type : MessageType . Error ,
124- symbol : 'api.response.project-no-access' ,
125- status : 401 ,
126- } ) ;
127- } else if ( status === 404 ) {
128- // TODO 更精细化的错误提示
129- this . helper . showMessage ( CodePlatform . antcode , {
130- type : MessageType . Error ,
131- symbol : 'error.resource-not-found' ,
132- status : 404 ,
133- } ) ;
134127 } else {
128+ if ( responseOptions ?. errorOption === false ) {
129+ // 此处为了web-scm查询 新增文件无需提示
130+ console . log ( err ) ;
131+ return undefined as any ;
132+ }
135133 this . helper . showMessage ( CodePlatform . antcode , {
136134 type : MessageType . Error ,
137- symbol : 'error.request' ,
138- status,
135+ status : status ,
136+ symbol : err ?. message ? '' : 'error.request' ,
137+ message : err ?. message ,
139138 } ) ;
140139 }
141140 } else {
@@ -185,15 +184,21 @@ export class AntCodeAPIService implements ICodeAPIService {
185184 return new Uint8Array ( buf ) ;
186185 }
187186
188- async getBlobByCommitPath ( repo : IRepositoryModel , commit : string , path : string ) {
187+ async getBlobByCommitPath (
188+ repo : IRepositoryModel ,
189+ commit : string ,
190+ path : string ,
191+ options ?: API . RequestResponseOptions
192+ ) {
189193 const buf = await this . request < ArrayBuffer > (
190194 `/api/v3/projects/${ this . getProjectId ( repo ) } /repository/blobs/${ commit } ` ,
191195 {
192196 responseType : 'arrayBuffer' ,
193197 params : {
194198 filepath : path ,
195199 } ,
196- }
200+ } ,
201+ options
197202 ) ;
198203 return new Uint8Array ( buf ) ;
199204 }
@@ -391,10 +396,69 @@ export class AntCodeAPIService implements ICodeAPIService {
391396 return await this . request < Project > ( `/api/v3/projects/${ this . getProjectId ( repo ) } ` ) ;
392397 }
393398
394- // async function createPullRequest(data: CodeRegistryPullRequestCreateParameters): Promise<CodeRegistryPullRequest> {
395- // return (await this.request(`/api/v3/projects/${this.getProjectId(repo)}/pull_requests`,{
396- // data: data,
397- // method: 'post',
398- // }));
399- // }
399+ async canResolveConflict (
400+ repo : IRepositoryModel ,
401+ sourceBranch : string ,
402+ targetBranch : string ,
403+ prId ?: string
404+ ) : Promise < API . CanResolveConflictResponse > {
405+ if ( prId ) {
406+ return await this . request < API . CanResolveConflictResponse > (
407+ `/api/v3/projects/${ this . getProjectId (
408+ repo
409+ ) } /pull_requests/${ prId } /can_resolve_conflicts_inweb`
410+ ) ;
411+ }
412+ return await this . request < API . CanResolveConflictResponse > (
413+ `/webapi/projects/${ this . getProjectId ( repo ) } /repository/can_resolve_conflicts_inweb` ,
414+ {
415+ params : {
416+ source_branch : sourceBranch ,
417+ target_branch : targetBranch ,
418+ } ,
419+ }
420+ ) ;
421+ }
422+
423+ async resolveConflict (
424+ repo : IRepositoryModel ,
425+ content : API . ResolveConflict ,
426+ sourceBranch : string ,
427+ targetBranch : string ,
428+ prId ?: string
429+ ) : Promise < API . ResolveConflictResponse > {
430+ if ( prId ) {
431+ return await this . request < API . ResolveConflictResponse > (
432+ `/api/v3/projects/${ this . getProjectId ( repo ) } /pull_requests/${ prId } /resolve_conflicts` ,
433+ {
434+ method : 'put' ,
435+ data : content ,
436+ responseType : undefined ,
437+ }
438+ ) ;
439+ } else {
440+ return await this . request < API . ResolveConflictResponse > (
441+ `/webapi/projects/${ this . getProjectId (
442+ repo
443+ ) } /repository/resolve_conflicts?source_branch=${ sourceBranch } &target_branch=${ targetBranch } `,
444+ {
445+ method : 'put' ,
446+ data : content ,
447+ responseType : undefined ,
448+ }
449+ ) ;
450+ }
451+ }
452+
453+ async getConflict (
454+ repo : IRepositoryModel ,
455+ sourceBranch : string ,
456+ targetBranch : string
457+ ) : Promise < API . ConflictResponse > {
458+ return await this . request < API . ConflictResponse > (
459+ `/api/v3/projects/${ this . getProjectId (
460+ repo
461+ ) } /merge/conflicts?source_branch=${ sourceBranch } &target_branch=${ targetBranch } `
462+ ) ;
463+ }
400464}
0 commit comments