Skip to content

Commit

Permalink
Merge pull request #34 from lee-dohm/assignee-input
Browse files Browse the repository at this point in the history
Add assignee input
  • Loading branch information
JasonEtco committed Dec 4, 2019
2 parents d9b3e15 + 3a80790 commit 96a7a1a
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
stuff:
steps:
- uses: JasonEtco/create-an-issue@master
env:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

Expand Down Expand Up @@ -52,8 +52,22 @@ Don't want to use `.github/ISSUE_TEMPLATE.md`? You can pass an input pointing th
steps:
- uses: actions/checkout@master
- uses: JasonEtco/create-an-issue@master
env:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
filename: .github/some-other-template.md
```

### Assignee input

Want to use Action logic to determine who to assign the issue to? You can pass an input containing the assignee list:

```yaml
steps:
- uses: actions/checkout@master
- uses: JasonEtco/create-an-issue@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
assignees: JasonEtco, octocat
```
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ branding:
icon: alert-circle
color: gray-dark
inputs:
assignees:
description: GitHub handle of the user(s) to assign the issue (comma-separated)
filename:
description: The name of the file to use as the issue template
default: .github/ISSUE_TEMPLATE.md
default: .github/ISSUE_TEMPLATE.md
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function listToArray (list) {

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

Expand Down Expand Up @@ -40,7 +41,7 @@ Toolkit.run(async tools => {
const issue = await tools.github.issues.create({
...tools.context.repo,
...templated,
assignees: listToArray(attributes.assignees),
assignees: assignees ? listToArray(assignees) : listToArray(attributes.assignees),
labels: listToArray(attributes.labels),
milestone: attributes.milestone
})
Expand Down
56 changes: 56 additions & 0 deletions tests/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ Array [
]
`;

exports[`create-an-issue creates a new issue with an assignee passed by input 1`] = `
Object {
"assignees": Array [],
"body": "Goodbye!",
"labels": Array [],
"title": "Hello!",
}
`;

exports[`create-an-issue creates a new issue with an assignee passed by input 2`] = `
Array [
Array [
"Created issue Hello!#1: www",
],
]
`;

exports[`create-an-issue creates a new issue with assignees and labels as comma-delimited strings 1`] = `
Object {
"assignees": Array [
Expand Down Expand Up @@ -87,6 +104,45 @@ Array [
]
`;

exports[`create-an-issue creates a new issue with an assignee passed by input 1`] = `
Object {
"assignees": Array [
"octocat",
],
"body": "Goodbye!",
"labels": Array [],
"title": "Hello!",
}
`;

exports[`create-an-issue creates a new issue with an assignee passed by input 2`] = `
Array [
Array [
"Created issue Hello!#1: www",
],
]
`;

exports[`create-an-issue creates a new issue with multiple assignees passed by input 1`] = `
Object {
"assignees": Array [
"octocat",
"JasonEtco",
],
"body": "Goodbye!",
"labels": Array [],
"title": "Hello!",
}
`;

exports[`create-an-issue creates a new issue with multiple assignees passed by input 2`] = `
Array [
Array [
"Created issue Hello!#1: www",
],
]
`;

exports[`create-an-issue logs a helpful error if creating an issue throws an error 1`] = `
Array [
Array [
Expand Down
16 changes: 16 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ describe('create-an-issue', () => {
expect(tools.log.success.mock.calls).toMatchSnapshot()
})

it('creates a new issue with an assignee passed by input', async () => {
process.env.INPUT_ASSIGNEES = 'octocat'
await actionFn(tools)
expect(params).toMatchSnapshot()
expect(tools.log.success).toHaveBeenCalled()
expect(tools.log.success.mock.calls).toMatchSnapshot()
})

it('creates a new issue with multiple assignees passed by input', async () => {
process.env.INPUT_ASSIGNEES = 'octocat, JasonEtco'
await actionFn(tools)
expect(params).toMatchSnapshot()
expect(tools.log.success).toHaveBeenCalled()
expect(tools.log.success.mock.calls).toMatchSnapshot()
})

it('logs a helpful error if creating an issue throws an error', async () => {
nock.cleanAll()
nock('https://api.github.com')
Expand Down

0 comments on commit 96a7a1a

Please sign in to comment.