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
73 changes: 48 additions & 25 deletions src/github/activityBarViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
public override readonly viewType = 'github:activePullRequest';
private _existingReviewers: ReviewState[] = [];
private _updatingPromise: Promise<unknown> | undefined;
private _stackUpdateSequence = 0;

constructor(
extensionUri: vscode.Uri,
private readonly _folderRepositoryManager: FolderRepositoryManager,
private readonly _reviewManager: ReviewManager,
private readonly _reviewManager: Pick<ReviewManager, 'createPullRequest'>,
private _item: PullRequestModel,
) {
super(extensionUri);
Expand Down Expand Up @@ -173,6 +174,49 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
}
}));
this._prDisposables.push(pullRequestModel.onDidChangePendingReviewState(() => this.updatePullRequest(pullRequestModel)));
this._prDisposables.push(pullRequestModel.githubRepository.onDidChangeStack(numbers => {
if (numbers.includes(this._item.number)) {
void this.refreshStack();
}
}));
Comment thread
alexr00 marked this conversation as resolved.
}

public override dispose(): void {
disposeAll(this._prDisposables ?? []);
this._updatePendingVisibility?.dispose();
super.dispose();
}

private async refreshStack(): Promise<void> {
const updateSequence = ++this._stackUpdateSequence;
const pullRequest = this._item;
if (this.isDisposed || !this._view || !areStacksEnabled()) {
return;
}
try {
const stack = await pullRequest.getStack();
if (this.isDisposed || updateSequence !== this._stackUpdateSequence || !areStacksEnabled()) {
return;
}
const mergeQueueMethod = await this._folderRepositoryManager.mergeQueueMethodForBranch(
stack?.base ?? pullRequest.base.ref, pullRequest.remote.owner, pullRequest.remote.repositoryName);
if (!this.isDisposed && updateSequence === this._stackUpdateSequence && areStacksEnabled()) {
await this._postMessage({
command: 'pr.update',
pullrequest: {
stack: stack ?? null,
stackLoaded: true,
stackLoadError: false,
mergeQueueMethod: mergeQueueMethod ?? null,
} satisfies Partial<PullRequest>,
});
}
} catch (error) {
Logger.error(`Failed to load active pull request stack: ${formatError(error)}`, PullRequestViewProvider.name);
if (!this.isDisposed && updateSequence === this._stackUpdateSequence && areStacksEnabled()) {
void this._postMessage({ command: 'pr.update', pullrequest: { stackLoadError: true } satisfies Partial<PullRequest> });
}
}
}

private _updatePendingVisibility: vscode.Disposable | undefined = undefined;
Expand All @@ -189,6 +233,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
}

try {
this._stackUpdateSequence++;
if (this._view && !this._view.visible) {
this._updatePendingVisibility?.dispose();
this._updatePendingVisibility = this._view.onDidChangeVisibility(async () => {
Expand All @@ -197,7 +242,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
});
}

if ((this._prDisposables === undefined) || (pullRequestModel.number !== this._item.number)) {
if ((this._prDisposables === undefined) || !isSamePullRequest) {
this.registerPrSpecificListeners(pullRequestModel);
}
this._item = pullRequestModel;
Expand Down Expand Up @@ -329,29 +374,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
command: 'pr.initialize',
pullrequest: context,
});
if (areStacksEnabled()) {
void pullRequest.getStack().then(async stack => {
if (!this._item.equals(pullRequest) || !areStacksEnabled()) {
return;
}
const stackQueueMethod = stack ? await this._folderRepositoryManager.mergeQueueMethodForBranch(stack.base, pullRequest.remote.owner, pullRequest.remote.repositoryName) : undefined;
if (this._item.equals(pullRequest) && areStacksEnabled()) {
this._postMessage({
command: 'pr.update',
pullrequest: {
stack,
stackLoaded: true,
...(stack ? { mergeQueueMethod: stackQueueMethod } : {}),
} satisfies Partial<PullRequest>,
});
}
}).catch(error => {
Logger.error(`Failed to load active pull request stack: ${formatError(error)}`, PullRequestViewProvider.name);
if (this._item.equals(pullRequest) && areStacksEnabled()) {
this._postMessage({ command: 'pr.update', pullrequest: { stackLoadError: true } satisfies Partial<PullRequest> });
}
});
}
void this.refreshStack();

} catch (e) {
vscode.window.showErrorMessage(`Error updating active pull request view: ${formatError(e)}`);
Expand Down
4 changes: 2 additions & 2 deletions src/github/pullRequestOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,11 +783,11 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
await this._postMessage({
command: 'pr.update',
pullrequest: {
stack: linkedStack,
stack: linkedStack ?? null,
stackLoaded: true,
stackLoadError: false,
canUpdateStack: this.canUpdateStack(pullRequestModel),
mergeQueueMethod,
mergeQueueMethod: mergeQueueMethod ?? null,
} satisfies Partial<PullRequest>,
});
}
Expand Down
6 changes: 4 additions & 2 deletions src/github/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export type PullRequestPreview = Pick<PullRequest, 'number' | 'title' | 'titleHT
export type OverviewItemPreview = IssuePreview | PullRequestPreview;

export interface PullRequest extends Issue {
stack?: PullRequestStack;
/** Use null to clear a previous value in serialized webview updates. */
stack?: PullRequestStack | null;
canUpdateStack?: boolean;
stackLoaded?: boolean;
stackLoadError?: boolean;
Expand Down Expand Up @@ -115,7 +116,8 @@ export interface PullRequest extends Issue {
autoMerge?: boolean;
allowAutoMerge: boolean;
autoMergeMethod?: MergeMethod;
mergeQueueMethod: MergeMethod | undefined;
/** Use null to clear a previous value in serialized webview updates. */
mergeQueueMethod: MergeMethod | undefined | null;
mergeQueueEntry?: {
url: string;
position: number;
Expand Down
Loading
Loading