Skip to content

Commit 92c6910

Browse files
authored
feat: add release user (#899)
* feat: add release user * Merge remote-tracking branch 'origin/main' into feature/support-release-subject
1 parent 54e30d8 commit 92c6910

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

src/typesGithub.ts

+16
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,22 @@ export interface IssueComments {
245245
body: string;
246246
}
247247

248+
export interface ReleaseComments {
249+
url: string;
250+
assets_url: string;
251+
html_url: string;
252+
id: number;
253+
author: User;
254+
node_id: string;
255+
tag_name: string;
256+
name: string;
257+
draft: boolean;
258+
prerelease: boolean;
259+
created_at: string;
260+
published_at: string;
261+
body: string;
262+
}
263+
248264
export interface GraphQLSearch<T> {
249265
data: {
250266
data: {

src/utils/subject.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,32 @@ describe('utils/subject.ts', () => {
592592
});
593593
});
594594

595+
describe('getGitifySubjectForRelease', () => {
596+
it('release notification', async () => {
597+
const mockNotification = {
598+
...mockedSingleNotification,
599+
subject: {
600+
...mockedSingleNotification.subject,
601+
type: 'Release' as SubjectType,
602+
url: 'https://api.github.com/repos/manosim/notifications-test/releases/1',
603+
latest_comment_url:
604+
'https://api.github.com/repos/manosim/notifications-test/releases/1',
605+
},
606+
};
607+
608+
nock('https://api.github.com')
609+
.get('/repos/manosim/notifications-test/releases/1')
610+
.reply(200, { author: { login: 'some-user' } });
611+
612+
const result = await getGitifySubjectDetails(
613+
mockNotification,
614+
mockAccounts.token,
615+
);
616+
617+
expect(result.user).toBe('some-user');
618+
});
619+
});
620+
595621
describe('getWorkflowRunState', () => {
596622
it('deploy review workflow run state', async () => {
597623
const mockNotification = {

src/utils/subject.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Notification,
1010
PullRequest,
1111
PullRequestStateType,
12+
ReleaseComments,
1213
User,
1314
WorkflowRunAttributes,
1415
} from '../typesGithub';
@@ -27,6 +28,8 @@ export async function getGitifySubjectDetails(
2728
return await getGitifySubjectForIssue(notification, token);
2829
case 'PullRequest':
2930
return await getGitifySubjectForPullRequest(notification, token);
31+
case 'Release':
32+
return await getGitifySubjectForRelease(notification, token);
3033
case 'WorkflowRun':
3134
return getGitifySubjectForWorkflowRun(notification);
3235
default:
@@ -156,6 +159,18 @@ async function getGitifySubjectForPullRequest(
156159
};
157160
}
158161

162+
async function getGitifySubjectForRelease(
163+
notification: Notification,
164+
token: string,
165+
): Promise<GitifySubject> {
166+
const releaseCommentUser = await getLatestCommentUser(notification, token);
167+
168+
return {
169+
state: null,
170+
user: releaseCommentUser.login,
171+
};
172+
}
173+
159174
function getGitifySubjectForWorkflowRun(
160175
notification: Notification,
161176
): GitifySubject {
@@ -203,9 +218,11 @@ async function getLatestCommentUser(
203218
notification: Notification,
204219
token: string,
205220
): Promise<User> {
206-
const response: IssueComments = (
221+
const response: IssueComments | ReleaseComments = (
207222
await apiRequestAuth(notification.subject.latest_comment_url, 'GET', token)
208223
).data;
209224

210-
return response.user;
225+
return (
226+
(response as IssueComments).user ?? (response as ReleaseComments).author
227+
);
211228
}

0 commit comments

Comments
 (0)