Skip to content

Commit

Permalink
Merge pull request #140 from JasonEtco/fix-search-all
Browse files Browse the repository at this point in the history
Don't include `is:all` in issue filter
  • Loading branch information
JasonEtco authored Dec 1, 2022
2 parents a2b2af1 + 277e9c1 commit 638725f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function logError(tools: Toolkit, template: string, action: 'creating' | 'updati
export async function createAnIssue (tools: Toolkit) {
const template = tools.inputs.filename || '.github/ISSUE_TEMPLATE.md'
const assignees = tools.inputs.assignees
const searchExistingType = tools.inputs.search_existing || 'open'

let updateExisting: Boolean | null = null
if (tools.inputs.update_existing) {
Expand Down Expand Up @@ -62,9 +61,16 @@ export async function createAnIssue (tools: Toolkit) {

if (updateExisting !== null) {
tools.log.info(`Fetching issues with title "${templated.title}"`)
const existingIssues = await tools.github.search.issuesAndPullRequests({
q: `is:${searchExistingType} is:issue repo:${process.env.GITHUB_REPOSITORY} in:title ${templated.title}`
})

let query = `is:issue repo:${process.env.GITHUB_REPOSITORY} in:title ${templated.title}`

const searchExistingType = tools.inputs.search_existing || 'open'
const allowedStates = ['open', 'closed']
if (allowedStates.includes(searchExistingType)) {
query += ` is:${searchExistingType}`
}

const existingIssues = await tools.github.search.issuesAndPullRequests({ q: query })
const existingIssue = existingIssues.data.items.find(issue => issue.title === templated.title)
if (existingIssue) {
if (updateExisting === false) {
Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe('create-an-issue', () => {
const q = parsedQuery['q']
if (typeof(q) === 'string') {
const args = q.split(' ')
return args.includes('is:all') && args.includes('is:issue')
return !args.includes('is:all') && args.includes('is:issue')
} else {
return false
}
Expand Down

0 comments on commit 638725f

Please sign in to comment.