From 277e9c1ad8c1d83ee44ce6c180c44060fb8c659d Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Thu, 1 Dec 2022 14:35:37 -0500 Subject: [PATCH] Don't include is:all in issue filter --- src/action.ts | 14 ++++++++++---- tests/index.test.ts | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/action.ts b/src/action.ts index 5bb31eb..8a661f3 100644 --- a/src/action.ts +++ b/src/action.ts @@ -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) { @@ -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) { diff --git a/tests/index.test.ts b/tests/index.test.ts index b871e7e..a8fe8a7 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -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 }