Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test('handles feed entries without titles', async () => {
const date = '2021-06-19T01:01:29+12:00'
mockHTTPSGet.__RETURN__ = `<feed xmlns="http://www.w3.org/2005/Atom"><entry><published>${date}</published><content type="html">TBD</content></entry></feed>`
core.__INPUTS__['max-age'] = '9999d'
octokit.rest.issues.listForRepo.mockReturnValueOnce({ data: [] })
octokit.rest.issues.listForRepo.mockReturnValueOnce({ status: 200, data: [] })
await run()

expect(https.get).toHaveBeenCalledTimes(1)
Expand Down Expand Up @@ -105,7 +105,7 @@ Signed-off-by: Johannes Schindelin &amp;lt;[email protected]&amp;gt;&lt
</entry>
</feed>
`
octokit.rest.issues.listForRepo.mockReturnValueOnce({ data: [] })
octokit.rest.issues.listForRepo.mockReturnValueOnce({ status: 200, data: [] })
await run()

expect(octokit.rest.issues.create).toHaveBeenCalledWith({
Expand Down Expand Up @@ -166,7 +166,7 @@ test('curl -rc versions', async () => {
<media:thumbnail height="30" width="30" url="https://avatars.githubusercontent.com/u/177011?s=60&amp;v=4"/>
</entry>
</feed>`
octokit.rest.issues.listForRepo.mockReturnValueOnce({ data: [] })
octokit.rest.issues.listForRepo.mockReturnValueOnce({ status: 200, data: [] })
Object.assign(core.__INPUTS__, {
'max-age': '9999d',
prefix: '[New curl version]',
Expand All @@ -185,3 +185,18 @@ test('curl -rc versions', async () => {
labels: undefined
})
})

test('errors out if GitHub API returns 500', async () => {
mockHTTPSGet.__RETURN__ = `<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
<entry>
<title>Hello></title>
<published>${new Date().toUTCString()}</published>
<content type="html">TBD</content>
</entry>
</feed>`
octokit.rest.issues.listForRepo.mockReturnValueOnce({ status: 500, data: [], message: 'Server Error' })
// Expect an error to be thrown
await expect(run()).rejects.toThrow('Failed to list issues: 500 {"message":"Server Error"}')
expect(octokit.rest.issues.listForRepo).toHaveBeenCalledTimes(1)
})
3 changes: 2 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ const run = async () => {
// Remove old items in feed
feed.items = feed.items.filter(x => x.pubDate === undefined || limitTime < new Date(x.pubDate).getTime())

const { data: issues } = await octokit.rest.issues.listForRepo({
const { status, data: issues, ...rest } = await octokit.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
labels
})
if (status !== 200) throw new Error(`Failed to list issues: ${status} ${JSON.stringify(rest)}`)
core.debug(`${issues.length} issues`)

const createdIssues = []
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ const run = async () => {
// Remove old items in feed
feed.items = feed.items.filter(x => x.pubDate === undefined || limitTime < new Date(x.pubDate).getTime())

const { data: issues } = await octokit.rest.issues.listForRepo({
const { status, data: issues, ...rest } = await octokit.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
labels
})
if (status !== 200) throw new Error(`Failed to list issues: ${status} ${JSON.stringify(rest)}`)
core.debug(`${issues.length} issues`)

const createdIssues = []
Expand Down