forked from gitify-app/gitify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-api.ts
137 lines (133 loc) · 4.27 KB
/
github-api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import {
AlertIcon,
CommentDiscussionIcon,
GitCommitIcon,
GitMergeIcon,
GitPullRequestClosedIcon,
GitPullRequestDraftIcon,
GitPullRequestIcon,
IssueClosedIcon,
IssueDraftIcon,
IssueOpenedIcon,
IssueReopenedIcon,
MailIcon,
OcticonProps,
QuestionIcon,
SyncIcon,
TagIcon,
} from '@primer/octicons-react';
import { Reason, StateType, SubjectType } from '../typesGithub';
// prettier-ignore
const DESCRIPTIONS = {
ASSIGN: 'You were assigned to the issue.',
AUTHOR: 'You created the thread.',
COMMENT: 'You commented on the thread.',
INVITATION: 'You accepted an invitation to contribute to the repository.',
MANUAL: 'You subscribed to the thread (via an issue or pull request).',
MENTION: 'You were specifically @mentioned in the content.',
REVIEW_REQUESTED: "You, or a team you're a member of, were requested to review a pull request.",
SECURITY_ALERT: 'GitHub discovered a security vulnerability in your repository.',
STATE_CHANGE: 'You changed the thread state (for example, closing an issue or merging a pull request).',
SUBSCRIBED: "You're watching the repository.",
TEAM_MENTION: 'You were on a team that was mentioned.',
CI_ACTIVITY: 'A GitHub Actions workflow run was triggered for your repository',
UNKNOWN: 'The reason for this notification is not supported by the app.',
};
export function formatReason(reason: Reason): {
type: string;
description: string;
} {
// prettier-ignore
switch (reason) {
case 'assign':
return { type: 'Assign', description: DESCRIPTIONS['ASSIGN'] };
case 'author':
return { type: 'Author', description: DESCRIPTIONS['AUTHOR'] };
case 'comment':
return { type: 'Comment', description: DESCRIPTIONS['COMMENT'] };
case 'invitation':
return { type: 'Invitation', description: DESCRIPTIONS['INVITATION'] };
case 'manual':
return { type: 'Manual', description: DESCRIPTIONS['MANUAL'] };
case 'mention':
return { type: 'Mention', description: DESCRIPTIONS['MENTION'] };
case 'review_requested':
return { type: 'Review Requested', description: DESCRIPTIONS['REVIEW_REQUESTED'] };
case 'security_alert':
return { type: 'Security Alert', description: DESCRIPTIONS['SECURITY_ALERT'] };
case 'state_change':
return { type: 'State Change', description: DESCRIPTIONS['STATE_CHANGE'] };
case 'subscribed':
return { type: 'Subscribed', description: DESCRIPTIONS['SUBSCRIBED'] };
case 'team_mention':
return { type: 'Team Mention', description: DESCRIPTIONS['TEAM_MENTION'] };
case 'ci_activity':
return { type: 'Workflow Run', description: DESCRIPTIONS['CI_ACTIVITY'] };
default:
return { type: 'Unknown', description: DESCRIPTIONS['UNKNOWN'] };
}
}
export function getNotificationTypeIcon(
type: SubjectType,
state?: StateType,
): React.FC<OcticonProps> {
switch (type) {
case 'CheckSuite':
return SyncIcon;
case 'Commit':
return GitCommitIcon;
case 'Discussion':
return CommentDiscussionIcon;
case 'Issue':
switch (state) {
case 'draft':
return IssueDraftIcon;
case 'closed':
case 'completed':
return IssueClosedIcon;
case 'reopened':
return IssueReopenedIcon;
default:
return IssueOpenedIcon;
}
case 'PullRequest':
switch (state) {
case 'draft':
return GitPullRequestDraftIcon;
case 'closed':
return GitPullRequestClosedIcon;
case 'merged':
return GitMergeIcon;
default:
return GitPullRequestIcon;
}
case 'Release':
return TagIcon;
case 'RepositoryInvitation':
return MailIcon;
case 'RepositoryVulnerabilityAlert':
return AlertIcon;
default:
return QuestionIcon;
}
}
export function getNotificationTypeIconColor(state: StateType): string {
switch (state) {
case 'closed':
return 'text-red-500';
case 'open':
return 'text-green-500';
case 'merged':
return 'text-purple-500';
case 'reopened':
return 'text-green-500';
case 'not_planned':
return 'text-gray-300';
case 'completed':
return 'text-purple-500';
case 'draft':
return 'text-gray-600';
default:
return 'text-gray-300';
}
}