Skip to content

Commit

Permalink
Search for all issues instead of open, closed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Sep 28, 2021
1 parent 73b6fe8 commit bee3c89
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ steps:
assignees: JasonEtco, octocat
milestone: 1
update_existing: true
search_existing: open, closed
search_existing: all
```

The `assignees` and `milestone` speak for themselves.
The `update_existing` param can be passed and set to `true` when you want to update an open issue with the **exact same title** when it exists.
The `search_existing` param lets you specify whether to search open and/or closed existing issues for duplicates (default is `open`).
* The `assignees` and `milestone` speak for themselves.
* The `update_existing` param can be passed and set to `true` when you want to update an open issue with the **exact same title** when it exists.
* The `search_existing` param lets you specify whether to search `open`, `closed`, or `all` existing issues for duplicates (default is `open`).

### Outputs

Expand Down
15 changes: 5 additions & 10 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function createAnIssue (tools: Toolkit) {
const template = tools.inputs.filename || '.github/ISSUE_TEMPLATE.md'
const assignees = tools.inputs.assignees
const updateExisting = Boolean(tools.inputs.update_existing)
const searchExistingTypes = (tools.inputs.search_existing || 'open').split(',').map(s => s.trim());
const searchExistingType = tools.inputs.search_existing || 'open'
const env = nunjucks.configure({ autoescape: false })
env.addFilter('date', dateFilter)

Expand Down Expand Up @@ -40,16 +40,11 @@ export async function createAnIssue (tools: Toolkit) {
tools.log.info(`Fetching issues with title "${templated.title}"`)
try {

// Fetch existing issues that match title
const issues = (await Promise.all(searchExistingTypes.map(s => {
return tools.github.search.issuesAndPullRequests({
q: `is:${s} is:issue repo:${process.env.GITHUB_REPOSITORY} in:title ${templated.title}`
}).then(existingIssues => {
return existingIssues.data.items
})})
)).flat()
const existingIssues = await tools.github.search.issuesAndPullRequests({
q: `is:${searchExistingType} is:issue repo:${process.env.GITHUB_REPOSITORY} in:title ${templated.title}`
})

existingIssue = issues.find(issue => issue.title === templated.title)
existingIssue = existingIssues.data.items.find(issue => issue.title === templated.title)

} catch (err) {
tools.exit.failure(err)
Expand Down
20 changes: 3 additions & 17 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,7 @@ describe('create-an-issue', () => {
var q = parsedQuery['q']
if (typeof(q) === 'string') {
var args = q.split(' ')
return args.includes('is:open') && args.includes('is:issue')
} else {
return false
}
})
.reply(200, {
items: []
})
// matching closed issue
.get(/\/search\/issues.*/)
.query(parsedQuery => {
var q = parsedQuery['q']
if (typeof(q) === 'string') {
var args = q.split(' ')
return args.includes('is:closed') && args.includes('is:issue')
return args.includes('is:all') && args.includes('is:issue')
} else {
return false
}
Expand All @@ -211,12 +197,12 @@ describe('create-an-issue', () => {
.patch(/\/repos\/.*\/.*\/issues\/.*/).reply(200, {})

process.env.INPUT_UPDATE_EXISTING = 'true'
process.env.INPUT_SEARCH_EXISTING = 'open, closed'
process.env.INPUT_SEARCH_EXISTING = 'all'

await createAnIssue(tools)
expect(params).toMatchSnapshot()
expect(tools.exit.success).toHaveBeenCalled()
})
})

it('exits when updating an issue fails', async () => {
nock.cleanAll()
Expand Down

0 comments on commit bee3c89

Please sign in to comment.