Skip to content

Commit 3eebcfd

Browse files
committed
Check value of update_existing for true/false.
1 parent ae43a78 commit 3eebcfd

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/action.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ import { FrontMatterAttributes, listToArray, setOutputs } from './helpers'
99
export async function createAnIssue (tools: Toolkit) {
1010
const template = tools.inputs.filename || '.github/ISSUE_TEMPLATE.md'
1111
const assignees = tools.inputs.assignees
12-
const updateExisting: Boolean | null = tools.inputs.update_existing ? tools.inputs.update_existing === 'true' : null
12+
let updateExisting: Boolean | null = null
13+
if (tools.inputs.update_existing) {
14+
if (tools.inputs.update_existing === 'true') {
15+
updateExisting = true
16+
} else if (tools.inputs.update_existing === 'false') {
17+
updateExisting = false
18+
} else {
19+
tools.exit.failure(`Invalid value update_existing=${tools.inputs.update_existing}, must be one of true or false`)
20+
}
21+
}
1322
const env = nunjucks.configure({ autoescape: false })
1423
env.addFilter('date', dateFilter)
1524

@@ -46,7 +55,7 @@ export async function createAnIssue (tools: Toolkit) {
4655
tools.exit.failure(err)
4756
}
4857
if (existingIssue) {
49-
if (! updateExisting) {
58+
if (updateExisting === false) {
5059
tools.exit.success(`Existing issue ${existingIssue.title}#${existingIssue.number}: ${existingIssue.html_url} found but not updated`)
5160
} else {
5261
try {

tests/__snapshots__/index.test.ts.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`create-an-issue checks the value of update_existing 1`] = `
4+
Object {
5+
"assignees": Array [
6+
"octocat",
7+
"JasonEtco",
8+
],
9+
"body": "Goodbye!",
10+
"labels": Array [],
11+
"milestone": 1,
12+
"title": "Hello!",
13+
}
14+
`;
15+
316
exports[`create-an-issue creates a new issue 1`] = `
417
Object {
518
"assignees": Array [],

tests/index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ describe('create-an-issue', () => {
151151
expect(tools.log.success).toHaveBeenCalled()
152152
})
153153

154+
it('checks the value of update_existing', async () => {
155+
process.env.INPUT_UPDATE_EXISTING = 'invalid'
156+
157+
await createAnIssue(tools)
158+
expect(params).toMatchSnapshot()
159+
expect(tools.exit.failure).toHaveBeenCalledWith('Invalid value update_existing=invalid, must be one of true or false')
160+
})
161+
154162
it('updates an existing issue with the same title', async () => {
155163
nock.cleanAll()
156164
nock('https://api.github.com')

0 commit comments

Comments
 (0)