Skip to content

Commit 5c4101f

Browse files
authored
refactor: handler overrides (#2720)
* refactor: handler overrides Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor: handler overrides Signed-off-by: Adam Setch <adam.setch@outlook.com> --------- Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent c5402eb commit 5c4101f

16 files changed

+44
-86
lines changed

src/main/updater.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ import { autoUpdater } from 'electron-updater';
6161
describe('main/updater.ts', () => {
6262
let menubar: Menubar;
6363
class TestMenuBuilder extends MenuBuilder {
64-
public setCheckForUpdatesMenuEnabled = vi.fn();
65-
public setNoUpdateAvailableMenuVisibility = vi.fn();
66-
public setUpdateAvailableMenuVisibility = vi.fn();
67-
public setUpdateReadyForInstallMenuVisibility = vi.fn();
64+
public override setCheckForUpdatesMenuEnabled = vi.fn();
65+
public override setNoUpdateAvailableMenuVisibility = vi.fn();
66+
public override setUpdateAvailableMenuVisibility = vi.fn();
67+
public override setUpdateReadyForInstallMenuVisibility = vi.fn();
6868
}
6969

7070
let menuBuilder: TestMenuBuilder;

src/renderer/utils/notifications/handlers/checkSuite.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export interface CheckSuiteAttributes {
3030
}
3131

3232
class CheckSuiteHandler extends DefaultHandler {
33-
readonly type = 'CheckSuite';
34-
35-
async enrich(
33+
override async enrich(
3634
notification: GitifyNotification,
3735
_settings: SettingsState,
3836
): Promise<Partial<GitifySubject>> {
@@ -49,7 +47,7 @@ class CheckSuiteHandler extends DefaultHandler {
4947
return {};
5048
}
5149

52-
iconType(notification: GitifyNotification): FC<OcticonProps> {
50+
override iconType(notification: GitifyNotification): FC<OcticonProps> {
5351
switch (notification.subject.state as GitifyCheckSuiteStatus) {
5452
case 'CANCELLED':
5553
return StopIcon;
@@ -64,7 +62,7 @@ class CheckSuiteHandler extends DefaultHandler {
6462
}
6563
}
6664

67-
iconColor(notification: GitifyNotification): IconColor {
65+
override iconColor(notification: GitifyNotification): IconColor {
6866
switch (notification.subject.state as GitifyCheckSuiteStatus) {
6967
case 'SUCCESS':
7068
return IconColor.GREEN;
@@ -75,7 +73,7 @@ class CheckSuiteHandler extends DefaultHandler {
7573
}
7674
}
7775

78-
defaultUrl(notification: GitifyNotification): Link {
76+
override defaultUrl(notification: GitifyNotification): Link {
7977
return getCheckSuiteUrl(notification);
8078
}
8179
}

src/renderer/utils/notifications/handlers/commit.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import { DefaultHandler } from './default';
1818
import { getNotificationAuthor } from './utils';
1919

2020
class CommitHandler extends DefaultHandler {
21-
readonly type = 'Commit';
22-
23-
async enrich(
21+
override async enrich(
2422
notification: GitifyNotification,
2523
_settings: SettingsState,
2624
): Promise<Partial<GitifySubject>> {
@@ -65,7 +63,7 @@ class CommitHandler extends DefaultHandler {
6563
};
6664
}
6765

68-
iconType(_notification: GitifyNotification): FC<OcticonProps> {
66+
override iconType(_notification: GitifyNotification): FC<OcticonProps> {
6967
return GitCommitIcon;
7068
}
7169
}

src/renderer/utils/notifications/handlers/default.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ import {
99
IconColor,
1010
type Link,
1111
type SettingsState,
12-
type SubjectType,
1312
type UserType,
1413
} from '../../../types';
1514
import type { NotificationTypeHandler } from './types';
1615

1716
export class DefaultHandler implements NotificationTypeHandler {
18-
type?: SubjectType;
19-
20-
supportsMergedQueryEnrichment?: boolean = false;
17+
supportsMergedQueryEnrichment = false;
2118

2219
async enrich(
2320
_notification: GitifyNotification,

src/renderer/utils/notifications/handlers/discussion.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ import { DefaultHandler, defaultHandler } from './default';
2929
import { getNotificationAuthor } from './utils';
3030

3131
class DiscussionHandler extends DefaultHandler {
32-
readonly type = 'Discussion';
32+
override readonly supportsMergedQueryEnrichment = true;
3333

34-
readonly supportsMergedQueryEnrichment = true;
35-
36-
async enrich(
34+
override async enrich(
3735
notification: GitifyNotification,
3836
_settings: SettingsState,
3937
fetchedData?: DiscussionDetailsFragment,
@@ -82,7 +80,7 @@ class DiscussionHandler extends DefaultHandler {
8280
};
8381
}
8482

85-
iconType(notification: GitifyNotification): FC<OcticonProps> {
83+
override iconType(notification: GitifyNotification): FC<OcticonProps> {
8684
switch (notification.subject.state as GitifyDiscussionState) {
8785
case 'DUPLICATE':
8886
return DiscussionDuplicateIcon;
@@ -95,7 +93,7 @@ class DiscussionHandler extends DefaultHandler {
9593
}
9694
}
9795

98-
iconColor(notification: GitifyNotification): IconColor {
96+
override iconColor(notification: GitifyNotification): IconColor {
9997
switch (notification.subject.state) {
10098
case 'ANSWERED':
10199
return IconColor.GREEN;
@@ -106,7 +104,7 @@ class DiscussionHandler extends DefaultHandler {
106104
}
107105
}
108106

109-
defaultUrl(notification: GitifyNotification): Link {
107+
override defaultUrl(notification: GitifyNotification): Link {
110108
const url = new URL(defaultHandler.defaultUrl(notification));
111109
url.pathname += '/discussions';
112110
return url.href as Link;

src/renderer/utils/notifications/handlers/index.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,3 @@ export function createNotificationHandler(
4444
return defaultHandler;
4545
}
4646
}
47-
48-
export const handlers = {
49-
checkSuiteHandler,
50-
commitHandler,
51-
discussionHandler,
52-
issueHandler,
53-
pullRequestHandler,
54-
releaseHandler,
55-
repositoryAdvisoryHandler,
56-
repositoryDependabotAlertsThreadHandler,
57-
repositoryInvitationHandler,
58-
repositoryVulnerabilityAlertHandler,
59-
workflowRunHandler,
60-
defaultHandler,
61-
};

src/renderer/utils/notifications/handlers/issue.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ import { DefaultHandler, defaultHandler } from './default';
2323
import { getNotificationAuthor } from './utils';
2424

2525
class IssueHandler extends DefaultHandler {
26-
readonly type = 'Issue';
26+
override readonly supportsMergedQueryEnrichment = true;
2727

28-
readonly supportsMergedQueryEnrichment = true;
29-
30-
async enrich(
28+
override async enrich(
3129
notification: GitifyNotification,
3230
_settings: SettingsState,
3331
fetchedData?: IssueDetailsFragment,
@@ -66,7 +64,7 @@ class IssueHandler extends DefaultHandler {
6664
};
6765
}
6866

69-
iconType(notification: GitifyNotification): FC<OcticonProps> {
67+
override iconType(notification: GitifyNotification): FC<OcticonProps> {
7068
switch (notification.subject.state as GitifyIssueState) {
7169
case 'CLOSED':
7270
case 'COMPLETED':
@@ -81,7 +79,7 @@ class IssueHandler extends DefaultHandler {
8179
}
8280
}
8381

84-
iconColor(notification: GitifyNotification): IconColor {
82+
override iconColor(notification: GitifyNotification): IconColor {
8583
switch (notification.subject.state as GitifyIssueState) {
8684
case 'OPEN':
8785
case 'REOPENED':
@@ -95,7 +93,7 @@ class IssueHandler extends DefaultHandler {
9593
}
9694
}
9795

98-
defaultUrl(notification: GitifyNotification): Link {
96+
override defaultUrl(notification: GitifyNotification): Link {
9997
const url = new URL(defaultHandler.defaultUrl(notification));
10098
url.pathname += '/issues';
10199
return url.href as Link;

src/renderer/utils/notifications/handlers/pullRequest.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ import { DefaultHandler, defaultHandler } from './default';
2929
import { getNotificationAuthor } from './utils';
3030

3131
class PullRequestHandler extends DefaultHandler {
32-
readonly type = 'PullRequest' as const;
32+
override readonly supportsMergedQueryEnrichment = true;
3333

34-
readonly supportsMergedQueryEnrichment = true;
35-
36-
async enrich(
34+
override async enrich(
3735
notification: GitifyNotification,
3836
_settings: SettingsState,
3937
fetchedData?: PullRequestDetailsFragment,
@@ -80,7 +78,7 @@ class PullRequestHandler extends DefaultHandler {
8078
};
8179
}
8280

83-
iconType(notification: GitifyNotification): FC<OcticonProps> {
81+
override iconType(notification: GitifyNotification): FC<OcticonProps> {
8482
switch (notification.subject.state as GitifyPullRequestState) {
8583
case 'DRAFT':
8684
return GitPullRequestDraftIcon;
@@ -95,7 +93,7 @@ class PullRequestHandler extends DefaultHandler {
9593
}
9694
}
9795

98-
iconColor(notification: GitifyNotification): IconColor {
96+
override iconColor(notification: GitifyNotification): IconColor {
9997
switch (notification.subject.state as GitifyPullRequestState) {
10098
case 'OPEN':
10199
return IconColor.GREEN;
@@ -110,7 +108,7 @@ class PullRequestHandler extends DefaultHandler {
110108
}
111109
}
112110

113-
defaultUrl(notification: GitifyNotification): Link {
111+
override defaultUrl(notification: GitifyNotification): Link {
114112
const url = new URL(defaultHandler.defaultUrl(notification));
115113
url.pathname += '/pulls';
116114
return url.href as Link;

src/renderer/utils/notifications/handlers/release.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ import { DefaultHandler, defaultHandler } from './default';
1919
import { getNotificationAuthor } from './utils';
2020

2121
class ReleaseHandler extends DefaultHandler {
22-
readonly type = 'Release';
23-
24-
async enrich(
22+
override async enrich(
2523
notification: GitifyNotification,
2624
_settings: SettingsState,
2725
): Promise<Partial<GitifySubject>> {
@@ -52,11 +50,11 @@ class ReleaseHandler extends DefaultHandler {
5250
};
5351
}
5452

55-
iconType(_notification: GitifyNotification): FC<OcticonProps> {
53+
override iconType(_notification: GitifyNotification): FC<OcticonProps> {
5654
return TagIcon;
5755
}
5856

59-
defaultUrl(notification: GitifyNotification): Link {
57+
override defaultUrl(notification: GitifyNotification): Link {
6058
const url = new URL(defaultHandler.defaultUrl(notification));
6159
url.pathname += '/releases';
6260
return url.href as Link;

src/renderer/utils/notifications/handlers/repositoryAdvisory.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ import type { GitifyNotification, Link, UserType } from '../../../types';
77
import { DefaultHandler, defaultHandler } from './default';
88

99
class RepositoryAdvisoryHandler extends DefaultHandler {
10-
readonly type = 'RepositoryAdvisory';
11-
12-
iconType(_notification: GitifyNotification): FC<OcticonProps> {
10+
override iconType(_notification: GitifyNotification): FC<OcticonProps> {
1311
return AlertIcon;
1412
}
1513

16-
defaultUrl(notification: GitifyNotification): Link {
14+
override defaultUrl(notification: GitifyNotification): Link {
1715
const url = new URL(defaultHandler.defaultUrl(notification));
1816
url.pathname += '/security/advisories';
1917
return url.href as Link;
2018
}
2119

22-
defaultUserType(): UserType {
20+
override defaultUserType(): UserType {
2321
return 'Bot';
2422
}
2523
}

0 commit comments

Comments
 (0)