Skip to content

feat(discussions): default to discussion author #964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 6, 2024
Merged
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
460 changes: 161 additions & 299 deletions src/__mocks__/mockedData.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ exports[`components/NotificationRow.tsx should render itself & its children with
</div>
<div
className="flex-1 overflow-hidden"
onClick={[Function]}
>
<div
className="mb-1 text-sm whitespace-nowrap overflow-ellipsis overflow-hidden cursor-pointer"
onClick={[Function]}
role="main"
title="I am a robot and this is a test!"
>
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/useNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ describe('hooks/useNotifications.ts', () => {
stateReason: null,
isAnswered: true,
url: 'https://github.com/manosim/notifications-test/discussions/612',
author: {
login: 'discussion-creator',
url: 'https://github.com/discussion-creator',
avatar_url:
'https://avatars.githubusercontent.com/u/1?v=4',
type: 'User',
},
comments: {
nodes: [
{
Expand All @@ -290,6 +297,7 @@ describe('hooks/useNotifications.ts', () => {
url: 'https://github.com/comment-user',
avatar_url:
'https://avatars.githubusercontent.com/u/1?v=4',
type: 'User',
},
replies: {
nodes: [],
Expand Down
6 changes: 6 additions & 0 deletions src/routes/__snapshots__/Notifications.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ exports[`routes/Notifications.tsx should render itself & its children (show acco
"title": "I am a robot and this is a test!",
"type": "Issue",
"url": "https://api.github.com/repos/manosim/notifications-test/issues/1",
"user": {
"avatar_url": "https://avatars0.githubusercontent.com/u/6333409?v=3",
"html_url": "https://github.com/manosim",
"login": "manosim",
"type": "User",
},
},
"subscription_url": "https://api.github.com/notifications/threads/138661096/subscription",
"unread": true,
Expand Down
13 changes: 7 additions & 6 deletions src/typesGithub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export interface DiscussionAuthor {
login: string;
url: string;
avatar_url: string;
type: string;
}

export interface Repository {
Expand Down Expand Up @@ -338,18 +339,18 @@ export interface Discussion {
stateReason: DiscussionStateType;
isAnswered: boolean;
url: string;
comments: {
nodes: DiscussionComment[];
};
author: DiscussionAuthor;
comments: DiscussionComments;
}

export interface DiscussionComments {
nodes: DiscussionComment[];
}

export interface DiscussionComment {
databaseId: string | number;
createdAt: string;
author: DiscussionAuthor;
bot: {
login?: string;
};
replies?: {
nodes: DiscussionComment[];
};
Expand Down
20 changes: 11 additions & 9 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,18 @@ export async function fetchDiscussion(
token,
{
query: `
fragment AuthorFields on Actor {
login
url
avatar_url: avatarUrl
type: __typename
}

fragment CommentFields on DiscussionComment {
databaseId
createdAt
author {
login
url
avatar_url: avatarUrl
}
bot: author {
... on Bot {
login
avatar_url: avatarUrl
}
...AuthorFields
}
}

Expand All @@ -195,6 +194,9 @@ export async function fetchDiscussion(
stateReason
isAnswered
url
author {
...AuthorFields
}
comments(last: $lastComments){
nodes {
...CommentFields
Expand Down
105 changes: 98 additions & 7 deletions src/utils/subject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ describe('utils/subject.ts', () => {
viewerSubscription: 'SUBSCRIBED',
stateReason: null,
isAnswered: true,
author: {
login: 'discussion-creator',
url: 'https://github.com/discussion-creator',
avatar_url:
'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
},
comments: {
nodes: [], //TODO - Update this to have real data
},
Expand All @@ -175,7 +182,12 @@ describe('utils/subject.ts', () => {
);

expect(result.state).toBe('ANSWERED');
expect(result.user).toBe(null);
expect(result.user).toEqual({
login: 'discussion-creator',
html_url: 'https://github.com/discussion-creator',
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
});
});

it('duplicate discussion state', async () => {
Expand All @@ -199,6 +211,13 @@ describe('utils/subject.ts', () => {
viewerSubscription: 'SUBSCRIBED',
stateReason: 'DUPLICATE',
isAnswered: false,
author: {
login: 'discussion-creator',
url: 'https://github.com/discussion-creator',
avatar_url:
'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
},
comments: {
nodes: [], //TODO - Update this to have real data
},
Expand All @@ -214,7 +233,12 @@ describe('utils/subject.ts', () => {
);

expect(result.state).toBe('DUPLICATE');
expect(result.user).toBe(null);
expect(result.user).toEqual({
login: 'discussion-creator',
html_url: 'https://github.com/discussion-creator',
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
});
});

it('open discussion state', async () => {
Expand All @@ -238,6 +262,13 @@ describe('utils/subject.ts', () => {
viewerSubscription: 'SUBSCRIBED',
stateReason: null,
isAnswered: false,
author: {
login: 'discussion-creator',
url: 'https://github.com/discussion-creator',
avatar_url:
'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
},
comments: {
nodes: [], //TODO - Update this to have real data
},
Expand All @@ -253,7 +284,12 @@ describe('utils/subject.ts', () => {
);

expect(result.state).toBe('OPEN');
expect(result.user).toBe(null);
expect(result.user).toEqual({
login: 'discussion-creator',
html_url: 'https://github.com/discussion-creator',
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
});
});

it('outdated discussion state', async () => {
Expand All @@ -277,6 +313,13 @@ describe('utils/subject.ts', () => {
viewerSubscription: 'SUBSCRIBED',
stateReason: 'OUTDATED',
isAnswered: false,
author: {
login: 'discussion-creator',
url: 'https://github.com/discussion-creator',
avatar_url:
'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
},
comments: {
nodes: [], //TODO - Update this to have real data
},
Expand All @@ -292,7 +335,12 @@ describe('utils/subject.ts', () => {
);

expect(result.state).toBe('OUTDATED');
expect(result.user).toBe(null);
expect(result.user).toEqual({
login: 'discussion-creator',
html_url: 'https://github.com/discussion-creator',
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
});
});

it('reopened discussion state', async () => {
Expand All @@ -316,6 +364,13 @@ describe('utils/subject.ts', () => {
viewerSubscription: 'SUBSCRIBED',
stateReason: 'REOPENED',
isAnswered: false,
author: {
login: 'discussion-creator',
url: 'https://github.com/discussion-creator',
avatar_url:
'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
},
comments: {
nodes: [], //TODO - Update this to have real data
},
Expand All @@ -331,7 +386,12 @@ describe('utils/subject.ts', () => {
);

expect(result.state).toBe('REOPENED');
expect(result.user).toBe(null);
expect(result.user).toEqual({
login: 'discussion-creator',
html_url: 'https://github.com/discussion-creator',
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
});
});

it('resolved discussion state', async () => {
Expand All @@ -355,6 +415,13 @@ describe('utils/subject.ts', () => {
viewerSubscription: 'SUBSCRIBED',
stateReason: 'RESOLVED',
isAnswered: false,
author: {
login: 'discussion-creator',
url: 'https://github.com/discussion-creator',
avatar_url:
'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
},
comments: {
nodes: [], //TODO - Update this to have real data
},
Expand All @@ -370,7 +437,12 @@ describe('utils/subject.ts', () => {
);

expect(result.state).toBe('RESOLVED');
expect(result.user).toBe(null);
expect(result.user).toEqual({
login: 'discussion-creator',
html_url: 'https://github.com/discussion-creator',
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
});
});

it('filtered response by subscribed', async () => {
Expand All @@ -394,6 +466,13 @@ describe('utils/subject.ts', () => {
viewerSubscription: 'SUBSCRIBED',
stateReason: null,
isAnswered: false,
author: {
login: 'discussion-creator',
url: 'https://github.com/discussion-creator',
avatar_url:
'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
},
comments: {
nodes: [], //TODO - Update this to have real data
},
Expand All @@ -403,6 +482,13 @@ describe('utils/subject.ts', () => {
viewerSubscription: 'IGNORED',
stateReason: null,
isAnswered: true,
author: {
login: 'discussion-creator',
url: 'https://github.com/discussion-creator',
avatar_url:
'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
},
comments: {
nodes: [], //TODO - Update this to have real data
},
Expand All @@ -418,7 +504,12 @@ describe('utils/subject.ts', () => {
);

expect(result.state).toBe('OPEN');
expect(result.user).toBe(null);
expect(result.user).toEqual({
login: 'discussion-creator',
html_url: 'https://github.com/discussion-creator',
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
});
});
});

Expand Down
10 changes: 8 additions & 2 deletions src/utils/subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,19 @@ async function getGitifySubjectForDiscussion(
const latestDiscussionComment = getLatestDiscussionComment(
discussion.comments.nodes,
);
let discussionUser: SubjectUser = null;

let discussionUser: SubjectUser = {
login: discussion.author.login,
html_url: discussion.author.url,
avatar_url: discussion.author.avatar_url,
type: discussion.author.type,
};
if (latestDiscussionComment) {
discussionUser = {
login: latestDiscussionComment.author.login,
html_url: latestDiscussionComment.author.url,
avatar_url: latestDiscussionComment.author.avatar_url,
type: latestDiscussionComment.bot?.login ? 'Bot' : 'User',
type: latestDiscussionComment.author.type,
};
}

Expand Down