Skip to content

Commit b711052

Browse files
authored
Get reactions on issue/pr body (#6910)
* Get reactions on issue/pr body Fixes #6908 * Move Reactions, fix test * Fix test
1 parent edefce1 commit b711052

File tree

11 files changed

+84
-20
lines changed

11 files changed

+84
-20
lines changed

src/common/comment.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import { IAccount } from '../github/interface';
7+
import { IAccount, Reaction } from '../github/interface';
88
import { COPILOT_LOGINS } from './copilot';
99
import { DiffHunk } from './diffHunk';
1010

@@ -19,14 +19,6 @@ export enum ViewedState {
1919
UNVIEWED = 'UNVIEWED'
2020
}
2121

22-
export interface Reaction {
23-
label: string;
24-
count: number;
25-
icon?: vscode.Uri;
26-
viewerHasReacted: boolean;
27-
reactors: readonly string[];
28-
}
29-
3022
export enum SubjectType {
3123
LINE = 'LINE',
3224
FILE = 'FILE'

src/github/graphql.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ export interface Issue {
599599
reactions: {
600600
totalCount: number;
601601
}
602+
reactionGroups: ReactionGroup[];
602603
}
603604

604605

src/github/interface.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import * as vscode from 'vscode';
67
import { ReviewStateValue } from '../common/timelineEvent';
78

89
export enum PRType {
@@ -179,6 +180,14 @@ export interface IIssueComment {
179180
createdAt: string;
180181
}
181182

183+
export interface Reaction {
184+
label: string;
185+
count: number;
186+
icon?: vscode.Uri;
187+
viewerHasReacted: boolean;
188+
reactors: readonly string[];
189+
}
190+
182191
export interface Issue {
183192
id: number;
184193
graphNodeId: string;
@@ -202,6 +211,7 @@ export interface Issue {
202211
comments?: IIssueComment[];
203212
commentCount: number;
204213
reactionCount: number;
214+
reactions: Reaction[];
205215
}
206216

207217
export interface PullRequest extends Issue {

src/github/issueOverview.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
175175
assignees: issue.assignees ?? [],
176176
isEnterprise: issue.githubRepository.remote.isEnterprise,
177177
isDarkTheme: vscode.window.activeColorTheme.kind === vscode.ColorThemeKind.Dark,
178-
canAssignCopilot: assignableUsers.find(user => COPILOT_ACCOUNTS[user.login]) !== undefined
178+
canAssignCopilot: assignableUsers.find(user => COPILOT_ACCOUNTS[user.login]) !== undefined,
179+
reactions: issue.item.reactions
179180
};
180181

181182
return context;

src/github/queries.gql

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ fragment Team on Team { # Team is not an Actor
4242
...Node
4343
}
4444

45+
fragment Reactable on Reactable {
46+
reactionGroups {
47+
content
48+
viewerHasReacted
49+
reactors(first: 10) {
50+
nodes {
51+
... on User {
52+
login
53+
}
54+
... on Actor {
55+
login
56+
}
57+
}
58+
totalCount
59+
}
60+
}
61+
}
62+
4563
fragment IssueBase on Issue {
4664
number
4765
url
@@ -83,6 +101,7 @@ fragment IssueBase on Issue {
83101
reactions(first: 100) {
84102
totalCount
85103
}
104+
...Reactable
86105
repository {
87106
name
88107
owner {
@@ -160,7 +179,7 @@ fragment PullRequestFragment on PullRequest {
160179
reactions(first: 100) {
161180
totalCount
162181
}
163-
182+
...Reactable
164183
comments(first: 1) {
165184
totalCount
166185
}

src/github/queriesExtra.gql

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ fragment Team on Team { # Team is not an Actor
4242
...Node
4343
}
4444

45+
fragment Reactable on Reactable {
46+
reactionGroups {
47+
content
48+
viewerHasReacted
49+
reactors(first: 10) {
50+
nodes {
51+
... on User {
52+
login
53+
}
54+
... on Actor {
55+
login
56+
}
57+
}
58+
totalCount
59+
}
60+
}
61+
}
4562

4663
fragment IssueBase on Issue {
4764
number
@@ -84,6 +101,7 @@ fragment IssueBase on Issue {
84101
reactions(first: 100) {
85102
totalCount
86103
}
104+
...Reactable
87105
repository {
88106
name
89107
owner {
@@ -170,6 +188,7 @@ fragment PullRequestFragment on PullRequest {
170188
reactions(first: 100) {
171189
totalCount
172190
}
191+
...Reactable
173192
projectItems(first: 100) {
174193
nodes {
175194
id
@@ -179,15 +198,9 @@ fragment PullRequestFragment on PullRequest {
179198
}
180199
}
181200
}
182-
183-
comments(first: 1) {
184-
totalCount
185-
}
186-
187201
comments(first: 1) {
188202
totalCount
189203
}
190-
191204
commits(first: 50) {
192205
nodes {
193206
commit {

src/github/queriesLimited.gql

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ fragment Organization on Organization {
3232
...Node
3333
}
3434

35+
fragment Reactable on Reactable {
36+
reactionGroups {
37+
content
38+
viewerHasReacted
39+
reactors(first: 10) {
40+
nodes {
41+
... on User {
42+
login
43+
}
44+
... on Actor {
45+
login
46+
}
47+
}
48+
totalCount
49+
}
50+
}
51+
}
52+
3553
fragment IssueBase on Issue {
3654
number
3755
url
@@ -73,6 +91,7 @@ fragment IssueBase on Issue {
7391
reactions(first: 100) {
7492
totalCount
7593
}
94+
...Reactable
7695
repository {
7796
name
7897
owner {
@@ -150,7 +169,7 @@ fragment PullRequestFragment on PullRequest {
150169
reactions(first: 100) {
151170
totalCount
152171
}
153-
172+
...Reactable
154173
comments(first: 1) {
155174
totalCount
156175
}

src/github/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as vscode from 'vscode';
1010
import { Repository } from '../api/api';
1111
import { GitApiImpl } from '../api/api1';
1212
import { AuthProvider, GitHubServerType } from '../common/authentication';
13-
import { COPILOT_ACCOUNTS, IComment, IReviewThread, Reaction, SubjectType } from '../common/comment';
13+
import { COPILOT_ACCOUNTS, IComment, IReviewThread, SubjectType } from '../common/comment';
1414
import { DiffHunk, parseDiffHunk } from '../common/diffHunk';
1515
import { GitHubRef } from '../common/githubRef';
1616
import Logger from '../common/logger';
@@ -43,6 +43,7 @@ import {
4343
NotificationSubjectType,
4444
PullRequest,
4545
PullRequestMergeability,
46+
Reaction,
4647
reviewerId,
4748
reviewerLabel,
4849
ReviewState,
@@ -355,6 +356,7 @@ export function convertRESTPullRequestToRawPullRequest(
355356
projectItems: [], // projects only available through GraphQL API
356357
commits: [], // commits only available through GraphQL API
357358
reactionCount: 0, // reaction count only available through GraphQL API
359+
reactions: [], // reactions only available through GraphQL API
358360
commentCount: 0 // comment count only available through GraphQL API
359361
};
360362

@@ -408,6 +410,7 @@ export function convertRESTIssueToRawPullRequest(
408410
),
409411
projectItems: [], // projects only available through GraphQL API
410412
reactionCount: 0, // reaction count only available through GraphQL API
413+
reactions: [], // reactions only available through GraphQL API
411414
commentCount: comments
412415
};
413416

@@ -786,6 +789,7 @@ export function parseGraphQLPullRequest(
786789
assignees: graphQLPullRequest.assignees?.nodes.map(assignee => parseAccount(assignee, githubRepository)),
787790
commits: parseCommits(graphQLPullRequest.commits.nodes),
788791
reactionCount: graphQLPullRequest.reactions.totalCount,
792+
reactions: parseGraphQLReaction(graphQLPullRequest.reactionGroups),
789793
commentCount: graphQLPullRequest.comments.totalCount,
790794
};
791795
pr.mergeCommitMeta = parseCommitMeta(graphQLPullRequest.baseRepository.mergeCommitTitle, graphQLPullRequest.baseRepository.mergeCommitMessage, pr);
@@ -897,6 +901,7 @@ export function parseGraphQLIssue(issue: GraphQL.Issue, githubRepository: GitHub
897901
projectItems: parseProjectItems(issue.projectItems?.nodes),
898902
comments: issue.comments.nodes?.map(comment => parseIssueComment(comment, githubRepository)),
899903
reactionCount: issue.reactions.totalCount,
904+
reactions: parseGraphQLReaction(issue.reactionGroups),
900905
commentCount: issue.comments.totalCount
901906
};
902907
}

src/github/views.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
PullRequestChecks,
1717
PullRequestMergeability,
1818
PullRequestReviewRequirement,
19+
Reaction,
1920
ReviewState,
2021
} from './interface';
2122

@@ -57,6 +58,7 @@ export interface Issue {
5758
isDarkTheme: boolean;
5859
isEnterprise: boolean;
5960
canAssignCopilot: boolean;
61+
reactions: Reaction[];
6062
busy?: boolean;
6163
}
6264

src/test/builders/graphql/pullRequestBuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ export const PullRequestBuilder = createBuilderClass<PullRequestResponse>()({
110110
}
111111
}),
112112
reactions: { default: { totalCount: 0 } },
113-
comments: { default: { totalCount: 0 } }
113+
comments: { default: { totalCount: 0 } },
114+
reactionGroups: { default: [] },
114115
})
115116
}),
116117
rateLimit: { linked: RateLimitBuilder },

0 commit comments

Comments
 (0)