Skip to content

Commit

Permalink
Merge pull request #35 from lee-dohm/output-url
Browse files Browse the repository at this point in the history
Add number and url outputs
  • Loading branch information
JasonEtco committed Dec 5, 2019
2 parents 96a7a1a + 73b6555 commit afe6c80
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,17 @@ steps:
with:
assignees: JasonEtco, octocat
```

### Outputs

If you need the number or URL of the issue that was created for another Action, you can use the `number` or `url` outputs, respectively. For example:

```yaml
steps:
- uses: JasonEtco/create-an-issue@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: create-issue
- run: 'echo Created issue number ${{ steps.create-issue.outputs.number }}'
- run: 'echo Created ${{ steps.create-issue.outputs.url }}'
```
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ inputs:
filename:
description: The name of the file to use as the issue template
default: .github/ISSUE_TEMPLATE.md
outputs:
number:
description: Number of the issue that was created
url:
description: URL of the issue that was created
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Toolkit.run(async tools => {
milestone: attributes.milestone
})

core.setOutput('number', issue.data.number)
core.setOutput('url', issue.data.html_url)
tools.log.success(`Created issue ${issue.data.title}#${issue.data.number}: ${issue.data.html_url}`)
} catch (err) {
// Log the error message
Expand Down
10 changes: 10 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const nock = require('nock')
const core = require('@actions/core')
const { Toolkit } = require('actions-toolkit')

describe('create-an-issue', () => {
Expand Down Expand Up @@ -28,6 +29,10 @@ describe('create-an-issue', () => {
}
})

// Turn core.setOutput into a mocked noop
jest.spyOn(core, 'setOutput')
.mockImplementation(() => {})

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

Expand All @@ -41,6 +46,11 @@ describe('create-an-issue', () => {
expect(params).toMatchSnapshot()
expect(tools.log.success).toHaveBeenCalled()
expect(tools.log.success.mock.calls).toMatchSnapshot()

// Verify that the outputs were set
expect(core.setOutput).toHaveBeenCalledTimes(2)
expect(core.setOutput).toHaveBeenCalledWith('url', 'www')
expect(core.setOutput).toHaveBeenCalledWith('number', 1)
})

it('creates a new issue from a different template', async () => {
Expand Down

0 comments on commit afe6c80

Please sign in to comment.