Skip to content

Commit ce83261

Browse files
committed
fix: 修复Code服务接入
1 parent 832222f commit ce83261

5 files changed

Lines changed: 18 additions & 52 deletions

File tree

packages/code-api/src/code-api.provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { IMainLayoutService } from '@opensumi/ide-main-layout';
1111
import { ICodePlatform, ICodeAPIProvider, ICodeAPIService, CodePlatform } from './common/types';
1212
import { AntCodeAPIService } from './antcode/antcode.service';
13-
import { CodeAPIService } from './antcode/code.service';
13+
import CodeAPIService from './code/code.service';
1414
import { GitHubAPIService } from './github/github.service';
1515
import { GitLabAPIService } from './gitlab/gitlab.service';
1616
import { GitLinkAPIService } from './gitlink/gitlink.service';

packages/code-api/src/code/code.service.ts

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const webgwRequestOpts = {
1616
/**
1717
* 小程序云Code
1818
*/
19-
export default class CodeApiService extends AntCodeAPIService {
19+
export default class CodeAPIService extends AntCodeAPIService {
2020
config = CODE_PLATFORM_CONFIG[CodePlatform.code];
2121

2222
protected async request<T>(
@@ -34,16 +34,14 @@ export default class CodeApiService extends AntCodeAPIService {
3434
baseURL: endpoint,
3535
credentials: 'include',
3636
responseType: 'json',
37-
...(privateToken
38-
? {
39-
...options,
40-
headers: {
41-
'PRIVATE-TOKEN': privateToken,
42-
...webgwRequestOpts,
43-
...options?.headers,
44-
},
45-
}
46-
: options),
37+
...options,
38+
...({
39+
headers: {
40+
...(privateToken ? { 'PRIVATE-TOKEN': privateToken } : {}),
41+
...options?.headers,
42+
...webgwRequestOpts,
43+
},
44+
}),
4745
});
4846
return data;
4947
} catch (err: any) {
@@ -58,10 +56,10 @@ export default class CodeApiService extends AntCodeAPIService {
5856
const goto = localize('api.login.goto');
5957
this.helper
6058
.showMessage(
61-
CodePlatform.antcode,
59+
CodePlatform.code,
6260
{
6361
type: MessageType.Error,
64-
symbol: 'api.response.no-login-antcode',
62+
symbol: 'api.response.no-login-code',
6563
status: 401,
6664
},
6765
{
@@ -96,46 +94,11 @@ export default class CodeApiService extends AntCodeAPIService {
9694
}
9795
}
9896

99-
private getProjectIdByRepo(repo: IRepositoryModel) {
100-
return `${repo.owner}%2F${repo.name}`;
101-
}
102-
103-
/*
104-
* 获取两个分支 的共同祖先
105-
* 类似于 git merge-base branch1 branch2
106-
* 接口暂时只支持查询两个分支
107-
*/
108-
async mergeBase(
97+
mergeBase(
10998
repo: IRepositoryModel,
11099
target: string,
111100
source: string
112101
): Promise<API.ResponseCommit> {
113-
let url = `/tcloudantcodeweb/api/v4/projects/${this.getProjectIdByRepo(
114-
repo
115-
)}/repository/merge_base?refs[]=${target}&refs[]=${source}`;
116-
if (this.config.endpoint) {
117-
url = createUrl(this.config.endpoint, url);
118-
}
119-
const urlInstance = new URL(url, location.origin);
120-
const privateToken = this.PRIVATE_TOKEN;
121-
return (
122-
await fetch(urlInstance.toString(), {
123-
method: 'GET',
124-
...(privateToken
125-
? {
126-
headers: {
127-
'PRIVATE-TOKEN': privateToken,
128-
'Content-Type': 'application/json',
129-
...webgwRequestOpts
130-
},
131-
}
132-
: {
133-
headers: {
134-
'Content-Type': 'application/json',
135-
...webgwRequestOpts
136-
},
137-
}),
138-
})
139-
).json();
102+
throw new Error('Method not implemented.');
140103
}
141104
}

packages/code-api/src/common/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const CODE_PLATFORM_CONFIG: Record<ICodePlatform, ICodePlatformConfig> =
4848
[CodePlatform.code]: {
4949
platform: CodePlatform.code,
5050
hostname: [],
51-
origin: 'https://twebgwnet.alipay.com',
51+
origin: 'https://code.cloud.alipay.com',
5252
endpoint: 'https://twebgwnet.alipay.com',
5353
brand: 'Code',
5454
line: {

packages/i18n/src/en-US.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export const localizationBundle = {
2525
'api.response.project-no-access': 'No access to project',
2626
'api.response.no-login-antcode':
2727
'Login to antcode is expired, please refresh page if you are logged in',
28+
'api.response.no-login-code':
29+
'Login to Code is expired, please refresh page if you are logged in',
2830
'api.login.goto': 'Go to login',
2931
'error.unknown': 'Unknown Error',
3032
'error.request': 'Request Error',

packages/i18n/src/zh-CN.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const localizationBundle = {
2424
'api.response.project-not-found': '{0} 不存在',
2525
'api.response.project-no-access': '无权限访问项目',
2626
'api.response.no-login-antcode': 'antcode 登录已失效,如已登录请刷新页面',
27+
'api.response.no-login-code': 'code 登录已失效,如已登录请刷新页面',
2728
'api.login.goto': '前往登录',
2829
'error.unknown': '未知错误',
2930
'error.request': '请求错误',

0 commit comments

Comments
 (0)