-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathcommit.ts
More file actions
71 lines (59 loc) · 1.97 KB
/
commit.ts
File metadata and controls
71 lines (59 loc) · 1.97 KB
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
import type { FC } from 'react';
import type { OcticonProps } from '@primer/octicons-react';
import { GitCommitIcon } from '@primer/octicons-react';
import type {
GitifyNotification,
GitifyNotificationState,
GitifyNotificationUser,
GitifySubject,
Link,
SettingsState,
} from '../../../types';
import { getCommit, getCommitComment } from '../../api/client';
import { isStateFilteredOut } from '../filters/filter';
import { DefaultHandler } from './default';
import { getNotificationAuthor } from './utils';
class CommitHandler extends DefaultHandler {
override async enrich(
notification: GitifyNotification,
_settings: SettingsState,
): Promise<Partial<GitifySubject>> {
const commitState: GitifyNotificationState = null; // Commit notifications are stateless
// Return early if this notification would be hidden by filters
if (isStateFilteredOut(commitState)) {
return {};
}
let user: GitifyNotificationUser;
if (notification.subject.latestCommentUrl) {
const commitComment = await getCommitComment(
notification.account,
notification.subject.latestCommentUrl,
);
user = {
login: commitComment.user.login,
avatarUrl: commitComment.user.avatar_url as Link,
htmlUrl: commitComment.user.html_url as Link,
type: commitComment.user.type as GitifyNotificationUser['type'],
};
} else {
const commit = await getCommit(
notification.account,
notification.subject.url,
);
user = {
login: commit.author.login,
avatarUrl: commit.author.avatar_url as Link,
htmlUrl: commit.author.html_url as Link,
type: commit.author.type as GitifyNotificationUser['type'],
};
}
return {
state: commitState,
user: getNotificationAuthor([user]),
};
}
override iconType(_notification: GitifyNotification): FC<OcticonProps> {
return GitCommitIcon;
}
}
export const commitHandler = new CommitHandler();