Skip to content
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
16 changes: 16 additions & 0 deletions src/typesGithub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ export interface IssueComments {
body: string;
}

export interface ReleaseComments {
url: string;
assets_url: string;
html_url: string;
id: number;
author: User;
node_id: string;
tag_name: string;
name: string;
draft: boolean;
prerelease: boolean;
created_at: string;
published_at: string;
body: string;
}

export interface GraphQLSearch<T> {
data: {
data: {
Expand Down
26 changes: 26 additions & 0 deletions src/utils/subject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,32 @@ describe('utils/state.ts', () => {
});
});

describe('getGitifySubjectForRelease', () => {
it('release notification', async () => {
const mockNotification = {
...mockedSingleNotification,
subject: {
...mockedSingleNotification.subject,
type: 'Release' as SubjectType,
url: 'https://api.github.com/repos/manosim/notifications-test/releases/1',
latest_comment_url:
'https://api.github.com/repos/manosim/notifications-test/releases/1',
},
};

nock('https://api.github.com')
.get('/repos/manosim/notifications-test/releases/1')
.reply(200, { author: { login: 'some-user' } });

const result = await getGitifySubjectDetails(
mockNotification,
mockAccounts.token,
);

expect(result.user).toBe('some-user');
});
});

describe('getWorkflowRunState', () => {
it('deploy review workflow run state', async () => {
const mockNotification = {
Expand Down
21 changes: 19 additions & 2 deletions src/utils/subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Notification,
PullRequest,
PullRequestStateType,
ReleaseComments,
User,
WorkflowRunAttributes,
} from '../typesGithub';
Expand All @@ -27,6 +28,8 @@ export async function getGitifySubjectDetails(
return await getGitifySubjectForIssue(notification, token);
case 'PullRequest':
return await getGitifySubjectForPullRequest(notification, token);
case 'Release':
return await getGitifySubjectForRelease(notification, token);
case 'WorkflowRun':
return getGitifySubjectForWorkflowRun(notification);
default:
Expand Down Expand Up @@ -156,6 +159,18 @@ async function getGitifySubjectForPullRequest(
};
}

async function getGitifySubjectForRelease(
notification: Notification,
token: string,
): Promise<GitifySubject> {
const releaseCommentUser = await getLatestCommentUser(notification, token);

return {
state: null,
user: releaseCommentUser.login,
};
}

function getGitifySubjectForWorkflowRun(
notification: Notification,
): GitifySubject {
Expand Down Expand Up @@ -203,9 +218,11 @@ async function getLatestCommentUser(
notification: Notification,
token: string,
): Promise<User> {
const response: IssueComments = (
const response: IssueComments | ReleaseComments = (
await apiRequestAuth(notification.subject.latest_comment_url, 'GET', token)
).data;

return response.user;
return (
(response as IssueComments).user ?? (response as ReleaseComments).author
);
}