From 848f8efb885f648df35c15d4a00789a06f727678 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 20 Mar 2024 23:13:28 -0400 Subject: [PATCH] feat: fallback to issue/pr user --- src/utils/subject.test.ts | 104 ++++++++++++++++++++++++++------------ src/utils/subject.ts | 4 +- 2 files changed, 75 insertions(+), 33 deletions(-) diff --git a/src/utils/subject.test.ts b/src/utils/subject.test.ts index 77f3c2ddd..657f4e3e0 100644 --- a/src/utils/subject.test.ts +++ b/src/utils/subject.test.ts @@ -423,11 +423,11 @@ describe('utils/subject.ts', () => { it('open issue state', async () => { nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/1') - .reply(200, { state: 'open' }); + .reply(200, { state: 'open', user: { login: 'some-user' } }); nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/comments/302888448') - .reply(200, { user: { login: 'some-user' } }); + .reply(200, { user: { login: 'some-commenter' } }); const result = await getGitifySubjectDetails( mockedSingleNotification, @@ -435,17 +435,17 @@ describe('utils/subject.ts', () => { ); expect(result.state).toBe('open'); - expect(result.user).toBe('some-user'); + expect(result.user).toBe('some-commenter'); }); it('closed issue state', async () => { nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/1') - .reply(200, { state: 'closed' }); + .reply(200, { state: 'closed', user: { login: 'some-user' } }); nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/comments/302888448') - .reply(200, { user: { login: 'some-user' } }); + .reply(200, { user: { login: 'some-commenter' } }); const result = await getGitifySubjectDetails( mockedSingleNotification, @@ -453,17 +453,21 @@ describe('utils/subject.ts', () => { ); expect(result.state).toBe('closed'); - expect(result.user).toBe('some-user'); + expect(result.user).toBe('some-commenter'); }); it('completed issue state', async () => { nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/1') - .reply(200, { state: 'closed', state_reason: 'completed' }); + .reply(200, { + state: 'closed', + state_reason: 'completed', + user: { login: 'some-user' }, + }); nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/comments/302888448') - .reply(200, { user: { login: 'some-user' } }); + .reply(200, { user: { login: 'some-commenter' } }); const result = await getGitifySubjectDetails( mockedSingleNotification, @@ -471,17 +475,21 @@ describe('utils/subject.ts', () => { ); expect(result.state).toBe('completed'); - expect(result.user).toBe('some-user'); + expect(result.user).toBe('some-commenter'); }); it('not_planned issue state', async () => { nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/1') - .reply(200, { state: 'open', state_reason: 'not_planned' }); + .reply(200, { + state: 'open', + state_reason: 'not_planned', + user: { login: 'some-user' }, + }); nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/comments/302888448') - .reply(200, { user: { login: 'some-user' } }); + .reply(200, { user: { login: 'some-commenter' } }); const result = await getGitifySubjectDetails( mockedSingleNotification, @@ -489,17 +497,21 @@ describe('utils/subject.ts', () => { ); expect(result.state).toBe('not_planned'); - expect(result.user).toBe('some-user'); + expect(result.user).toBe('some-commenter'); }); it('reopened issue state', async () => { nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/1') - .reply(200, { state: 'open', state_reason: 'reopened' }); + .reply(200, { + state: 'open', + state_reason: 'reopened', + user: { login: 'some-user' }, + }); nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/comments/302888448') - .reply(200, { user: { login: 'some-user' } }); + .reply(200, { user: { login: 'some-commenter' } }); const result = await getGitifySubjectDetails( mockedSingleNotification, @@ -507,13 +519,18 @@ describe('utils/subject.ts', () => { ); expect(result.state).toBe('reopened'); - expect(result.user).toBe('some-user'); + expect(result.user).toBe('some-commenter'); }); it('handle issues without latest_comment_url', async () => { nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/1') - .reply(200, { state: 'open', draft: false, merged: false }); + .reply(200, { + state: 'open', + draft: false, + merged: false, + user: { login: 'some-user' }, + }); const result = await getGitifySubjectDetails( { @@ -527,7 +544,7 @@ describe('utils/subject.ts', () => { ); expect(result.state).toBe('open'); - expect(result.user).toBeNull(); + expect(result.user).toBe('some-user'); }); }); @@ -543,11 +560,16 @@ describe('utils/subject.ts', () => { it('closed pull request state', async () => { nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/1') - .reply(200, { state: 'closed', draft: false, merged: false }); + .reply(200, { + state: 'closed', + draft: false, + merged: false, + user: { login: 'some-user' }, + }); nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/comments/302888448') - .reply(200, { user: { login: 'some-user' } }); + .reply(200, { user: { login: 'some-commenter' } }); const result = await getGitifySubjectDetails( mockNotification, @@ -555,17 +577,22 @@ describe('utils/subject.ts', () => { ); expect(result.state).toBe('closed'); - expect(result.user).toBe('some-user'); + expect(result.user).toBe('some-commenter'); }); it('draft pull request state', async () => { nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/1') - .reply(200, { state: 'open', draft: true, merged: false }); + .reply(200, { + state: 'open', + draft: true, + merged: false, + user: { login: 'some-user' }, + }); nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/comments/302888448') - .reply(200, { user: { login: 'some-user' } }); + .reply(200, { user: { login: 'some-commenter' } }); const result = await getGitifySubjectDetails( mockNotification, @@ -573,17 +600,22 @@ describe('utils/subject.ts', () => { ); expect(result.state).toBe('draft'); - expect(result.user).toBe('some-user'); + expect(result.user).toBe('some-commenter'); }); it('merged pull request state', async () => { nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/1') - .reply(200, { state: 'open', draft: false, merged: true }); + .reply(200, { + state: 'open', + draft: false, + merged: true, + user: { login: 'some-user' }, + }); nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/comments/302888448') - .reply(200, { user: { login: 'some-user' } }); + .reply(200, { user: { login: 'some-commenter' } }); const result = await getGitifySubjectDetails( mockNotification, @@ -591,17 +623,22 @@ describe('utils/subject.ts', () => { ); expect(result.state).toBe('merged'); - expect(result.user).toBe('some-user'); + expect(result.user).toBe('some-commenter'); }); it('open pull request state', async () => { nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/1') - .reply(200, { state: 'open', draft: false, merged: false }); + .reply(200, { + state: 'open', + draft: false, + merged: false, + user: { login: 'some-user' }, + }); nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/comments/302888448') - .reply(200, { user: { login: 'some-user' } }); + .reply(200, { user: { login: 'some-commenter' } }); const result = await getGitifySubjectDetails( mockNotification, @@ -609,13 +646,18 @@ describe('utils/subject.ts', () => { ); expect(result.state).toBe('open'); - expect(result.user).toBe('some-user'); + expect(result.user).toBe('some-commenter'); }); it('handle pull request without latest_comment_url', async () => { nock('https://api.github.com') .get('/repos/manosim/notifications-test/issues/1') - .reply(200, { state: 'open', draft: false, merged: false }); + .reply(200, { + state: 'open', + draft: false, + merged: false, + user: { login: 'some-user' }, + }); const result = await getGitifySubjectDetails( { @@ -629,7 +671,7 @@ describe('utils/subject.ts', () => { ); expect(result.state).toBe('open'); - expect(result.user).toBeNull(); + expect(result.user).toBe('some-user'); }); }); }); diff --git a/src/utils/subject.ts b/src/utils/subject.ts index 96969a129..10ce5ae31 100644 --- a/src/utils/subject.ts +++ b/src/utils/subject.ts @@ -128,7 +128,7 @@ async function getGitifySubjectForIssue( return { state: issue.state_reason ?? issue.state, - user: issueCommentUser?.login ?? null, + user: issueCommentUser?.login ?? issue.user.login, }; } @@ -151,7 +151,7 @@ async function getGitifySubjectForPullRequest( return { state: prState, - user: prCommentUser?.login ?? null, + user: prCommentUser?.login ?? pr.user.login, }; }