Skip to content

Commit 454c7da

Browse files
authored
feat: add pr review icons (approved, requested changes, commented, dismissed) (#1078)
* feat: add icon for previously approved prs * feat: add pr review icons (approved, requested changes, commented, dismissed) * feat: add pr review icons (approved, requested changes, commented, dismissed) * fix tests * update coverage * feat: move icon to notification row footer. include all reviewers * feat: move icon to notification row footer. include all reviewers * feat: move icon to notification row footer. include all reviewers * feat: move icon to notification row footer. include all reviewers * update commented icon color to green. ensure ordering is consistent * update commented icon color to yellow. ensure ordering is consistent * refactor: alphabetic order for icon color enum * revert token * revert partial mock
1 parent 88fdfd9 commit 454c7da

12 files changed

+555
-5
lines changed

src/__mocks__/mockedData.ts

+17
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ export const mockedGitHubNotifications: Notification[] = [
7272
'https://avatars.githubusercontent.com/u/133795385?s=200&v=4',
7373
type: 'User',
7474
},
75+
reviews: [
76+
{
77+
state: 'APPROVED',
78+
users: ['octocat'],
79+
},
80+
{
81+
state: 'CHANGES_REQUESTED',
82+
users: ['gitify-app'],
83+
},
84+
{
85+
state: 'PENDING',
86+
users: ['gitify-user'],
87+
},
88+
],
7589
},
7690
repository: {
7791
id: 57216596,
@@ -198,6 +212,7 @@ export const mockedGitHubNotifications: Notification[] = [
198212
latest_comment_url:
199213
'https://api.github.com/repos/gitify-app/notifications-test/issues/comments/302885965',
200214
type: 'Issue',
215+
reviews: null,
201216
},
202217
repository: {
203218
id: 57216596,
@@ -255,6 +270,7 @@ export const mockedEnterpriseNotifications: Notification[] = [
255270
latest_comment_url:
256271
'https://github.gitify.io/api/v3/repos/myorg/notifications-test/releases/3',
257272
type: 'Release',
273+
reviews: null,
258274
},
259275
repository: {
260276
id: 1,
@@ -308,6 +324,7 @@ export const mockedEnterpriseNotifications: Notification[] = [
308324
latest_comment_url:
309325
'https://github.gitify.io/api/v3/repos/myorg/notifications-test/issues/comments/21',
310326
type: 'PullRequest',
327+
reviews: null,
311328
},
312329
repository: {
313330
id: 1,

src/components/NotificationRow.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ describe('components/NotificationRow.tsx', () => {
207207
avatar_url: 'https://avatars.githubusercontent.com/u/123456789?v=4',
208208
type: 'User' as UserType,
209209
},
210+
reviews: null,
210211
},
211212
},
212213
hostname: 'github.com',

src/components/NotificationRow.tsx

+25-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { formatForDisplay, openInBrowser } from '../utils/helpers';
2020
import {
2121
getNotificationTypeIcon,
2222
getNotificationTypeIconColor,
23+
getPullRequestReviewIcon,
2324
} from '../utils/icons';
2425
import { formatReason } from '../utils/reason';
2526

@@ -69,13 +70,14 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
6970
const reason = formatReason(notification.reason);
7071
const NotificationIcon = getNotificationTypeIcon(notification.subject);
7172
const iconColor = getNotificationTypeIconColor(notification.subject);
73+
7274
const updatedAt = formatDistanceToNow(parseISO(notification.updated_at), {
7375
addSuffix: true,
7476
});
75-
7677
const updatedLabel = notification.subject.user
7778
? `${notification.subject.user.login} updated ${updatedAt}`
7879
: `Updated ${updatedAt}`;
80+
7981
const notificationTitle = formatForDisplay([
8082
notification.subject.state,
8183
notification.subject.type,
@@ -131,6 +133,28 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
131133
{reason.title}
132134
</span>
133135
<span className="ml-1">{updatedAt}</span>
136+
{notification.subject.reviews
137+
? notification.subject.reviews.map((review) => {
138+
const icon = getPullRequestReviewIcon(review);
139+
if (!icon) {
140+
return null;
141+
}
142+
143+
return (
144+
<span
145+
key={review.state}
146+
title={icon.description}
147+
className="ml-1"
148+
>
149+
<icon.type
150+
size={16}
151+
className={icon.color}
152+
aria-label={icon.description}
153+
/>
154+
</span>
155+
);
156+
})
157+
: null}
134158
</span>
135159
</span>
136160
</div>

src/components/__snapshots__/NotificationRow.test.tsx.snap

+108
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/routes/__snapshots__/Notifications.test.tsx.snap

+44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/types.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { OcticonProps } from '@primer/octicons-react';
2+
import type { FC } from 'react';
13
import type { Notification } from './typesGitHub';
24

35
export interface AuthState {
@@ -101,4 +103,11 @@ export enum IconColor {
101103
GREEN = 'text-green-500',
102104
PURPLE = 'text-purple-500',
103105
RED = 'text-red-500',
106+
YELLOW = 'text-yellow-500 dark:text-yellow-300',
104107
}
108+
109+
export type PullRequestApprovalIcon = {
110+
type: FC<OcticonProps>;
111+
color: IconColor;
112+
description: string;
113+
};

src/typesGitHub.ts

+36
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ export type CheckSuiteStatus =
7676
| 'timed_out'
7777
| 'waiting';
7878

79+
export type PullRequestReviewState =
80+
| 'APPROVED'
81+
| 'CHANGES_REQUESTED'
82+
| 'COMMENTED'
83+
| 'DISMISSED'
84+
| 'PENDING';
85+
86+
export type PullRequestReviewAuthorAssociation =
87+
| 'COLLABORATOR'
88+
| 'CONTRIBUTOR'
89+
| 'FIRST_TIMER'
90+
| 'FIRST_TIME_CONTRIBUTOR'
91+
| 'MANNEQUIN'
92+
| 'MEMBER'
93+
| 'NONE'
94+
| 'OWNER';
95+
7996
export interface Notification {
8097
id: string;
8198
unread: boolean;
@@ -241,6 +258,7 @@ interface GitHubSubject {
241258
export interface GitifySubject {
242259
state?: StateType;
243260
user?: SubjectUser;
261+
reviews?: GitifyPullRequestReview[];
244262
}
245263

246264
export interface PullRequest {
@@ -281,6 +299,24 @@ export interface PullRequest {
281299
changed_files: number;
282300
}
283301

302+
export interface GitifyPullRequestReview {
303+
state: PullRequestReviewState;
304+
users: string[];
305+
}
306+
307+
export interface PullRequestReview {
308+
id: number;
309+
node_id: string;
310+
user: User;
311+
body: string;
312+
state: PullRequestReviewState;
313+
html_url: string;
314+
pull_request_url: string;
315+
author_association: PullRequestReviewAuthorAssociation;
316+
submitted_at: string;
317+
commit_id: string;
318+
}
319+
284320
export interface Commit {
285321
sha: string;
286322
node_id: string;

0 commit comments

Comments
 (0)