Skip to content

Commit 1371c08

Browse files
committed
feat(filter): avoid further enrichment if state not visible
Signed-off-by: Adam Setch <[email protected]>
1 parent 0ee2c24 commit 1371c08

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

src/renderer/utils/subject.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,22 @@ describe('renderer/utils/subject.ts', () => {
239239
},
240240
});
241241
});
242+
243+
it('return early if commit state filtered', async () => {
244+
const mockNotification = partialMockNotification({
245+
title: 'This is a commit with comments',
246+
type: 'Commit',
247+
url: 'https://api.github.com/repos/gitify-app/notifications-test/commits/d2a86d80e3d24ea9510d5de6c147e53c30f313a8' as Link,
248+
latest_comment_url: null,
249+
});
250+
251+
const result = await getGitifySubjectDetails(mockNotification, {
252+
...mockSettings,
253+
filterStates: ['closed'],
254+
});
255+
256+
expect(result).toEqual(null);
257+
});
242258
});
243259

244260
describe('Discussions', () => {
@@ -1270,6 +1286,23 @@ describe('renderer/utils/subject.ts', () => {
12701286
},
12711287
});
12721288
});
1289+
1290+
it('return early if release state filtered', async () => {
1291+
const mockNotification = partialMockNotification({
1292+
title: 'This is a mock release',
1293+
type: 'Release',
1294+
url: 'https://api.github.com/repos/gitify-app/notifications-test/releases/1' as Link,
1295+
latest_comment_url:
1296+
'https://api.github.com/repos/gitify-app/notifications-test/releases/1' as Link,
1297+
});
1298+
1299+
const result = await getGitifySubjectDetails(mockNotification, {
1300+
...mockSettings,
1301+
filterStates: ['closed'],
1302+
});
1303+
1304+
expect(result).toEqual(null);
1305+
});
12731306
});
12741307

12751308
describe('WorkflowRuns - GitHub Actions', () => {

src/renderer/utils/subject.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
PullRequest,
1212
PullRequestReview,
1313
PullRequestStateType,
14+
StateType,
1415
SubjectUser,
1516
User,
1617
WorkflowRunAttributes,
@@ -36,15 +37,15 @@ export async function getGitifySubjectDetails(
3637
case 'CheckSuite':
3738
return getGitifySubjectForCheckSuite(notification);
3839
case 'Commit':
39-
return getGitifySubjectForCommit(notification);
40+
return getGitifySubjectForCommit(notification, settings);
4041
case 'Discussion':
4142
return await getGitifySubjectForDiscussion(notification, settings);
4243
case 'Issue':
4344
return await getGitifySubjectForIssue(notification, settings);
4445
case 'PullRequest':
4546
return await getGitifySubjectForPullRequest(notification, settings);
4647
case 'Release':
47-
return await getGitifySubjectForRelease(notification);
48+
return await getGitifySubjectForRelease(notification, settings);
4849
case 'WorkflowRun':
4950
return getGitifySubjectForWorkflowRun(notification);
5051
default:
@@ -122,8 +123,15 @@ function getGitifySubjectForCheckSuite(
122123

123124
async function getGitifySubjectForCommit(
124125
notification: Notification,
126+
settings: SettingsState,
125127
): Promise<GitifySubject> {
126128
let user: User;
129+
const commitState: StateType = null; // Commit notifications are stateless
130+
131+
// Return early if this notification would be hidden by filters
132+
if (isStateFilteredOut(commitState, settings)) {
133+
return null;
134+
}
127135

128136
if (notification.subject.latest_comment_url) {
129137
const commitComment = (
@@ -143,7 +151,7 @@ async function getGitifySubjectForCommit(
143151
}
144152

145153
return {
146-
state: null,
154+
state: commitState,
147155
user: getSubjectUser([user]),
148156
};
149157
}
@@ -373,13 +381,21 @@ export function parseLinkedIssuesFromPr(pr: PullRequest): string[] {
373381

374382
async function getGitifySubjectForRelease(
375383
notification: Notification,
384+
settings: SettingsState,
376385
): Promise<GitifySubject> {
386+
const releaseState: StateType = null; // Release notifications are stateless
387+
388+
// Return early if this notification would be hidden by filters
389+
if (isStateFilteredOut(releaseState, settings)) {
390+
return null;
391+
}
392+
377393
const release = (
378394
await getRelease(notification.subject.url, notification.account.token)
379395
).data;
380396

381397
return {
382-
state: null,
398+
state: releaseState,
383399
user: getSubjectUser([release.author]),
384400
};
385401
}

0 commit comments

Comments
 (0)