Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/github/activityBarViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { MergeArguments, PullRequest, ReviewType } from './views';
import { IComment } from '../common/comment';
import { emojify, ensureEmojis } from '../common/emoji';
import { disposeAll } from '../common/lifecycle';
import Logger from '../common/logger';
import { CHECKOUT_DEFAULT_BRANCH, CHECKOUT_PULL_REQUEST_BASE_BRANCH, DELETE_BRANCH_AFTER_MERGE, POST_DONE, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
import { ReviewEvent } from '../common/timelineEvent';
import { formatError } from '../common/utils';
Expand All @@ -25,7 +26,7 @@ import { ReviewManager } from '../view/reviewManager';
export class PullRequestViewProvider extends WebviewViewBase implements vscode.WebviewViewProvider {
public override readonly viewType = 'github:activePullRequest';
private _existingReviewers: ReviewState[] = [];
private _isUpdating: boolean = false;
private _updatingPromise: Promise<unknown> | undefined;

constructor(
extensionUri: vscode.Uri,
Expand Down Expand Up @@ -151,7 +152,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
}
this._prDisposables = [];
this._prDisposables.push(pullRequestModel.onDidChange(e => {
if ((e.state || e.comments || e.reviewers) && !this._isUpdating) {
if ((e.state || e.comments || e.reviewers) && !this._updatingPromise) {
this.updatePullRequest(pullRequestModel);
}
}));
Expand All @@ -160,10 +161,16 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W

private _updatePendingVisibility: vscode.Disposable | undefined = undefined;
public async updatePullRequest(pullRequestModel: PullRequestModel): Promise<void> {
if (this._isUpdating) {
throw new Error('Already updating pull request view');
const isSamePullRequest = pullRequestModel.equals(this._item);
if (this._updatingPromise && isSamePullRequest) {
Logger.error('Already updating pull request view', PullRequestViewProvider.name);
return;
} else if (this._updatingPromise && !isSamePullRequest) {
this._item = pullRequestModel;
await this._updatingPromise;
} else {
this._item = pullRequestModel;
}
this._isUpdating = true;

try {
if (this._view && !this._view.visible) {
Expand All @@ -178,7 +185,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
this.registerPrSpecificListeners(pullRequestModel);
}
this._item = pullRequestModel;
const [pullRequest, repositoryAccess, timelineEvents, requestedReviewers, branchInfo, defaultBranch, currentUser, viewerCanEdit, hasReviewDraft, coAuthors] = await Promise.all([
const updatingPromise = Promise.all([
this._folderRepositoryManager.resolvePullRequest(
pullRequestModel.remote.owner,
pullRequestModel.remote.repositoryName,
Expand All @@ -195,13 +202,19 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
pullRequestModel.getCoAuthors(),
ensureEmojis(this._folderRepositoryManager.context)
]);
this._updatingPromise = updatingPromise;
const [pullRequest, repositoryAccess, timelineEvents, requestedReviewers, branchInfo, defaultBranch, currentUser, viewerCanEdit, hasReviewDraft, coAuthors] = await updatingPromise;

if (!pullRequest) {
throw new Error(
`Fail to resolve Pull Request #${pullRequestModel.number} in ${pullRequestModel.remote.owner}/${pullRequestModel.remote.repositoryName}`,
);
}

if (!this._item.equals(pullRequestModel)) {
return;
}

this._item = pullRequest;
if (!this._view) {
// If the there is no PR webview, then there is nothing else to update.
Expand Down Expand Up @@ -292,8 +305,6 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W

} catch (e) {
vscode.window.showErrorMessage(`Error updating active pull request view: ${formatError(e)}`);
} finally {
this._isUpdating = false;
}
}

Expand Down
68 changes: 40 additions & 28 deletions src/github/pullRequestOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
private _assignableUsers: { [key: string]: IAccount[] } = {};

private _prListeners: vscode.Disposable[] = [];
private _isUpdating: boolean = false;
private _updatingPromise: Promise<unknown> | undefined;

public static override async createOrShow(
telemetry: ITelemetry,
Expand Down Expand Up @@ -172,7 +172,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode

if (this._item) {
this._prListeners.push(this._item.onDidChange(e => {
if ((e.state || e.comments) && !this._isUpdating) {
if ((e.state || e.comments) && !this._updatingPromise) {
this.refreshPanel();
}
}));
Expand Down Expand Up @@ -235,32 +235,19 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
}

protected override async updateItem(pullRequestModel: PullRequestModel): Promise<void> {
this._item = pullRequestModel;

if (this._isUpdating) {
throw new Error('Already updating pull request webview');
const isSamePullRequest = pullRequestModel.equals(this._item);
if (this._updatingPromise && isSamePullRequest) {
Logger.error('Already updating pull request webview', PullRequestOverviewPanel.ID);
return;
} else if (this._updatingPromise && !isSamePullRequest) {
this._item = pullRequestModel;
await this._updatingPromise;
} else {
this._item = pullRequestModel;
}
this._isUpdating = true;

try {
const [
pullRequest,
timelineEvents,
defaultBranch,
status,
requestedReviewers,
repositoryAccess,
branchInfo,
currentUser,
viewerCanEdit,
orgTeamsCount,
mergeQueueMethod,
isBranchUpToDateWithBase,
mergeability,
emailForCommit,
coAuthors,
hasReviewDraft,
assignableUsers
] = await Promise.all([
const updatingPromise = Promise.all([
this._folderRepositoryManager.resolvePullRequest(
pullRequestModel.remote.owner,
pullRequestModel.remote.repositoryName,
Expand All @@ -283,12 +270,39 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
pullRequestModel.validateDraftMode(),
this._folderRepositoryManager.getAssignableUsers()
]);
this._updatingPromise = updatingPromise;

const [
pullRequest,
timelineEvents,
defaultBranch,
status,
requestedReviewers,
repositoryAccess,
branchInfo,
currentUser,
viewerCanEdit,
orgTeamsCount,
mergeQueueMethod,
isBranchUpToDateWithBase,
mergeability,
emailForCommit,
coAuthors,
hasReviewDraft,
assignableUsers
] = await updatingPromise;
this._updatingPromise = undefined;
if (!pullRequest) {
throw new Error(
`Fail to resolve Pull Request #${pullRequestModel.number} in ${pullRequestModel.remote.owner}/${pullRequestModel.remote.repositoryName}`,
);
}

if (!this._item.equals(pullRequestModel)) {
// Updated PR is no longer the current one
return;
}

this._item = pullRequest;
this.registerPrListeners();
this._repositoryDefaultBranch = defaultBranch!;
Expand Down Expand Up @@ -361,8 +375,6 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
}
} catch (e) {
vscode.window.showErrorMessage(`Error updating pull request description: ${formatError(e)}`);
} finally {
this._isUpdating = false;
}
}

Expand Down