Skip to content

Commit 7352cd8

Browse files
authored
Merge pull request #99 from git-for-windows/avoid-duplicate-issues
Avoid duplicate issues
2 parents d17f52c + dbed57f commit 7352cd8

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
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+
})

dist/index.js

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

77-
const { data: issues } = await octokit.rest.issues.listForRepo({
77+
const { status, data: issues, ...rest } = await octokit.rest.issues.listForRepo({
7878
owner: context.repo.owner,
7979
repo: context.repo.repo,
8080
state: 'all',
8181
labels
8282
})
83+
if (status !== 200) throw new Error(`Failed to list issues: ${status} ${JSON.stringify(rest)}`)
8384
core.debug(`${issues.length} issues`)
8485

8586
const createdIssues = []

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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)