Skip to content

Commit e49cf1c

Browse files
committed
Fail when issues could not be listed
As of a couple of weeks ago, GitHub seems to have serious issues with reliability, where the issues sometimes fail to be listed. Those issues revealed that this here Action failed to inspect the returned HTTP status (which was previously unnecessary because it was always 200, but this now apparently is no longer as reliable). Let's inspect the `status` attribute to find out, and complain loudly instead of opening duplicate issues. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent d17f52c commit e49cf1c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

__tests__/index.test.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ test('handles feed entries without titles', async () => {
6161
const date = '2021-06-19T01:01:29+12:00'
6262
mockHTTPSGet.__RETURN__ = `<feed xmlns="http://www.w3.org/2005/Atom"><entry><published>${date}</published><content type="html">TBD</content></entry></feed>`
6363
core.__INPUTS__['max-age'] = '9999d'
64-
octokit.rest.issues.listForRepo.mockReturnValueOnce({ data: [] })
64+
octokit.rest.issues.listForRepo.mockReturnValueOnce({ status: 200, data: [] })
6565
await run()
6666

6767
expect(https.get).toHaveBeenCalledTimes(1)
@@ -105,7 +105,7 @@ Signed-off-by: Johannes Schindelin &amp;lt;johannes.schindelin@gmx.de&amp;gt;&lt
105105
</entry>
106106
</feed>
107107
`
108-
octokit.rest.issues.listForRepo.mockReturnValueOnce({ data: [] })
108+
octokit.rest.issues.listForRepo.mockReturnValueOnce({ status: 200, data: [] })
109109
await run()
110110

111111
expect(octokit.rest.issues.create).toHaveBeenCalledWith({
@@ -166,7 +166,7 @@ test('curl -rc versions', async () => {
166166
<media:thumbnail height="30" width="30" url="https://avatars.githubusercontent.com/u/177011?s=60&amp;v=4"/>
167167
</entry>
168168
</feed>`
169-
octokit.rest.issues.listForRepo.mockReturnValueOnce({ data: [] })
169+
octokit.rest.issues.listForRepo.mockReturnValueOnce({ status: 200, data: [] })
170170
Object.assign(core.__INPUTS__, {
171171
'max-age': '9999d',
172172
prefix: '[New curl version]',
@@ -185,3 +185,18 @@ test('curl -rc versions', async () => {
185185
labels: undefined
186186
})
187187
})
188+
189+
test('errors out if GitHub API returns 500', async () => {
190+
mockHTTPSGet.__RETURN__ = `<?xml version="1.0" encoding="UTF-8"?>
191+
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
192+
<entry>
193+
<title>Hello></title>
194+
<published>${new Date().toUTCString()}</published>
195+
<content type="html">TBD</content>
196+
</entry>
197+
</feed>`
198+
octokit.rest.issues.listForRepo.mockReturnValueOnce({ status: 500, data: [], message: 'Server Error' })
199+
// Expect an error to be thrown
200+
await expect(run()).rejects.toThrow('Failed to list issues: 500 {"message":"Server Error"}')
201+
expect(octokit.rest.issues.listForRepo).toHaveBeenCalledTimes(1)
202+
})

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ const run = async () => {
6868
// Remove old items in feed
6969
feed.items = feed.items.filter(x => x.pubDate === undefined || limitTime < new Date(x.pubDate).getTime())
7070

71-
const { data: issues } = await octokit.rest.issues.listForRepo({
71+
const { status, data: issues, ...rest } = await octokit.rest.issues.listForRepo({
7272
owner: context.repo.owner,
7373
repo: context.repo.repo,
7474
state: 'all',
7575
labels
7676
})
77+
if (status !== 200) throw new Error(`Failed to list issues: ${status} ${JSON.stringify(rest)}`)
7778
core.debug(`${issues.length} issues`)
7879

7980
const createdIssues = []

0 commit comments

Comments
 (0)