Skip to content

Commit 5d174bb

Browse files
authored
feat: fallback to issue/pr user (#916)
1 parent 128fe59 commit 5d174bb

File tree

2 files changed

+75
-33
lines changed

2 files changed

+75
-33
lines changed

src/utils/subject.test.ts

+73-31
Original file line numberDiff line numberDiff line change
@@ -423,97 +423,114 @@ describe('utils/subject.ts', () => {
423423
it('open issue state', async () => {
424424
nock('https://api.github.com')
425425
.get('/repos/manosim/notifications-test/issues/1')
426-
.reply(200, { state: 'open' });
426+
.reply(200, { state: 'open', user: { login: 'some-user' } });
427427

428428
nock('https://api.github.com')
429429
.get('/repos/manosim/notifications-test/issues/comments/302888448')
430-
.reply(200, { user: { login: 'some-user' } });
430+
.reply(200, { user: { login: 'some-commenter' } });
431431

432432
const result = await getGitifySubjectDetails(
433433
mockedSingleNotification,
434434
mockAccounts.token,
435435
);
436436

437437
expect(result.state).toBe('open');
438-
expect(result.user).toBe('some-user');
438+
expect(result.user).toBe('some-commenter');
439439
});
440440

441441
it('closed issue state', async () => {
442442
nock('https://api.github.com')
443443
.get('/repos/manosim/notifications-test/issues/1')
444-
.reply(200, { state: 'closed' });
444+
.reply(200, { state: 'closed', user: { login: 'some-user' } });
445445

446446
nock('https://api.github.com')
447447
.get('/repos/manosim/notifications-test/issues/comments/302888448')
448-
.reply(200, { user: { login: 'some-user' } });
448+
.reply(200, { user: { login: 'some-commenter' } });
449449

450450
const result = await getGitifySubjectDetails(
451451
mockedSingleNotification,
452452
mockAccounts.token,
453453
);
454454

455455
expect(result.state).toBe('closed');
456-
expect(result.user).toBe('some-user');
456+
expect(result.user).toBe('some-commenter');
457457
});
458458

459459
it('completed issue state', async () => {
460460
nock('https://api.github.com')
461461
.get('/repos/manosim/notifications-test/issues/1')
462-
.reply(200, { state: 'closed', state_reason: 'completed' });
462+
.reply(200, {
463+
state: 'closed',
464+
state_reason: 'completed',
465+
user: { login: 'some-user' },
466+
});
463467

464468
nock('https://api.github.com')
465469
.get('/repos/manosim/notifications-test/issues/comments/302888448')
466-
.reply(200, { user: { login: 'some-user' } });
470+
.reply(200, { user: { login: 'some-commenter' } });
467471

468472
const result = await getGitifySubjectDetails(
469473
mockedSingleNotification,
470474
mockAccounts.token,
471475
);
472476

473477
expect(result.state).toBe('completed');
474-
expect(result.user).toBe('some-user');
478+
expect(result.user).toBe('some-commenter');
475479
});
476480

477481
it('not_planned issue state', async () => {
478482
nock('https://api.github.com')
479483
.get('/repos/manosim/notifications-test/issues/1')
480-
.reply(200, { state: 'open', state_reason: 'not_planned' });
484+
.reply(200, {
485+
state: 'open',
486+
state_reason: 'not_planned',
487+
user: { login: 'some-user' },
488+
});
481489

482490
nock('https://api.github.com')
483491
.get('/repos/manosim/notifications-test/issues/comments/302888448')
484-
.reply(200, { user: { login: 'some-user' } });
492+
.reply(200, { user: { login: 'some-commenter' } });
485493

486494
const result = await getGitifySubjectDetails(
487495
mockedSingleNotification,
488496
mockAccounts.token,
489497
);
490498

491499
expect(result.state).toBe('not_planned');
492-
expect(result.user).toBe('some-user');
500+
expect(result.user).toBe('some-commenter');
493501
});
494502

495503
it('reopened issue state', async () => {
496504
nock('https://api.github.com')
497505
.get('/repos/manosim/notifications-test/issues/1')
498-
.reply(200, { state: 'open', state_reason: 'reopened' });
506+
.reply(200, {
507+
state: 'open',
508+
state_reason: 'reopened',
509+
user: { login: 'some-user' },
510+
});
499511

500512
nock('https://api.github.com')
501513
.get('/repos/manosim/notifications-test/issues/comments/302888448')
502-
.reply(200, { user: { login: 'some-user' } });
514+
.reply(200, { user: { login: 'some-commenter' } });
503515

504516
const result = await getGitifySubjectDetails(
505517
mockedSingleNotification,
506518
mockAccounts.token,
507519
);
508520

509521
expect(result.state).toBe('reopened');
510-
expect(result.user).toBe('some-user');
522+
expect(result.user).toBe('some-commenter');
511523
});
512524

513525
it('handle issues without latest_comment_url', async () => {
514526
nock('https://api.github.com')
515527
.get('/repos/manosim/notifications-test/issues/1')
516-
.reply(200, { state: 'open', draft: false, merged: false });
528+
.reply(200, {
529+
state: 'open',
530+
draft: false,
531+
merged: false,
532+
user: { login: 'some-user' },
533+
});
517534

518535
const result = await getGitifySubjectDetails(
519536
{
@@ -527,7 +544,7 @@ describe('utils/subject.ts', () => {
527544
);
528545

529546
expect(result.state).toBe('open');
530-
expect(result.user).toBeNull();
547+
expect(result.user).toBe('some-user');
531548
});
532549
});
533550

@@ -543,79 +560,104 @@ describe('utils/subject.ts', () => {
543560
it('closed pull request state', async () => {
544561
nock('https://api.github.com')
545562
.get('/repos/manosim/notifications-test/issues/1')
546-
.reply(200, { state: 'closed', draft: false, merged: false });
563+
.reply(200, {
564+
state: 'closed',
565+
draft: false,
566+
merged: false,
567+
user: { login: 'some-user' },
568+
});
547569

548570
nock('https://api.github.com')
549571
.get('/repos/manosim/notifications-test/issues/comments/302888448')
550-
.reply(200, { user: { login: 'some-user' } });
572+
.reply(200, { user: { login: 'some-commenter' } });
551573

552574
const result = await getGitifySubjectDetails(
553575
mockNotification,
554576
mockAccounts.token,
555577
);
556578

557579
expect(result.state).toBe('closed');
558-
expect(result.user).toBe('some-user');
580+
expect(result.user).toBe('some-commenter');
559581
});
560582

561583
it('draft pull request state', async () => {
562584
nock('https://api.github.com')
563585
.get('/repos/manosim/notifications-test/issues/1')
564-
.reply(200, { state: 'open', draft: true, merged: false });
586+
.reply(200, {
587+
state: 'open',
588+
draft: true,
589+
merged: false,
590+
user: { login: 'some-user' },
591+
});
565592

566593
nock('https://api.github.com')
567594
.get('/repos/manosim/notifications-test/issues/comments/302888448')
568-
.reply(200, { user: { login: 'some-user' } });
595+
.reply(200, { user: { login: 'some-commenter' } });
569596

570597
const result = await getGitifySubjectDetails(
571598
mockNotification,
572599
mockAccounts.token,
573600
);
574601

575602
expect(result.state).toBe('draft');
576-
expect(result.user).toBe('some-user');
603+
expect(result.user).toBe('some-commenter');
577604
});
578605

579606
it('merged pull request state', async () => {
580607
nock('https://api.github.com')
581608
.get('/repos/manosim/notifications-test/issues/1')
582-
.reply(200, { state: 'open', draft: false, merged: true });
609+
.reply(200, {
610+
state: 'open',
611+
draft: false,
612+
merged: true,
613+
user: { login: 'some-user' },
614+
});
583615

584616
nock('https://api.github.com')
585617
.get('/repos/manosim/notifications-test/issues/comments/302888448')
586-
.reply(200, { user: { login: 'some-user' } });
618+
.reply(200, { user: { login: 'some-commenter' } });
587619

588620
const result = await getGitifySubjectDetails(
589621
mockNotification,
590622
mockAccounts.token,
591623
);
592624

593625
expect(result.state).toBe('merged');
594-
expect(result.user).toBe('some-user');
626+
expect(result.user).toBe('some-commenter');
595627
});
596628

597629
it('open pull request state', async () => {
598630
nock('https://api.github.com')
599631
.get('/repos/manosim/notifications-test/issues/1')
600-
.reply(200, { state: 'open', draft: false, merged: false });
632+
.reply(200, {
633+
state: 'open',
634+
draft: false,
635+
merged: false,
636+
user: { login: 'some-user' },
637+
});
601638

602639
nock('https://api.github.com')
603640
.get('/repos/manosim/notifications-test/issues/comments/302888448')
604-
.reply(200, { user: { login: 'some-user' } });
641+
.reply(200, { user: { login: 'some-commenter' } });
605642

606643
const result = await getGitifySubjectDetails(
607644
mockNotification,
608645
mockAccounts.token,
609646
);
610647

611648
expect(result.state).toBe('open');
612-
expect(result.user).toBe('some-user');
649+
expect(result.user).toBe('some-commenter');
613650
});
614651

615652
it('handle pull request without latest_comment_url', async () => {
616653
nock('https://api.github.com')
617654
.get('/repos/manosim/notifications-test/issues/1')
618-
.reply(200, { state: 'open', draft: false, merged: false });
655+
.reply(200, {
656+
state: 'open',
657+
draft: false,
658+
merged: false,
659+
user: { login: 'some-user' },
660+
});
619661

620662
const result = await getGitifySubjectDetails(
621663
{
@@ -629,7 +671,7 @@ describe('utils/subject.ts', () => {
629671
);
630672

631673
expect(result.state).toBe('open');
632-
expect(result.user).toBeNull();
674+
expect(result.user).toBe('some-user');
633675
});
634676
});
635677
});

src/utils/subject.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async function getGitifySubjectForIssue(
128128

129129
return {
130130
state: issue.state_reason ?? issue.state,
131-
user: issueCommentUser?.login ?? null,
131+
user: issueCommentUser?.login ?? issue.user.login,
132132
};
133133
}
134134

@@ -151,7 +151,7 @@ async function getGitifySubjectForPullRequest(
151151

152152
return {
153153
state: prState,
154-
user: prCommentUser?.login ?? null,
154+
user: prCommentUser?.login ?? pr.user.login,
155155
};
156156
}
157157

0 commit comments

Comments
 (0)