Skip to content

Commit

Permalink
Merge pull request #25 from JasonEtco/inputs
Browse files Browse the repository at this point in the history
Use inputs instead of args for custom filename
  • Loading branch information
JasonEtco committed Sep 16, 2019
2 parents 9af9111 + 3285e0c commit 58a4ce2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ This example will create a new issue with a title like **Weekly Radar Saturday,

### Custom templates

Don't want to use `.github/ISSUE_TEMPLATE.md`? You can pass an argument pointing the action to a different template:
Don't want to use `.github/ISSUE_TEMPLATE.md`? You can pass an input pointing the action to a different template:

```yaml
steps:
- uses: JasonEtco/create-an-issue@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: .github/some-other-template.md
filename: .github/some-other-template.md
```
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ runs:
branding:
icon: alert-circle
color: gray-dark
inputs:
filename:
description: The name of the file to use as the issue template
default: .github/ISSUE_TEMPLATE.md
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const core = require('@actions/core')
const { Toolkit } = require('actions-toolkit')
const fm = require('front-matter')
const nunjucks = require('nunjucks')
Expand All @@ -9,7 +10,7 @@ function listToArray (list) {
}

Toolkit.run(async tools => {
const template = tools.arguments._[0] || '.github/ISSUE_TEMPLATE.md'
const template = core.getInput('filename') || '.github/ISSUE_TEMPLATE.md'
const env = nunjucks.configure({ autoescape: false })
env.addFilter('date', dateFilter)

Expand Down
35 changes: 20 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "Jason Etcovitch <jasonetco@gmail.com>",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.1.0",
"actions-toolkit": "^2.2.0",
"front-matter": "^3.0.2",
"js-yaml": "^3.13.1",
Expand Down
11 changes: 7 additions & 4 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ describe('create-an-issue', () => {

tools.exit.success = jest.fn()
tools.exit.failure = jest.fn()

// Ensure that the filename input isn't set at the start of a test
delete process.env.INPUT_FILENAME
})

it('creates a new issue', async () => {
Expand All @@ -41,7 +44,7 @@ describe('create-an-issue', () => {
})

it('creates a new issue from a different template', async () => {
tools.arguments._ = ['.github/different-template.md']
process.env.INPUT_FILENAME = '.github/different-template.md'
tools.context.payload = { repository: { owner: { login: 'JasonEtco' }, name: 'waddup' } }
await actionFn(tools)
expect(params).toMatchSnapshot()
Expand All @@ -50,22 +53,22 @@ describe('create-an-issue', () => {
})

it('creates a new issue with some template variables', async () => {
tools.arguments._[0] = '.github/variables.md'
process.env.INPUT_FILENAME = '.github/variables.md'
await actionFn(tools)
expect(tools.log.success).toHaveBeenCalled()
expect(tools.log.success.mock.calls).toMatchSnapshot()
})

it('creates a new issue with assignees, labels and a milestone', async () => {
tools.arguments._[0] = '.github/kitchen-sink.md'
process.env.INPUT_FILENAME = '.github/kitchen-sink.md'
await actionFn(tools)
expect(params).toMatchSnapshot()
expect(tools.log.success).toHaveBeenCalled()
expect(tools.log.success.mock.calls).toMatchSnapshot()
})

it('creates a new issue with assignees and labels as comma-delimited strings', async () => {
tools.arguments._[0] = '.github/split-strings.md'
process.env.INPUT_FILENAME = '.github/split-strings.md'
await actionFn(tools)
expect(params).toMatchSnapshot()
expect(tools.log.success).toHaveBeenCalled()
Expand Down

0 comments on commit 58a4ce2

Please sign in to comment.