Skip to content

Commit e19d8df

Browse files
setchyafonsojramos
andauthored
feat: skip fetching PR comments when none exist (#1075)
Co-authored-by: Afonso Jorge Ramos <[email protected]>
1 parent 55bba75 commit e19d8df

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/utils/subject.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,35 @@ describe('utils/subject.ts', () => {
736736
});
737737
});
738738

739+
it('avoid fetching comments if latest_comment_url and url are the same', async () => {
740+
mockNotification.subject.latest_comment_url =
741+
mockNotification.subject.url;
742+
743+
nock('https://api.github.com')
744+
.get('/repos/gitify-app/notifications-test/pulls/1')
745+
.reply(200, {
746+
state: 'open',
747+
draft: false,
748+
merged: false,
749+
user: mockAuthor,
750+
});
751+
752+
const result = await getGitifySubjectDetails(
753+
mockNotification,
754+
mockAccounts.token,
755+
);
756+
757+
expect(result).toEqual({
758+
state: 'open',
759+
user: {
760+
login: mockAuthor.login,
761+
html_url: mockAuthor.html_url,
762+
avatar_url: mockAuthor.avatar_url,
763+
type: mockAuthor.type,
764+
},
765+
});
766+
});
767+
739768
it('handle pull request without latest_comment_url', async () => {
740769
mockNotification.subject.latest_comment_url = null;
741770

src/utils/subject.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ async function getGitifySubjectForPullRequest(
224224

225225
let prCommentUser: User;
226226

227-
if (notification.subject.latest_comment_url) {
227+
if (
228+
notification.subject.latest_comment_url &&
229+
notification.subject.latest_comment_url !== notification.subject.url
230+
) {
228231
const prComment = (
229232
await getIssueOrPullRequestComment(
230233
notification.subject.latest_comment_url,

0 commit comments

Comments
 (0)