Skip to content

Commit 67abc89

Browse files
authored
feat: only extract linked issues for User PRs (#1219)
* fix: only extract linked issues for User PRs * fix: only extract linked issues for User PRs
1 parent 2774959 commit 67abc89

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/utils/subject.test.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import type {
1010
DiscussionAuthor,
1111
DiscussionStateType,
1212
Notification,
13+
PullRequest,
1314
Repository,
1415
} from '../typesGitHub';
1516
import {
1617
getCheckSuiteAttributes,
1718
getGitifySubjectDetails,
1819
getLatestReviewForReviewers,
1920
getWorkflowRunAttributes,
20-
parseLinkedIssuesFromPrBody,
21+
parseLinkedIssuesFromPr,
2122
} from './subject';
2223

2324
const mockAuthor = partialMockUser('some-author');
@@ -982,13 +983,36 @@ describe('utils/subject.ts', () => {
982983

983984
describe('Pull Request With Linked Issues', () => {
984985
it('returns empty if no pr body', () => {
985-
const result = parseLinkedIssuesFromPrBody(null);
986+
const mockPr = {
987+
user: {
988+
type: 'User',
989+
},
990+
body: null,
991+
} as PullRequest;
992+
993+
const result = parseLinkedIssuesFromPr(mockPr);
994+
expect(result).toEqual([]);
995+
});
996+
997+
it('returns empty if pr from non-user', () => {
998+
const mockPr = {
999+
user: {
1000+
type: 'Bot',
1001+
},
1002+
body: 'This PR is linked to #1, #2, and #3',
1003+
} as PullRequest;
1004+
const result = parseLinkedIssuesFromPr(mockPr);
9861005
expect(result).toEqual([]);
9871006
});
9881007

9891008
it('returns linked issues', () => {
990-
const mockPrBody = 'This PR is linked to #1, #2, and #3';
991-
const result = parseLinkedIssuesFromPrBody(mockPrBody);
1009+
const mockPr = {
1010+
user: {
1011+
type: 'User',
1012+
},
1013+
body: 'This PR is linked to #1, #2, and #3',
1014+
} as PullRequest;
1015+
const result = parseLinkedIssuesFromPr(mockPr);
9921016
expect(result).toEqual(['#1', '#2', '#3']);
9931017
});
9941018
});

src/utils/subject.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
GitifyPullRequestReview,
77
GitifySubject,
88
Notification,
9+
PullRequest,
910
PullRequestReview,
1011
PullRequestStateType,
1112
SubjectUser,
@@ -267,7 +268,7 @@ async function getGitifySubjectForPullRequest(
267268
}
268269

269270
const reviews = await getLatestReviewForReviewers(notification);
270-
const linkedIssues = parseLinkedIssuesFromPrBody(pr.body);
271+
const linkedIssues = parseLinkedIssuesFromPr(pr);
271272

272273
return {
273274
state: prState,
@@ -336,16 +337,16 @@ export async function getLatestReviewForReviewers(
336337
});
337338
}
338339

339-
export function parseLinkedIssuesFromPrBody(body: string): string[] {
340+
export function parseLinkedIssuesFromPr(pr: PullRequest): string[] {
340341
const linkedIssues: string[] = [];
341342

342-
if (!body) {
343+
if (!pr.body || pr.user.type !== 'User') {
343344
return linkedIssues;
344345
}
345346

346347
const regexPattern = /\s*#(\d+)\s*/gi;
347348

348-
const matches = body.matchAll(regexPattern);
349+
const matches = pr.body.matchAll(regexPattern);
349350

350351
for (const match of matches) {
351352
if (match[0]) {

0 commit comments

Comments
 (0)