-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathrelease.ts
More file actions
64 lines (53 loc) · 1.73 KB
/
release.ts
File metadata and controls
64 lines (53 loc) · 1.73 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
import type { FC } from 'react';
import type { OcticonProps } from '@primer/octicons-react';
import { TagIcon } from '@primer/octicons-react';
import type {
GitifyNotification,
GitifyNotificationState,
GitifyNotificationUser,
GitifySubject,
Link,
SettingsState,
UserType,
} from '../../../types';
import { getRelease } from '../../api/client';
import { isStateFilteredOut } from '../filters/filter';
import { DefaultHandler, defaultHandler } from './default';
import { getNotificationAuthor } from './utils';
class ReleaseHandler extends DefaultHandler {
override async enrich(
notification: GitifyNotification,
_settings: SettingsState,
): Promise<Partial<GitifySubject>> {
const releaseState: GitifyNotificationState = null; // Release notifications are stateless
// Return early if this notification would be hidden by filters
if (isStateFilteredOut(releaseState)) {
return {};
}
const release = await getRelease(
notification.account,
notification.subject.url,
);
const user: GitifyNotificationUser = release.author
? {
login: release.author.login,
avatarUrl: release.author.avatar_url as Link,
htmlUrl: release.author.html_url as Link,
type: release.author.type as UserType,
}
: null;
return {
state: releaseState,
user: getNotificationAuthor([user]),
};
}
override iconType(_notification: GitifyNotification): FC<OcticonProps> {
return TagIcon;
}
override defaultUrl(notification: GitifyNotification): Link {
const url = new URL(defaultHandler.defaultUrl(notification));
url.pathname += '/releases';
return url.href as Link;
}
}
export const releaseHandler = new ReleaseHandler();