|
1 | 1 | import { Injectable, Autowired } from '@opensumi/di'; |
2 | 2 | import { localize, IReporterService, MessageType, LRUCache } from '@opensumi/ide-core-common'; |
3 | 3 | import { REPORT_NAME } from '@alipay/alex-core'; |
4 | | -import { request, RequestOptions, isResponseError } from '@alipay/alex-shared'; |
| 4 | +import { request, RequestOptions, isResponseError, createUrl } from '@alipay/alex-shared'; |
5 | 5 | import { API } from './types'; |
6 | 6 | import { Branch, FileAction, FileActionHeader, FileActionResult, Project } from '../common/types'; |
7 | 7 | import { |
@@ -461,4 +461,41 @@ export class AntCodeAPIService implements ICodeAPIService { |
461 | 461 | )}/merge/conflicts?source_branch=${sourceBranch}&target_branch=${targetBranch}` |
462 | 462 | ); |
463 | 463 | } |
| 464 | + |
| 465 | + /* |
| 466 | + * 获取两个分支 的共同祖先 |
| 467 | + * 类似于 git merge-base branch1 branch2 |
| 468 | + * 接口暂时只支持查询两个分支 |
| 469 | + */ |
| 470 | + async mergeBase( |
| 471 | + repo: IRepositoryModel, |
| 472 | + target: string, |
| 473 | + source: string |
| 474 | + ): Promise<API.ResponseCommit> { |
| 475 | + let url = `/api/v4/projects/${this.getProjectId( |
| 476 | + repo |
| 477 | + )}/repository/merge_base?refs[]=${target}&refs[]=${source}`; |
| 478 | + if (this.config.endpoint) { |
| 479 | + url = createUrl(this.config.endpoint, url); |
| 480 | + } |
| 481 | + const urlInstance = new URL(url, location.origin); |
| 482 | + const privateToken = this.PRIVATE_TOKEN; |
| 483 | + return ( |
| 484 | + await fetch(urlInstance.toString(), { |
| 485 | + method: 'GET', |
| 486 | + ...(privateToken |
| 487 | + ? { |
| 488 | + headers: { |
| 489 | + 'PRIVATE-TOKEN': privateToken, |
| 490 | + 'Content-Type': 'application/json', |
| 491 | + }, |
| 492 | + } |
| 493 | + : { |
| 494 | + headers: { |
| 495 | + 'Content-Type': 'application/json', |
| 496 | + }, |
| 497 | + }), |
| 498 | + }) |
| 499 | + ).json(); |
| 500 | + } |
464 | 501 | } |
0 commit comments