Skip to content

Commit 108970e

Browse files
authored
Fix changing reviewers when one of the reviewers is a bot (#6628)
* Fix changing reviewers when one of the reviewers is a bot Fixes #6443 * Fixe tests
1 parent 2afc684 commit 108970e

19 files changed

+370
-440
lines changed

src/common/timelineEvent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export interface ReviewResolveInfo {
4747
isResolved: boolean;
4848
}
4949

50+
export type ReviewStateValue = 'COMMENTED' | 'APPROVED' | 'CHANGES_REQUESTED' | 'PENDING' | 'REQUESTED';
51+
5052
export interface ReviewEvent {
5153
id: number;
5254
reviewThread?: ReviewResolveInfo
@@ -58,7 +60,7 @@ export interface ReviewEvent {
5860
htmlUrl: string;
5961
user: IAccount;
6062
authorAssociation: string;
61-
state?: 'COMMENTED' | 'APPROVED' | 'CHANGES_REQUESTED' | 'PENDING' | 'REQUESTED';
63+
state?: ReviewStateValue;
6264
}
6365

6466
export interface CommitEvent {

src/github/activityBarViewProvider.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { formatError } from '../common/utils';
1212
import { getNonce, IRequestMessage, WebviewViewBase } from '../common/webview';
1313
import { ReviewManager } from '../view/reviewManager';
1414
import { FolderRepositoryManager } from './folderRepositoryManager';
15-
import { GithubItemStateEnum, IAccount, isTeam, PullRequestMergeability, reviewerId, ReviewEvent, ReviewState } from './interface';
15+
import { GithubItemStateEnum, IAccount, isTeam, ITeam, PullRequestMergeability, reviewerId, ReviewEvent, ReviewState } from './interface';
1616
import { PullRequestModel } from './pullRequestModel';
1717
import { getDefaultMergeMethod } from './pullRequestOverview';
1818
import { PullRequestView } from './pullRequestOverviewCommon';
@@ -153,12 +153,12 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
153153

154154
private reRequestReview(message: IRequestMessage<string>): void {
155155
let targetReviewer: ReviewState | undefined;
156-
const userReviewers: string[] = [];
157-
const teamReviewers: string[] = [];
156+
const userReviewers: IAccount[] = [];
157+
const teamReviewers: ITeam[] = [];
158158

159159
for (const reviewer of this._existingReviewers) {
160160
let id: string | undefined;
161-
let reviewerArray: string[] | undefined;
161+
let reviewerArray: (IAccount | ITeam)[] | undefined;
162162
if (reviewer && isTeam(reviewer.reviewer)) {
163163
id = reviewer.reviewer.id;
164164
reviewerArray = teamReviewers;
@@ -167,7 +167,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
167167
reviewerArray = userReviewers;
168168
}
169169
if (reviewerArray && id && ((reviewer.state === 'REQUESTED') || (id === message.args))) {
170-
reviewerArray.push(id);
170+
reviewerArray.push(reviewer.reviewer);
171171
if (id === message.args) {
172172
targetReviewer = reviewer;
173173
}
@@ -288,7 +288,8 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
288288
avatarUrl: pullRequest.userAvatar,
289289
url: pullRequest.author.url,
290290
email: pullRequest.author.email,
291-
id: pullRequest.author.id
291+
id: pullRequest.author.id,
292+
accountType: pullRequest.author.accountType,
292293
},
293294
state: pullRequest.state,
294295
isCurrentlyCheckedOut: isCurrentlyCheckedOut,

src/github/createPRViewProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,13 @@ export abstract class BaseCreatePullRequestViewProvider<T extends BasePullReques
306306

307307
private async setReviewers(pr: PullRequestModel, reviewers: (IAccount | ITeam)[]): Promise<void> {
308308
if (reviewers.length) {
309-
const users: string[] = [];
310-
const teams: string[] = [];
309+
const users: IAccount[] = [];
310+
const teams: ITeam[] = [];
311311
for (const reviewer of reviewers) {
312312
if (isTeam(reviewer)) {
313-
teams.push(reviewer.id);
313+
teams.push(reviewer);
314314
} else {
315-
users.push(reviewer.id);
315+
users.push(reviewer);
316316
}
317317
}
318318
await pr.requestReview(users, teams);

src/github/githubRepository.ts

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
getAvatarWithEnterpriseFallback,
6565
getOverrideBranch,
6666
isInCodespaces,
67+
parseAccount,
6768
parseGraphQLIssue,
6869
parseGraphQLPullRequest,
6970
parseGraphQLViewerPermission,
@@ -1177,14 +1178,7 @@ export class GitHubRepository extends Disposable {
11771178

11781179
ret.push(
11791180
...result.data.repository.mentionableUsers.nodes.map(node => {
1180-
return {
1181-
login: node.login,
1182-
avatarUrl: getAvatarWithEnterpriseFallback(node.avatarUrl, undefined, this.remote.isEnterprise),
1183-
name: node.name,
1184-
url: node.url,
1185-
email: node.email,
1186-
id: node.id
1187-
};
1181+
return parseAccount(node, this);
11881182
}),
11891183
);
11901184

@@ -1226,14 +1220,7 @@ export class GitHubRepository extends Disposable {
12261220

12271221
ret.push(
12281222
...result.data.repository.assignableUsers.nodes.map(node => {
1229-
return {
1230-
login: node.login,
1231-
avatarUrl: getAvatarWithEnterpriseFallback(node.avatarUrl, undefined, this.remote.isEnterprise),
1232-
name: node.name,
1233-
url: node.url,
1234-
email: node.email,
1235-
id: node.id
1236-
};
1223+
return parseAccount(node, this);
12371224
}),
12381225
);
12391226

@@ -1370,14 +1357,7 @@ export class GitHubRepository extends Disposable {
13701357

13711358
ret.push(
13721359
...result.data.repository.pullRequest.participants.nodes.map(node => {
1373-
return {
1374-
login: node.login,
1375-
avatarUrl: getAvatarWithEnterpriseFallback(node.avatarUrl, undefined, this.remote.isEnterprise),
1376-
name: node.name,
1377-
url: node.url,
1378-
email: node.email,
1379-
id: node.id
1380-
};
1360+
return parseAccount(node, this);
13811361
}),
13821362
);
13831363
} catch (e) {

src/github/graphql.ts

Lines changed: 30 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ interface PageInfo {
1414
export interface MergedEvent {
1515
__typename: string;
1616
id: string;
17-
actor: {
18-
login: string;
19-
avatarUrl: string;
20-
url: string;
21-
};
17+
actor: Actor;
2218
createdAt: string;
2319
mergeRef: {
2420
name: string;
@@ -33,23 +29,13 @@ export interface MergedEvent {
3329
export interface HeadRefDeletedEvent {
3430
__typename: string;
3531
id: string;
36-
actor: {
37-
login: string;
38-
avatarUrl: string;
39-
url: string;
40-
};
32+
actor: Actor;
4133
createdAt: string;
4234
headRefName: string;
4335
}
4436

4537
export interface AbbreviatedIssueComment {
46-
author: {
47-
login: string;
48-
avatarUrl: string;
49-
url: string;
50-
email?: string;
51-
id: string;
52-
};
38+
author: Account;
5339
body: string;
5440
databaseId: number;
5541
reactions: {
@@ -82,16 +68,28 @@ export interface ReactionGroup {
8268
};
8369
}
8470

85-
export interface Account {
71+
export interface Actor {
72+
__typename: string;
73+
id: string;
8674
login: string;
8775
avatarUrl: string;
88-
name: string;
8976
url: string;
77+
}
78+
79+
export interface Account extends Actor {
80+
name: string;
9081
email: string;
91-
id: string;
9282
}
9383

94-
interface Team {
84+
export function isAccount(x: Actor | Team | undefined | null): x is Account {
85+
return !!x && 'name' in x && 'email' in x;
86+
}
87+
88+
export function isTeam(x: Actor | Team | undefined | null): x is Team {
89+
return !!x && 'slug' in x;
90+
}
91+
92+
export interface Team {
9593
avatarUrl: string;
9694
name: string;
9795
url: string;
@@ -109,13 +107,7 @@ export interface ReviewComment {
109107
id: string;
110108
databaseId: number;
111109
url: string;
112-
author?: {
113-
login: string;
114-
avatarUrl: string;
115-
url: string;
116-
id: string;
117-
name?: string;
118-
};
110+
author?: Actor | Account;
119111
path: string;
120112
originalPosition: number;
121113
body: string;
@@ -146,12 +138,7 @@ export interface Commit {
146138
id: string;
147139
commit: {
148140
author: {
149-
user: {
150-
login: string;
151-
avatarUrl: string;
152-
url: string;
153-
id: string;
154-
};
141+
user: Account;
155142
};
156143
committer: {
157144
avatarUrl: string;
@@ -168,21 +155,12 @@ export interface Commit {
168155
export interface AssignedEvent {
169156
__typename: string;
170157
id: number;
171-
actor: {
172-
login: string;
173-
avatarUrl: string;
174-
url: string;
175-
};
176-
user: {
177-
login: string;
178-
avatarUrl: string;
179-
url: string;
180-
id: string;
181-
};
158+
actor: Actor;
159+
user: Account;
182160
}
183161

184162
export interface MergeQueueEntry {
185-
position: number,
163+
position: number;
186164
state: MergeQueueState;
187165
mergeQueue: {
188166
url: string;
@@ -195,12 +173,7 @@ export interface Review {
195173
databaseId: number;
196174
authorAssociation: string;
197175
url: string;
198-
author: {
199-
login: string;
200-
avatarUrl: string;
201-
url: string;
202-
id: string;
203-
};
176+
author: Actor | Account;
204177
state: 'COMMENTED' | 'APPROVED' | 'CHANGES_REQUESTED' | 'PENDING';
205178
body: string;
206179
bodyHTML?: string;
@@ -271,18 +244,7 @@ export interface GetReviewRequestsResponse {
271244
pullRequest: {
272245
reviewRequests: {
273246
nodes: {
274-
requestedReviewer: {
275-
// Shared properties between accounts and teams
276-
avatarUrl: string;
277-
url: string;
278-
name: string;
279-
// Account properties
280-
login?: string;
281-
email?: string;
282-
// Team properties
283-
slug?: string;
284-
id: string;
285-
} | null;
247+
requestedReviewer: Actor | Account | Team | null;
286248
}[];
287249
};
288250
};
@@ -554,13 +516,7 @@ export interface Ref {
554516
export interface SuggestedReviewerResponse {
555517
isAuthor: boolean;
556518
isCommenter: boolean;
557-
reviewer: {
558-
login: string;
559-
avatarUrl: string;
560-
name: string;
561-
url: string;
562-
id: string;
563-
};
519+
reviewer: Actor | Account;
564520
}
565521

566522
export type MergeMethod = 'MERGE' | 'REBASE' | 'SQUASH';
@@ -577,20 +533,9 @@ export interface PullRequest {
577533
title: string;
578534
titleHTML: string;
579535
assignees?: {
580-
nodes: {
581-
login: string;
582-
url: string;
583-
email: string;
584-
avatarUrl: string;
585-
id: string;
586-
}[];
587-
};
588-
author: {
589-
login: string;
590-
url: string;
591-
avatarUrl: string;
592-
id: string;
536+
nodes: Account[];
593537
};
538+
author: Account;
594539
commits: {
595540
nodes: {
596541
commit: {
@@ -827,6 +772,7 @@ export interface UserResponse {
827772
contributionsCollection: ContributionsCollection;
828773
url: string;
829774
id: string;
775+
__typename: string;
830776
};
831777
}
832778

src/github/interface.ts

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

6+
import { ReviewStateValue } from '../common/timelineEvent';
7+
68
export enum PRType {
79
Query,
810
All,
@@ -39,7 +41,7 @@ export enum MergeQueueState {
3941

4042
export interface ReviewState {
4143
reviewer: IAccount | ITeam;
42-
state: string;
44+
state: ReviewStateValue;
4345
}
4446

4547
export interface ReadyForReview {
@@ -54,14 +56,35 @@ export interface IActor {
5456
url: string;
5557
}
5658

59+
export enum AccountType {
60+
User = 'User',
61+
Organization = 'Organization',
62+
Mannequin = 'Mannequin',
63+
Bot = 'Bot'
64+
}
65+
66+
export function toAccountType(type: string): AccountType {
67+
switch (type) {
68+
case 'Organization':
69+
return AccountType.Organization;
70+
case 'Mannequin':
71+
return AccountType.Mannequin;
72+
case 'Bot':
73+
return AccountType.Bot;
74+
default:
75+
return AccountType.User;
76+
}
77+
}
78+
5779
export interface IAccount extends IActor {
5880
login: string;
5981
id: string;
6082
name?: string;
6183
avatarUrl?: string;
6284
url: string;
6385
email?: string;
64-
specialDisplayName?: string
86+
specialDisplayName?: string;
87+
accountType: AccountType;
6588
}
6689

6790
export interface ITeam {

0 commit comments

Comments
 (0)