Skip to content

Commit 7fbc64c

Browse files
Let the view know about the review status of the PR (#1833)
1 parent 7aabb24 commit 7fbc64c

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

src/github/pullRequestOverview.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
139139
});
140140
}
141141

142+
/**
143+
* Find currently configured user's review status for the current PR
144+
* @param reviewers All the reviewers who have been requested to review the current PR
145+
* @param pullRequestModel Model of the PR
146+
*/
147+
private getCurrentUserReviewState(reviewers: ReviewState[], currentUser: IAccount): string | undefined {
148+
const review = reviewers.find(r => r.reviewer.login === currentUser.login);
149+
// There will always be a review. If not then the PR shouldn't have been or fetched/shown for the current user
150+
return review?.state;
151+
}
152+
142153
public async updatePullRequest(pullRequestModel: PullRequestModel): Promise<void> {
143154
return Promise.all([
144155
this._folderRepositoryManager.resolvePullRequest(
@@ -190,7 +201,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
190201
!pullRequest.base.repositoryCloneUrl.equals(pullRequest.head.repositoryCloneUrl);
191202

192203
const continueOnGitHub = isCrossRepository && isInCodespaces();
193-
204+
const reviewState = this.getCurrentUserReviewState(this._existingReviewers, currentUser);
194205
Logger.debug('pr.initialize', PullRequestOverviewPanel.ID);
195206
this._postMessage({
196207
command: 'pr.initialize',
@@ -230,6 +241,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
230241
assignees: pullRequest.assignees,
231242
continueOnGitHub,
232243
isAuthor: currentUser.login === pullRequest.author.login,
244+
currentUserReviewState: reviewState
233245
},
234246
});
235247
})

webviews/common/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ export interface PullRequest {
6363
reviewers: ReviewState[];
6464
isDraft?: boolean;
6565
isIssue: boolean;
66-
6766
isAuthor?: boolean;
6867
continueOnGitHub: boolean;
68+
currentUserReviewState: string;
6969
}
7070

7171
export function getState(): PullRequest {

webviews/common/context.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { createContext } from 'react';
77
import { IComment } from '../../src/common/comment';
88
import { EventType, isReviewEvent, ReviewEvent } from '../../src/common/timelineEvent';
9-
import { MergeMethod } from '../../src/github/interface';
9+
import { MergeMethod, ReviewState } from '../../src/github/interface';
1010
import { getState, PullRequest, setState, updateState } from './cache';
1111
import { getMessageHandler, MessageHandler } from './message';
1212

@@ -148,7 +148,7 @@ export class PRContext {
148148
this.postMessage({ command: 'pr.apply-patch', args: { comment } });
149149
};
150150

151-
private appendReview({ review, reviewers }: any) {
151+
private appendReview({ review, reviewers }: {review: ReviewEvent, reviewers: ReviewState[]}) {
152152
const state = this.pr;
153153
const events = state.events.filter(e => !isReviewEvent(e) || e.state.toLowerCase() !== 'pending');
154154
events.forEach(event => {
@@ -158,6 +158,7 @@ export class PRContext {
158158
});
159159
state.reviewers = reviewers;
160160
state.events = [...state.events.filter(e => (isReviewEvent(e) ? e.state !== 'PENDING' : e)), review];
161+
state.currentUserReviewState = review.state;
161162
this.updatePR(state);
162163
}
163164

webviews/components/comment.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export function AddComment({
238238
isIssue,
239239
isAuthor,
240240
continueOnGitHub,
241+
currentUserReviewState
241242
}: PullRequest) {
242243
const { updatePR, comment, requestChanges, approve, close, openOnGitHub } = useContext(PullRequestContext);
243244
const [isBusy, setBusy] = useState(false);
@@ -332,7 +333,7 @@ export function AddComment({
332333
<button
333334
id="approve"
334335
className="secondary"
335-
disabled={isBusy}
336+
disabled={isBusy || currentUserReviewState === 'APPROVED'}
336337
onClick={onClick}
337338
data-command="approve"
338339
>

webviews/editorWebview/test/builder/pullRequest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ export const PullRequestBuilder = createBuilderClass<PullRequest>()({
3838
assignees: { default: [] },
3939
milestone: { default: undefined },
4040
continueOnGitHub: { default: false },
41+
currentUserReviewState: { default: 'REQUESTED' }
4142
});

0 commit comments

Comments
 (0)