Skip to content

Commit f844dba

Browse files
committed
Clean up
1 parent d51e7cf commit f844dba

2 files changed

Lines changed: 21 additions & 24 deletions

File tree

src/github/folderRepositoryManager.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,11 +2453,8 @@ export class FolderRepositoryManager extends Disposable {
24532453
}
24542454

24552455
const isBrowser = (vscode.env.appHost === 'vscode.dev' || vscode.env.appHost === 'github.dev');
2456-
const hasNoConflicts = pullRequest.item.mergeable === PullRequestMergeability.Mergeable || pullRequest.item.mergeable === PullRequestMergeability.Behind;
24572456

2458-
// Use GraphQL API when PR is not checked out, in browser, or when there are no conflicts
2459-
// The GraphQL API is simpler and more efficient for conflict-free updates
2460-
if (!pullRequest.isActive || isBrowser || hasNoConflicts) {
2457+
if (!pullRequest.isActive || isBrowser) {
24612458
const conflictModel = await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: vscode.l10n.t('Finding conflicts...') }, () => createConflictResolutionModel(pullRequest));
24622459
if (conflictModel === undefined) {
24632460
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.') });
@@ -2472,18 +2469,27 @@ export class FolderRepositoryManager extends Disposable {
24722469
}
24732470

24742471
if (continueWithMerge) {
2475-
const updateSucceeded = await pullRequest.updateBranch(conflictModel);
2476-
// If the PR is currently checked out and update succeeded via GraphQL (no conflicts), pull to sync local branch
2477-
// When there are conflicts (REST API path), the update already pushes the changes, so no pull is needed
2478-
if (updateSucceeded && pullRequest.isActive && !isBrowser && hasNoConflicts) {
2479-
await this.repository.pull();
2480-
}
2481-
return updateSucceeded;
2472+
return pullRequest.updateBranch(conflictModel);
24822473
} else {
24832474
return false;
24842475
}
24852476
}
24862477

2478+
if (pullRequest.item.mergeable !== PullRequestMergeability.Conflict) {
2479+
const result = await vscode.window.withProgress(
2480+
{ location: vscode.ProgressLocation.Notification, title: vscode.l10n.t('Updating branch...') },
2481+
async () => {
2482+
const success = await pullRequest.updateBranchWithGraphQL();
2483+
if (success && pullRequest.isActive) {
2484+
await this.repository.pull();
2485+
}
2486+
return success;
2487+
}
2488+
);
2489+
return result;
2490+
}
2491+
2492+
24872493
if (this.repository.state.workingTreeChanges.length > 0 || this.repository.state.indexChanges.length > 0) {
24882494
await vscode.window.showErrorMessage(vscode.l10n.t('The pull request branch cannot be updated when the there changed files in the working tree or index. Stash or commit all change and then try again.'), { modal: true });
24892495
return false;
@@ -3063,7 +3069,7 @@ export const byRemoteName = (name: string): Predicate<GitHubRepository> => ({ re
30633069
/**
30643070
* Unwraps lines that were wrapped for conventional commit message formatting (typically at 72 characters).
30653071
* Similar to GitHub's behavior when converting commit messages to PR descriptions.
3066-
*
3072+
*
30673073
* Rules:
30683074
* - Preserves blank lines as paragraph breaks
30693075
* - Preserves fenced code blocks (```)

src/github/pullRequestModel.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,30 +1202,21 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
12021202
}
12031203

12041204
async updateBranch(model: ConflictResolutionModel): Promise<boolean> {
1205-
if (this.item.mergeable === PullRequestMergeability.Conflict && (!model.resolvedConflicts || model.resolvedConflicts.size === 0)) {
1205+
if (!model.resolvedConflicts || model.resolvedConflicts.size === 0) {
12061206
throw new Error('Pull Request has conflicts but no resolutions were provided.');
12071207
}
1208-
12091208
Logger.debug(`Updating branch ${model.prHeadBranchName} to ${model.prBaseBranchName} - enter`, GitHubRepository.ID);
1210-
1211-
// When there are no conflicts, use the GitHub GraphQL API's UpdatePullRequestBranch mutation.
1212-
// This is simpler and more efficient than manually creating trees and commits.
1213-
// The GraphQL API is suitable for Mergeable and Behind states, which can be cleanly updated.
1214-
if (this.item.mergeable === PullRequestMergeability.Mergeable || this.item.mergeable === PullRequestMergeability.Behind) {
1215-
return this.updateBranchWithGraphQL();
1216-
}
1217-
12181209
// For Conflict state, use the REST API approach with conflict resolution.
12191210
// For Unknown or NotMergeable states, the REST API approach will also be used as a fallback,
12201211
// though these states may fail for other reasons (e.g., blocked by branch protection).
1221-
return this.updateBranchWithConflictResolution(model);
1212+
return this.updateBranchWithConflictResolution(model!);
12221213
}
12231214

12241215
/**
12251216
* Update the branch using the GitHub GraphQL API's UpdatePullRequestBranch mutation.
12261217
* This is used when there are no conflicts between the head and base branches.
12271218
*/
1228-
private async updateBranchWithGraphQL(): Promise<boolean> {
1219+
public async updateBranchWithGraphQL(): Promise<boolean> {
12291220
Logger.debug(`Updating branch using GraphQL UpdatePullRequestBranch mutation - enter`, GitHubRepository.ID);
12301221

12311222
if (!this.head?.sha) {

0 commit comments

Comments
 (0)