Skip to content

Commit 23bae52

Browse files
author
guqiankun.gqk
committed
feat: 支持3-way-merge 解决冲突
1 parent 821d06e commit 23bae52

8 files changed

Lines changed: 87 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
{
100100
"publisher": "cloud-ide-ext",
101101
"name": "web-scm",
102-
"version": "0.1.3"
102+
"version": "0.1.10"
103103
},
104104
{
105105
"publisher": "alex-ext-public",

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable, Autowired } from '@opensumi/di';
22
import { localize, IReporterService, MessageType, LRUCache } from '@opensumi/ide-core-common';
33
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';
55
import { API } from './types';
66
import { Branch, FileAction, FileActionHeader, FileActionResult, Project } from '../common/types';
77
import {
@@ -461,4 +461,41 @@ export class AntCodeAPIService implements ICodeAPIService {
461461
)}/merge/conflicts?source_branch=${sourceBranch}&target_branch=${targetBranch}`
462462
);
463463
}
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+
}
464501
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ export interface ICodeAPIService {
368368
sourceBranch: string,
369369
targetBranch: string
370370
): Promise<AntCodeAPI.ConflictResponse>;
371+
372+
mergeBase(
373+
repo: IRepositoryModel,
374+
target: string,
375+
source: string
376+
): Promise<AntCodeAPI.ResponseCommit>;
371377
}
372378

373379
export interface ICodeAPIServiceProvider extends ICodeAPIService {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ export class GitHubAPIService implements ICodeAPIService {
6969
constructor() {
7070
this._OAUTH_TOKEN = this.config.token || this.helper.GITHUB_TOKEN;
7171
}
72+
mergeBase(
73+
repo: IRepositoryModel,
74+
target: string,
75+
source: string
76+
): Promise<ConflictAPI.ResponseCommit> {
77+
throw new Error('Method not implemented.');
78+
}
7279
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo> {
7380
throw new Error('Method not implemented.');
7481
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ export class GitLabAPIService implements ICodeAPIService {
6666
constructor() {
6767
this._PRIVATE_TOKEN = this.config.token || this.helper.GITLAB_TOKEN;
6868
}
69+
mergeBase(
70+
repo: IRepositoryModel,
71+
target: string,
72+
source: string
73+
): Promise<ConflictAPI.ResponseCommit> {
74+
throw new Error('Method not implemented.');
75+
}
6976
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo> {
7077
throw new Error('Method not implemented.');
7178
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ export class GitLinkAPIService implements ICodeAPIService {
6161
constructor() {
6262
this._PRIVATE_TOKEN = this.config.token || '';
6363
}
64+
mergeBase(
65+
repo: IRepositoryModel,
66+
target: string,
67+
source: string
68+
): Promise<ConflictAPI.ResponseCommit> {
69+
throw new Error('Method not implemented.');
70+
}
6471
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo> {
6572
throw new Error('Method not implemented.');
6673
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ namespace CODE_SERVICE_COMMANDS {
126126
id: 'code-service.getConflict',
127127
category: CATEGORY,
128128
};
129+
export const MERGEBASE: Command = {
130+
id: 'code-service.mergeBase',
131+
category: CATEGORY,
132+
};
129133
}
130134

131135
export enum RemoteResourceType {
@@ -192,6 +196,7 @@ export class CommandsContribution extends Disposable implements CommandContribut
192196
CODE_SERVICE_COMMANDS.GETFILES,
193197
CODE_SERVICE_COMMANDS.GETUSER,
194198
CODE_SERVICE_COMMANDS.SCMREFRESH,
199+
CODE_SERVICE_COMMANDS.MERGEBASE,
195200
// CODE_SERVICE_COMMANDS.CREATEBRANCHFROM,
196201

197202
// conflict
@@ -403,6 +408,12 @@ export class CommandsContribution extends Disposable implements CommandContribut
403408
return repo.request.createBranch(newBranchName, ref);
404409
}
405410

411+
async mergeBase(repoPath: string, target: string, source: string) {
412+
const repo = this.codeModel.getRepository(repoPath);
413+
if (!repo) throw new Error('conflict request Error createNewBranch');
414+
return repo.request.mergeBase(target, source);
415+
}
416+
406417
// TODO: 暂时只支持根仓库的切换,submodules 切换会引起文件变更
407418
async checkoutBranch(repoPath: string, branchName: string) {
408419
const { rootRepository } = this.codeModel;

packages/integrations/src/startup/web-scm.plugin.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ export const activate = ({ commands }: IPluginAPI) => {
7070
});
7171

7272
commands.registerCommand('web-scm.windowOpen', async (path) => {
73-
window.open(path);
73+
if (!path) {
74+
window.location = window.location;
75+
} else {
76+
window.open(path);
77+
}
7478
});
7579

7680
/*
@@ -92,11 +96,11 @@ export const activate = ({ commands }: IPluginAPI) => {
9296
// 测试解决冲突内容
9397
return {
9498
isMergeConflicts: false,
95-
// sourceBranch: "merge2",
96-
// targetBranch: "merge1",
97-
// prId: "146007520",
98-
// hasTag: false,
99-
// from: 0
99+
sourceBranch: 'merge4',
100+
targetBranch: 'merge1',
101+
prId: '146206608',
102+
hasTag: false,
103+
from: 0,
100104
};
101105
});
102106
};

0 commit comments

Comments
 (0)