Skip to content

Commit 5c1234b

Browse files
authored
Merge pull request #11 from JasonEtco/sting-delimited
Comma delimited lists
2 parents 0eb5acf + 852e422 commit 5c1234b

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ This reads from the `.github/ISSUE_TEMPLATE.md` file. This file should have fron
2323
```markdown
2424
---
2525
title: Someone just pushed
26-
assignees:
27-
- JasonEtco
28-
labels:
29-
- bug
26+
assignees: JasonEtco, matchai
27+
labels: bug, enhancement
3028
---
3129
Someone just pushed, oh no! Here's who did it: {{ payload.sender.login }}
3230
```

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ const fm = require('front-matter')
33
const nunjucks = require('nunjucks')
44
const dateFilter = require('nunjucks-date-filter')
55

6+
function listToArray (list) {
7+
if (!list) return []
8+
return Array.isArray(list) ? list : list.split(', ')
9+
}
10+
611
Toolkit.run(async tools => {
712
const template = tools.arguments._[0] || '.github/ISSUE_TEMPLATE.md'
813
const env = nunjucks.configure({ autoescape: false })
@@ -33,8 +38,8 @@ Toolkit.run(async tools => {
3338
const issue = await tools.github.issues.create({
3439
...tools.context.repo,
3540
...templated,
36-
assignees: attributes.assignees || [],
37-
labels: attributes.labels || [],
41+
assignees: listToArray(attributes.assignees),
42+
labels: listToArray(attributes.labels),
3843
milestone: attributes.milestone
3944
})
4045

tests/__snapshots__/index.test.js.snap

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@ Array [
3434
]
3535
`;
3636

37+
exports[`create-an-issue creates a new issue with assignees and labels as comma-delimited strings 1`] = `
38+
Object {
39+
"assignees": Array [
40+
"JasonEtco",
41+
"matchai",
42+
],
43+
"body": "The action create-an-issue is the best action.",
44+
"labels": Array [
45+
"bug",
46+
"enhancement",
47+
],
48+
"title": "DO EVERYTHING",
49+
}
50+
`;
51+
52+
exports[`create-an-issue creates a new issue with assignees and labels as comma-delimited strings 2`] = `
53+
Array [
54+
Array [
55+
"Created issue DO EVERYTHING#1: www",
56+
],
57+
]
58+
`;
59+
3760
exports[`create-an-issue creates a new issue with assignees, labels and a milestone 1`] = `
3861
Object {
3962
"assignees": Array [
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: DO EVERYTHING
3+
assignees: JasonEtco, matchai
4+
labels: bug, enhancement
5+
---
6+
The action {{ action }} is the best action.

tests/index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,12 @@ describe('create-an-issue', () => {
6262
expect(tools.log.success).toHaveBeenCalled()
6363
expect(tools.log.success.mock.calls).toMatchSnapshot()
6464
})
65+
66+
it('creates a new issue with assignees and labels as comma-delimited strings', async () => {
67+
tools.arguments._[0] = '.github/split-strings.md'
68+
await actionFn(tools)
69+
expect(params).toMatchSnapshot()
70+
expect(tools.log.success).toHaveBeenCalled()
71+
expect(tools.log.success.mock.calls).toMatchSnapshot()
72+
})
6573
})

0 commit comments

Comments
 (0)