Skip to content

Commit 96af1b5

Browse files
author
guqiankun.gqk
committed
chore: 移除gitlink创建分支能力
1 parent 68c8b62 commit 96af1b5

6 files changed

Lines changed: 29 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const CODE_PLATFORM_CONFIG: Record<ICodePlatform, ICodePlatformConfig> =
113113
return `#L${startLineNumber}-${endLineNumber}`;
114114
},
115115
},
116-
createBranchAble: true,
116+
createBranchAble: false,
117117
},
118118
};
119119

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ export interface ICodeAPIProvider {
225225
asPlatform(platform: ICodePlatform): ICodeAPIService;
226226
}
227227

228+
export interface RequestFailed {
229+
message: string;
230+
status?: number;
231+
error?: string;
232+
}
233+
228234
export interface ICodeAPIService {
229235
/**
230236
* 检查 API service 可用性

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ export class GitLinkAPIService implements ICodeAPIService {
100100

101101
// TODO 静态资源路径 gitlink 静态资源好像无法用commit获取
102102
transformStaticResource(repo: IRepositoryModel, path: string) {
103-
return `${this.config.origin}/repo/${this.getProjectPath(repo)}/${repo.commit}/${path}`;
104-
// return `${this.config.origin}/repo/${this.getProjectPath(repo)}/raw/branch/${ref}/${path}`;
103+
return `${this.config.origin}/repo/${this.getProjectPath(repo)}/raw/branch/${
104+
repo.commit
105+
}/${path}`;
105106
}
106107

107108
protected async request<T>(path: string, options?: RequestOptions): Promise<T> {

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { CodeModelService } from './code-model.service';
4242
import { RefType, ICodeServiceConfig, CodePlatform } from './types';
4343
import { Configure } from './config.service';
4444
import { ISCMRepository, SCMService, ISCMResource, ISCMResourceGroup } from '@opensumi/ide-scm';
45-
import { CODE_PLATFORM_CONFIG } from '@alipay/alex-code-api';
45+
import { CODE_PLATFORM_CONFIG, RequestFailed } from '@alipay/alex-code-api';
4646

4747
namespace CODE_SERVICE_COMMANDS {
4848
const CATEGORY = 'CodeService';
@@ -343,15 +343,20 @@ export class CodeContribution
343343
}
344344
if (!refBranches.find((b) => b.name === newBranchName)) {
345345
const branch = await repo.request.createBranch(newBranchName, repo.commit);
346-
if (branch) {
346+
if (branch?.commit.id) {
347347
this.messageService.info(
348348
formatLocalize('code-service.command.create-branch-success', newBranchName)
349349
);
350350
await repo.refreshRepository(branch.commit.id, branch.name);
351+
} else {
352+
this.messageService.error(
353+
(branch as any as RequestFailed).message ||
354+
formatLocalize('code-service.command.create-branch-error', newBranchName)
355+
);
351356
}
352357
} else {
353358
this.messageService.error(
354-
formatLocalize('code-service.command.create-branch-error', newBranchName)
359+
formatLocalize('code-service.command.create-branch-error-exists', newBranchName)
355360
);
356361
}
357362
},
@@ -367,7 +372,7 @@ export class CodeContribution
367372
}
368373
if (repo.refs.branches.find((b) => b.name === newBranchName)) {
369374
this.messageService.error(
370-
formatLocalize('code-service.command.create-branch-error', newBranchName)
375+
formatLocalize('code-service.command.create-branch-error-exists', newBranchName)
371376
);
372377
return;
373378
}
@@ -389,11 +394,16 @@ export class CodeContribution
389394
if (typeof value === 'number') {
390395
const target = refs[value];
391396
const branch = await repo.request.createBranch(newBranchName, target.commit);
392-
if (branch) {
397+
if (branch?.commit.id) {
393398
this.messageService.info(
394399
formatLocalize('code-service.command.create-branch-success', newBranchName)
395400
);
396401
await repo.refreshRepository(branch.commit.id, branch.name);
402+
} else {
403+
this.messageService.error(
404+
(branch as any as RequestFailed).message ||
405+
formatLocalize('code-service.command.create-branch-error', newBranchName)
406+
);
397407
}
398408
}
399409
},

packages/i18n/src/en-US.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export const localizationBundle = {
3232

3333
'code-service.command.create-branch': 'Create new branch...',
3434
'code-service.command.create-branch-from': 'Create new branch from...',
35-
'code-service.command.create-branch-error': 'New Branch is exists {0}',
35+
'code-service.command.create-branch-error-exists': 'New Branch is exists {0}',
36+
'code-service.command.create-branch-error': 'Create branch failed {0}',
3637
'code-service.command.create-branch-success': 'New branch {0} created success',
3738
'code-service.command.new-branch-name': 'Input new branch name',
3839
'code-service.command.check-branch-name': 'Check the new branch name',

packages/i18n/src/zh-CN.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export const localizationBundle = {
3131

3232
'code-service.command.create-branch': '创建分支',
3333
'code-service.command.create-branch-from': '从...创建分支',
34-
'code-service.command.create-branch-error': '分支已存在 {0}',
34+
'code-service.command.create-branch-error-exists': '分支已存在 {0}',
35+
'code-service.command.create-branch-error': '分支创建失败 {0}',
3536
'code-service.command.create-branch-success': '分支 {0} 创建成功',
3637
'code-service.command.new-branch-name': '输入新分支',
3738
'code-service.command.check-branch-name': '检查分支名是否正确',

0 commit comments

Comments
 (0)