Skip to content

Commit 7e2135a

Browse files
authored
fix: github null body (#29)
1 parent 09b6afa commit 7e2135a

4 files changed

Lines changed: 124 additions & 1 deletion

File tree

.changeset/dull-ghosts-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'starlight-changelogs': patch
3+
---
4+
5+
Fixes an issue with the GitHub provider where release without a body would cause an error.

fixtures/github/null-body.json

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
[
2+
{
3+
"url": "https://api.github.com/repos/HiDeoo/starlight-blog/releases/223798079",
4+
"assets_url": "https://api.github.com/repos/HiDeoo/starlight-blog/releases/223798079/assets",
5+
"upload_url": "https://uploads.github.com/repos/HiDeoo/starlight-blog/releases/223798079/assets{?name,label}",
6+
"html_url": "https://github.com/HiDeoo/starlight-blog/releases/tag/starlight-blog%400.24.0",
7+
"id": 223798079,
8+
"author": {
9+
"login": "github-actions[bot]",
10+
"id": 41898282,
11+
"node_id": "MDM6Qm90NDE4OTgyODI=",
12+
"avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
13+
"gravatar_id": "",
14+
"url": "https://api.github.com/users/github-actions%5Bbot%5D",
15+
"html_url": "https://github.com/apps/github-actions",
16+
"followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
17+
"following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
18+
"gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
19+
"starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
20+
"subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
21+
"organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
22+
"repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
23+
"events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
24+
"received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
25+
"type": "Bot",
26+
"user_view_type": "public",
27+
"site_admin": false
28+
},
29+
"node_id": "RE_kwDOJ9RHEc4NVuM_",
30+
"tag_name": "starlight-blog@0.24.0",
31+
"target_commitish": "main",
32+
"name": "starlight-blog@0.24.0",
33+
"draft": false,
34+
"immutable": false,
35+
"prerelease": false,
36+
"created_at": "2025-06-07T14:25:22Z",
37+
"published_at": "2025-06-07T14:25:22Z",
38+
"assets": [
39+
40+
],
41+
"tarball_url": "https://api.github.com/repos/HiDeoo/starlight-blog/tarball/starlight-blog@0.24.0",
42+
"zipball_url": "https://api.github.com/repos/HiDeoo/starlight-blog/zipball/starlight-blog@0.24.0",
43+
"body": "### Minor Changes\n\n- [#162](https://github.com/HiDeoo/starlight-blog/pull/162) [`bc995dc`](https://github.com/HiDeoo/starlight-blog/commit/bc995dce6ad26075316ee3240c6933bd00ffb090) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Exposes a list of all the authors in the blog data object accessible on Starlight pages using `Astro.locals.starlightBlog.authors`. This can be useful for example to create a widget that lists all the authors of your blog on your homepage.\n\n See the [“Blog Data” guide](https://starlight-blog-docs.vercel.app/guides/blog-data/) for more information.\n\n- [#160](https://github.com/HiDeoo/starlight-blog/pull/160) [`f91a48c`](https://github.com/HiDeoo/starlight-blog/commit/f91a48c9d5527dcc54f0374e511fedd9bab95515) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Adds support for [remote](https://docs.astro.build/en/guides/images/#remote-images) [cover images](https://starlight-blog-docs.vercel.app/guides/frontmatter/#cover) in blog posts.\n\n- [#155](https://github.com/HiDeoo/starlight-blog/pull/155) [`e5746c1`](https://github.com/HiDeoo/starlight-blog/commit/e5746c19e8d350e0fc7e759de221fa6948100875) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Adds support for [metrics](https://starlight-blog-docs.vercel.app/configuration/#metrics-configuration) that can be displayed alongside blog posts, such as an estimated reading time or a word count.\n\n To learn more about metrics, check the new [\"Metrics\" guide](https://starlight-blog-docs.vercel.app/guides/metrics/).\n"
44+
},
45+
{
46+
"url": "https://api.github.com/repos/HiDeoo/starlight-blog/releases/218046732",
47+
"assets_url": "https://api.github.com/repos/HiDeoo/starlight-blog/releases/218046732/assets",
48+
"upload_url": "https://uploads.github.com/repos/HiDeoo/starlight-blog/releases/218046732/assets{?name,label}",
49+
"html_url": "https://github.com/HiDeoo/starlight-blog/releases/tag/starlight-blog%400.23.2",
50+
"id": 218046732,
51+
"author": {
52+
"login": "github-actions[bot]",
53+
"id": 41898282,
54+
"node_id": "MDM6Qm90NDE4OTgyODI=",
55+
"avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
56+
"gravatar_id": "",
57+
"url": "https://api.github.com/users/github-actions%5Bbot%5D",
58+
"html_url": "https://github.com/apps/github-actions",
59+
"followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
60+
"following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
61+
"gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
62+
"starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
63+
"subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
64+
"organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
65+
"repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
66+
"events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
67+
"received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
68+
"type": "Bot",
69+
"user_view_type": "public",
70+
"site_admin": false
71+
},
72+
"node_id": "RE_kwDOJ9RHEc4M_yEM",
73+
"tag_name": "starlight-blog@0.23.2",
74+
"target_commitish": "main",
75+
"name": "starlight-blog@0.23.2",
76+
"draft": false,
77+
"immutable": false,
78+
"prerelease": false,
79+
"created_at": "2025-05-12T16:49:49Z",
80+
"published_at": "2025-05-12T16:49:50Z",
81+
"assets": [
82+
83+
],
84+
"tarball_url": "https://api.github.com/repos/HiDeoo/starlight-blog/tarball/starlight-blog@0.23.2",
85+
"zipball_url": "https://api.github.com/repos/HiDeoo/starlight-blog/zipball/starlight-blog@0.23.2",
86+
"body": null
87+
}
88+
]

packages/starlight-changelogs/providers/github.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ const GitHubApiResponseNextPageRegex = /(?<=<)(?:[\S]*?)[&|?]page=(\d+)(?:[\S]*?
136136

137137
const GitHubApiReleasesSchema = z
138138
.object({
139-
body: z.string(),
139+
body: z
140+
.string()
141+
.nullable()
142+
.transform((val) => val ?? ''),
140143
draft: z.boolean(),
141144
html_url: z.string(),
142145
name: z.string().nullable(),

packages/starlight-changelogs/tests/github.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,30 @@ describe('`null` release name', async () => {
202202
expect(versions[3]?.data.title).toBe(fixture.default[3]?.tag_name)
203203
})
204204
})
205+
206+
describe('`null` release body', async () => {
207+
const fixture = await import('../../../fixtures/github/null-body.json')
208+
209+
beforeAll(async () => {
210+
store.clear()
211+
212+
server.use(
213+
http.get('https://api.github.com/repos/hideoo/starlight-blog/releases', () => HttpResponse.json(fixture.default)),
214+
)
215+
216+
await loadGitHubData(baseConfig, mockLoaderContext(store))
217+
})
218+
219+
test('loads all versions', () => {
220+
expect(store.values().length).toBe(2)
221+
})
222+
223+
test('uses an empty string when the release name is `null`', () => {
224+
const versions = store.values()
225+
226+
expect(fixture.default[1]?.body).toBeNull()
227+
228+
expect(versions[1]?.id).toBe('test/version/starlight-blog-0-23-2')
229+
expect(versions[1]?.body).toBe('')
230+
})
231+
})

0 commit comments

Comments
 (0)