Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assignee input #34

Merged
merged 3 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
assignee: 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:
assignee:
lee-dohm marked this conversation as resolved.
Show resolved Hide resolved
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('assignee')
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_ASSIGNEE = '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_ASSIGNEE = '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