Skip to content

Commit

Permalink
Merge pull request #11 from JasonEtco/sting-delimited
Browse files Browse the repository at this point in the history
Comma delimited lists
  • Loading branch information
JasonEtco authored May 2, 2019
2 parents 0eb5acf + 852e422 commit 5c1234b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ This reads from the `.github/ISSUE_TEMPLATE.md` file. This file should have fron
```markdown
---
title: Someone just pushed
assignees:
- JasonEtco
labels:
- bug
assignees: JasonEtco, matchai
labels: bug, enhancement
---
Someone just pushed, oh no! Here's who did it: {{ payload.sender.login }}
```
Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const fm = require('front-matter')
const nunjucks = require('nunjucks')
const dateFilter = require('nunjucks-date-filter')

function listToArray (list) {
if (!list) return []
return Array.isArray(list) ? list : list.split(', ')
}

Toolkit.run(async tools => {
const template = tools.arguments._[0] || '.github/ISSUE_TEMPLATE.md'
const env = nunjucks.configure({ autoescape: false })
Expand Down Expand Up @@ -33,8 +38,8 @@ Toolkit.run(async tools => {
const issue = await tools.github.issues.create({
...tools.context.repo,
...templated,
assignees: attributes.assignees || [],
labels: attributes.labels || [],
assignees: listToArray(attributes.assignees),
labels: listToArray(attributes.labels),
milestone: attributes.milestone
})

Expand Down
23 changes: 23 additions & 0 deletions tests/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ Array [
]
`;

exports[`create-an-issue creates a new issue with assignees and labels as comma-delimited strings 1`] = `
Object {
"assignees": Array [
"JasonEtco",
"matchai",
],
"body": "The action create-an-issue is the best action.",
"labels": Array [
"bug",
"enhancement",
],
"title": "DO EVERYTHING",
}
`;

exports[`create-an-issue creates a new issue with assignees and labels as comma-delimited strings 2`] = `
Array [
Array [
"Created issue DO EVERYTHING#1: www",
],
]
`;

exports[`create-an-issue creates a new issue with assignees, labels and a milestone 1`] = `
Object {
"assignees": Array [
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/.github/split-strings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: DO EVERYTHING
assignees: JasonEtco, matchai
labels: bug, enhancement
---
The action {{ action }} is the best action.
8 changes: 8 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ describe('create-an-issue', () => {
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'
await actionFn(tools)
expect(params).toMatchSnapshot()
expect(tools.log.success).toHaveBeenCalled()
expect(tools.log.success.mock.calls).toMatchSnapshot()
})
})

0 comments on commit 5c1234b

Please sign in to comment.