Skip to content

Commit ba440c4

Browse files
committed
Frequently getting all conflicts have been resolved after clicking Resolve conflicts
Fixes #5952
1 parent 33751f1 commit ba440c4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/github/folderRepositoryManager.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
variableSubstitution,
5555
} from './utils';
5656

57-
async function createConflictResolutionModel(pullRequest: PullRequestModel): Promise<ConflictResolutionModel> {
57+
async function createConflictResolutionModel(pullRequest: PullRequestModel): Promise<ConflictResolutionModel | undefined> {
5858
const head = pullRequest.head;
5959
if (!head) {
6060
throw new Error('No head found for pull request');
@@ -67,6 +67,11 @@ async function createConflictResolutionModel(pullRequest: PullRequestModel): Pro
6767
const potentialMergeConflicts: Conflict[] = [];
6868
if (pullRequest.item.mergeable === PullRequestMergeability.Conflict) {
6969
const mergeBaseIntoPrCompareData = await pullRequest.compareBaseBranchForMerge(prHeadOwner, prHeadRef, prBaseOwner, baseCommitSha);
70+
if ((pullRequest.item.mergeable === PullRequestMergeability.Conflict) && (mergeBaseIntoPrCompareData.length >= 300)) {
71+
// API limitation: it only returns the first 300 files
72+
return undefined;
73+
}
74+
7075
const previousFilenames: Map<string, SlimFileChange | InMemFileChange> = new Map();
7176
// We must also check all the previous file names of the files in the PR. Assemble a map with this info
7277
for (const fileChange of pullRequest.fileChanges.values()) {
@@ -2149,8 +2154,13 @@ export class FolderRepositoryManager implements vscode.Disposable {
21492154
return true;
21502155
}
21512156

2152-
if (!pullRequest.isActive || (vscode.env.appHost === 'vscode.dev' || vscode.env.appHost === 'github.dev')) {
2157+
const isBrowser = (vscode.env.appHost === 'vscode.dev' || vscode.env.appHost === 'github.dev');
2158+
if (!pullRequest.isActive || isBrowser) {
21532159
const conflictModel = await createConflictResolutionModel(pullRequest);
2160+
if (conflictModel === undefined) {
2161+
await vscode.window.showErrorMessage(vscode.l10n.t('Unable to resolved conflicts for this pull request. There are too many file changes.'), { modal: true, detail: isBrowser ? undefined : vscode.l10n.t('Please check out the pull request to resolve conflicts.') });
2162+
return false;
2163+
}
21542164
let continueWithMerge = true;
21552165
if (pullRequest.item.mergeable === PullRequestMergeability.Conflict) {
21562166
const coordinator = new ConflictResolutionCoordinator(this.telemetry, conflictModel, this.gitHubRepositories.filter(repo => repo.remote.repositoryName === pullRequest.githubRepository.remote.repositoryName));

src/github/pullRequestModel.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -815,14 +815,14 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
815815
const { octokit, remote } = await this.githubRepository.ensure();
816816

817817
// Get the files that would change as part of the merge
818-
const compareData = await restPaginate<typeof octokit.api.repos.compareCommits, OctokitCommon.ReposCompareCommitsResponseData>(octokit.api.repos.compareCommits, {
818+
const compareData = await octokit.call(octokit.api.repos.compareCommits, {
819819
repo: remote.repositoryName,
820820
owner: headOwner,
821821
base: `${headOwner}:${headRef}`, // flip base and head because we are comparing for a merge to update the PR
822822
head: `${baseOwner}:${baseRef}`,
823823
});
824824

825-
return compareData.map(data => data.files).flat().filter<IRawFileChange>((change): change is IRawFileChange => change !== undefined);
825+
return compareData?.data?.files?.filter<IRawFileChange>((change): change is IRawFileChange => change !== undefined) ?? [];
826826
}
827827

828828
private async getUpdateBranchFiles(baseCommitSha: string, headTreeSha: string, model: ConflictResolutionModel): Promise<IGitTreeItem[]> {

0 commit comments

Comments
 (0)