Skip to content

Commit 0f1dd96

Browse files
Copilotalexr00
andauthored
Exclude pending reviews from "Show Changes Since Last Review" (#8264)
* Initial plan * Initial plan for fixing Show Changes Since Last Review Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Modify GraphQL query to exclude pending reviews from last review Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Fix test builder for array handling Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Use 'last: 1' to get the most recent review instead of 'first: 1' Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Revert API proposal changes that were unintentionally included Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 9934ff2 commit 0f1dd96

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

src/github/graphql.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,12 @@ export interface LatestUpdatesResponse {
322322
export interface LatestReviewCommitResponse {
323323
repository: {
324324
pullRequest: {
325-
viewerLatestReview: {
326-
commit: {
327-
oid: string;
328-
}
325+
reviews: {
326+
nodes: {
327+
commit: {
328+
oid: string;
329+
}
330+
}[];
329331
};
330332
};
331333
} | null;

src/github/pullRequestModel.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
599599
async getViewerLatestReviewCommit(): Promise<{ sha: string } | undefined> {
600600
Logger.debug(`Fetch viewers latest review commit`, IssueModel.ID);
601601
const { query, remote, schema } = await this.githubRepository.ensure();
602+
const currentUser = (await this.githubRepository.getAuthenticatedUser()).login;
602603

603604
try {
604605
const { data } = await query<LatestReviewCommitResponse>({
@@ -607,15 +608,17 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
607608
owner: remote.owner,
608609
name: remote.repositoryName,
609610
number: this.number,
611+
author: currentUser,
610612
},
611613
});
612614

613615
if (data.repository === null) {
614616
Logger.error('Unexpected null repository while getting last review commit', PullRequestModel.ID);
615617
}
616618

617-
return data.repository?.pullRequest.viewerLatestReview ? {
618-
sha: data.repository?.pullRequest.viewerLatestReview.commit.oid,
619+
const latestReview = data.repository?.pullRequest.reviews.nodes[0];
620+
return latestReview ? {
621+
sha: latestReview.commit.oid,
619622
} : undefined;
620623
}
621624
catch (e) {

src/github/queriesShared.gql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,14 @@ query IssueTimelineEvents($owner: String!, $name: String!, $number: Int!, $last:
342342
}
343343
}
344344

345-
query LatestReviewCommit($owner: String!, $name: String!, $number: Int!) {
345+
query LatestReviewCommit($owner: String!, $name: String!, $number: Int!, $author: String!) {
346346
repository(owner: $owner, name: $name) {
347347
pullRequest(number: $number) {
348-
viewerLatestReview {
349-
commit {
350-
oid
348+
reviews(last: 1, author: $author, states: [APPROVED, CHANGES_REQUESTED, COMMENTED, DISMISSED]) {
349+
nodes {
350+
commit {
351+
oid
352+
}
351353
}
352354
}
353355
}

src/test/builders/graphql/latestReviewCommitBuilder.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@ import { RateLimitBuilder } from './rateLimitBuilder';
1010

1111
type Repository = NonNullable<LatestReviewCommitResponse['repository']>;
1212
type PullRequest = Repository['pullRequest'];
13-
type ViewerLatestReview = PullRequest['viewerLatestReview'];
14-
type Commit = ViewerLatestReview['commit'];
13+
type Reviews = PullRequest['reviews'];
1514

1615
export const LatestReviewCommitBuilder = createBuilderClass<LatestReviewCommitResponse>()({
1716
repository: createLink<Repository>()({
1817
pullRequest: createLink<PullRequest>()({
19-
viewerLatestReview: createLink<ViewerLatestReview>()({
20-
commit: createLink<Commit>()({
21-
oid: { default: 'abc' },
22-
}),
18+
reviews: createLink<Reviews>()({
19+
nodes: { default: [] },
2320
}),
2421
}),
2522
}),

0 commit comments

Comments
 (0)