From cf8842d3594e93d01132cdf287ae1d97d1778677 Mon Sep 17 00:00:00 2001 From: Brian Lou Date: Mon, 28 Oct 2024 10:39:12 -0700 Subject: [PATCH 1/2] Add optional to type chain --- src/utils/changelog.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/changelog.ts b/src/utils/changelog.ts index 3a5c6719..45c06c52 100644 --- a/src/utils/changelog.ts +++ b/src/utils/changelog.ts @@ -472,7 +472,7 @@ async function getPRAndMilestoneFromCommit( hash.slice(1), pr ? { - author: pr.author.login, + author: pr.author?.login ?? null, pr: pr.number, prBody: pr.body, milestone: pr.milestone?.number ?? null, From 6d677ee0802d4c41fe6daea7b4472b1556035e95 Mon Sep 17 00:00:00 2001 From: Brian Lou Date: Mon, 28 Oct 2024 11:08:42 -0700 Subject: [PATCH 2/2] Add tests --- src/utils/__tests__/changelog.test.ts | 15 ++++++++++++++- src/utils/changelog.ts | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/utils/__tests__/changelog.test.ts b/src/utils/__tests__/changelog.test.ts index 49b56062..d02ccaae 100644 --- a/src/utils/__tests__/changelog.test.ts +++ b/src/utils/__tests__/changelog.test.ts @@ -290,7 +290,7 @@ describe('generateChangesetFromGit', () => { pr?: { local?: string; remote?: { - author: { login: string }; + author?: { login: string }; number: string; body?: string; milestone?: string; @@ -389,6 +389,19 @@ describe('generateChangesetFromGit', () => { {}, '### Various fixes & improvements\n\n- Upgraded the kernel (#123) by @sentry', ], + [ + 'Does not error when PR author is null', + [ + { + hash: 'abcdef1234567890', + title: 'Upgraded the kernel', + body: '', + pr: { remote: { number: '123' } }, + }, + ], + {}, + '### Various fixes & improvements\n\n- Upgraded the kernel (#123)', + ], [ 'handle multiple commits properly', [ diff --git a/src/utils/changelog.ts b/src/utils/changelog.ts index 45c06c52..7426e796 100644 --- a/src/utils/changelog.ts +++ b/src/utils/changelog.ts @@ -380,7 +380,7 @@ interface CommitInfo { nodes: Array<{ number: string; body: string; - author: { + author?: { login: string; }; milestone: { @@ -472,7 +472,7 @@ async function getPRAndMilestoneFromCommit( hash.slice(1), pr ? { - author: pr.author?.login ?? null, + author: pr.author?.login, pr: pr.number, prBody: pr.body, milestone: pr.milestone?.number ?? null,