Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,16 @@ export interface GitifySubject {
number?: number;
/** Parsed state */
state?: GitifyNotificationState;
/** Latest comment/PR author */
/**
* Identity shown for this notification in the UI (avatar, user-type filter).
* Resolves to the most recent actor: the latest commenter, falling back to
* the author.
*/
user?: GitifyNotificationUser;
/** Author who created the thread (pull request/issue/discussion/release/commit) */
author?: GitifyNotificationUser;
/** Author of the latest comment, when the subject has comments */
commenter?: GitifyNotificationUser;
/** PR review states & reviewers */
reviews?: GitifyPullRequestReview[];
/** PRs closing issues */
Expand Down
37 changes: 37 additions & 0 deletions src/renderer/utils/forges/github/handlers/commit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ describe('renderer/utils/notifications/handlers/commit.ts', () => {
avatarUrl: mockCommenter.avatar_url,
type: mockCommenter.type,
},
author: {
login: mockAuthor.login,
htmlUrl: mockAuthor.html_url,
avatarUrl: mockAuthor.avatar_url,
type: mockAuthor.type,
},
commenter: {
login: mockCommenter.login,
htmlUrl: mockCommenter.html_url,
avatarUrl: mockCommenter.avatar_url,
type: mockCommenter.type,
},
});
});

Expand All @@ -70,9 +82,34 @@ describe('renderer/utils/notifications/handlers/commit.ts', () => {
avatarUrl: mockAuthor.avatar_url,
type: mockAuthor.type,
},
author: {
login: mockAuthor.login,
htmlUrl: mockAuthor.html_url,
avatarUrl: mockAuthor.avatar_url,
type: mockAuthor.type,
},
});
});

it('leaves roles undefined when the commit has no linked GitHub user', async () => {
const mockNotification = mockPartialGitifyNotification({
title: 'This is a commit with comments',
type: 'Commit',
url: 'https://api.github.com/repos/gitify-app/notifications-test/commits/d2a86d80e3d24ea9510d5de6c147e53c30f313a8' as Link,
latestCommentUrl: null,
});

getCommitSpy.mockResolvedValue({
author: null,
} as GetCommitResponse);

const result = await commitHandler.enrich(mockNotification, mockSettings);

expect(result.user).toBeUndefined();
expect(result.author).toBeUndefined();
expect(result.commenter).toBeUndefined();
});

it('return early if commit state filtered', async () => {
useFiltersStore.setState({ states: ['closed'] });

Expand Down
50 changes: 31 additions & 19 deletions src/renderer/utils/forges/github/handlers/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,26 @@ import type {
Link,
SettingsState,
} from '../../../../types';
import type { RawUser } from '../types';

import { isStateFilteredOut } from '../../../notifications/filters/filter';
import { getCommit, getCommitComment } from '../client';
import { DefaultHandler } from './default';
import { getNotificationAuthor } from './utils';

function toNotificationUser(
user: RawUser | Record<string, never> | null | undefined,
): GitifyNotificationUser | undefined {
if (!user || !('login' in user)) {
return undefined;
}

return {
login: user.login,
avatarUrl: user.avatar_url as Link,
htmlUrl: user.html_url as Link,
type: user.type as GitifyNotificationUser['type'],
};
}

class CommitHandler extends DefaultHandler {
override async enrich(
Expand All @@ -29,34 +44,31 @@ class CommitHandler extends DefaultHandler {
return {};
}

let user: GitifyNotificationUser;
// Always resolve the commit author; additionally resolve the latest
// comment author when the notification points at a comment. Both calls run
// in parallel so populating both roles costs no extra latency.
let author: GitifyNotificationUser | undefined;
let commenter: GitifyNotificationUser | undefined;

if (notification.subject.latestCommentUrl) {
const commitComment = await getCommitComment(
notification.account,
notification.subject.latestCommentUrl,
);
const [commit, commitComment] = await Promise.all([
getCommit(notification.account, notification.subject.url!),
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'],
};
author = toNotificationUser(commit.author);
commenter = toNotificationUser(commitComment.user);
} 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'],
};
author = toNotificationUser(commit.author);
}

return {
state: commitState,
user: getNotificationAuthor([user]),
user: commenter ?? author,
author: author,
commenter: commenter,
};
}

Expand Down
48 changes: 48 additions & 0 deletions src/renderer/utils/forges/github/handlers/discussion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ describe('renderer/utils/notifications/handlers/discussion.ts', () => {
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
author: {
login: mockAuthor.login,
avatarUrl: mockAuthor.avatarUrl,
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
commentCount: 0,
labels: [],
htmlUrl: 'https://github.com/gitify-app/notifications-test/discussions/123' as Link,
Expand Down Expand Up @@ -86,6 +92,12 @@ describe('renderer/utils/notifications/handlers/discussion.ts', () => {
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
author: {
login: mockAuthor.login,
avatarUrl: mockAuthor.avatarUrl,
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
commentCount: 0,
labels: [],
htmlUrl: 'https://github.com/gitify-app/notifications-test/discussions/123' as Link,
Expand Down Expand Up @@ -117,6 +129,12 @@ describe('renderer/utils/notifications/handlers/discussion.ts', () => {
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
author: {
login: mockAuthor.login,
avatarUrl: mockAuthor.avatarUrl,
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
commentCount: 0,
labels: [],
htmlUrl: 'https://github.com/gitify-app/notifications-test/discussions/123' as Link,
Expand Down Expand Up @@ -153,6 +171,12 @@ describe('renderer/utils/notifications/handlers/discussion.ts', () => {
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
author: {
login: mockAuthor.login,
avatarUrl: mockAuthor.avatarUrl,
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
commentCount: 0,
labels: [{ name: 'enhancement', color: '0e8a16' }],
htmlUrl: 'https://github.com/gitify-app/notifications-test/discussions/123' as Link,
Expand Down Expand Up @@ -199,6 +223,18 @@ describe('renderer/utils/notifications/handlers/discussion.ts', () => {
htmlUrl: mockCommenter.htmlUrl,
type: mockCommenter.type,
},
author: {
login: mockAuthor.login,
avatarUrl: mockAuthor.avatarUrl,
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
commenter: {
login: mockCommenter.login,
avatarUrl: mockCommenter.avatarUrl,
htmlUrl: mockCommenter.htmlUrl,
type: mockCommenter.type,
},
commentCount: 1,
labels: [],
htmlUrl:
Expand Down Expand Up @@ -256,6 +292,18 @@ describe('renderer/utils/notifications/handlers/discussion.ts', () => {
htmlUrl: mockReplier.htmlUrl,
type: mockReplier.type,
},
author: {
login: mockAuthor.login,
avatarUrl: mockAuthor.avatarUrl,
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
commenter: {
login: mockReplier.login,
avatarUrl: mockReplier.avatarUrl,
htmlUrl: mockReplier.htmlUrl,
type: mockReplier.type,
},
commentCount: 1,
labels: [],
htmlUrl:
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/utils/forges/github/handlers/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ class DiscussionHandler extends DefaultHandler {
const discussionReactionGroup =
latestDiscussionComment?.reactionGroups ?? discussion.reactionGroups;

const author = getNotificationAuthor([discussion.author]);
const commenter = getNotificationAuthor([latestDiscussionComment?.author]);

return {
number: discussion.number,
state: discussionState,
user: getNotificationAuthor([latestDiscussionComment?.author, discussion.author]),
user: commenter ?? author,
author: author,
commenter: commenter,
commentCount: discussion.comments.totalCount,
labels:
discussion.labels?.nodes?.filter(Boolean).map((label) => ({
Expand Down
36 changes: 36 additions & 0 deletions src/renderer/utils/forges/github/handlers/issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ describe('renderer/utils/notifications/handlers/issue.ts', () => {
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
author: {
login: mockAuthor.login,
avatarUrl: mockAuthor.avatarUrl,
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
commentCount: 0,
htmlUrl: 'https://github.com/gitify-app/notifications-test/issues/123' as Link,
labels: [],
Expand Down Expand Up @@ -86,6 +92,12 @@ describe('renderer/utils/notifications/handlers/issue.ts', () => {
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
author: {
login: mockAuthor.login,
avatarUrl: mockAuthor.avatarUrl,
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
commentCount: 0,
htmlUrl: 'https://github.com/gitify-app/notifications-test/issues/123' as Link,
labels: [],
Expand Down Expand Up @@ -130,6 +142,18 @@ describe('renderer/utils/notifications/handlers/issue.ts', () => {
htmlUrl: mockCommenter.htmlUrl,
type: mockCommenter.type,
},
author: {
login: mockAuthor.login,
avatarUrl: mockAuthor.avatarUrl,
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
commenter: {
login: mockCommenter.login,
avatarUrl: mockCommenter.avatarUrl,
htmlUrl: mockCommenter.htmlUrl,
type: mockCommenter.type,
},
commentCount: 1,
htmlUrl:
'https://github.com/gitify-app/notifications-test/issues/123#issuecomment-1234' as Link,
Expand Down Expand Up @@ -165,6 +189,12 @@ describe('renderer/utils/notifications/handlers/issue.ts', () => {
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
author: {
login: mockAuthor.login,
avatarUrl: mockAuthor.avatarUrl,
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
commentCount: 0,
htmlUrl: 'https://github.com/gitify-app/notifications-test/issues/123' as Link,
labels: [{ name: 'enhancement', color: '0e8a16' }],
Expand Down Expand Up @@ -200,6 +230,12 @@ describe('renderer/utils/notifications/handlers/issue.ts', () => {
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
author: {
login: mockAuthor.login,
avatarUrl: mockAuthor.avatarUrl,
htmlUrl: mockAuthor.htmlUrl,
type: mockAuthor.type,
},
commentCount: 0,
htmlUrl: 'https://github.com/gitify-app/notifications-test/issues/123' as Link,
labels: [],
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/utils/forges/github/handlers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class IssueHandler extends DefaultHandler {

const issueComment = issue.comments?.nodes?.[0];

const issueUser = getNotificationAuthor([issueComment?.author, issue.author]);
const author = getNotificationAuthor([issue.author]);
const commenter = getNotificationAuthor([issueComment?.author]);
const issueUser = commenter ?? author;

const issueReactionCount = issueComment?.reactions.totalCount ?? issue.reactions.totalCount;
const issueReactionGroup = issueComment?.reactionGroups ?? issue.reactionGroups;
Expand All @@ -49,6 +51,8 @@ class IssueHandler extends DefaultHandler {
number: issue.number,
state: issueState,
user: issueUser,
author: author,
commenter: commenter,
commentCount: issue.comments.totalCount,
labels:
issue.labels?.nodes?.filter(Boolean).map((label) => ({
Expand Down
Loading
Loading