Skip to content

Commit

Permalink
Merge pull request #53 from JasonEtco/add-env-var-support
Browse files Browse the repository at this point in the history
Add support for environment variables in issue templates
  • Loading branch information
JasonEtco committed Apr 4, 2020
2 parents 7a1eb67 + ef639d9 commit dc9d69c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@ title: Someone just pushed
assignees: JasonEtco, matchai
labels: bug, enhancement
---
Someone just pushed, oh no! Here's who did it: {{ payload.sender.login }}
Someone just pushed, oh no! Here's who did it: {{ payload.sender.login }}.
```

You'll notice that the above example has some `{{ mustache }}` variables. Your issue templates have access to everything about the event that triggered the action. [Here is a list of all of the available template variables](https://github.com/JasonEtco/actions-toolkit#toolscontext).
You'll notice that the above example has some `{{ mustache }}` variables. Your issue templates have access to everything about the event that triggered the action. [Here is a list of all of the available template variables](https://github.com/JasonEtco/actions-toolkit#toolscontext). You can also use environment variables:

```yaml
- uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ADJECTIVE: great
```

```markdown
Environment variables are pretty {{ env.ADJECTIVE }}, right?
```

Note that you can only assign people matching given [conditions](https://help.github.com/en/github/managing-your-work-on-github/assigning-issues-and-pull-requests-to-other-github-users).

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Toolkit.run(async tools => {

const templateVariables = {
...tools.context,
env: process.env,
date: Date.now()
}

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

exports[`create-an-issue creates a new issue with some template variables 1`] = `
Object {
"assignees": Array [],
"body": "The action create-an-issue is the best action.
Environment variable foo is great.
",
"labels": Array [],
"title": "Hello create-an-issue",
}
`;

exports[`create-an-issue creates a new issue with some template variables 2`] = `
Array [
Array [
"Created issue Hello create-an-issue#1: www",
Expand Down
4 changes: 3 additions & 1 deletion tests/fixtures/.github/variables.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
title: Hello {{ action }}
---
The action {{ action }} is the best action.
The action {{ action }} is the best action.

Environment variable {{ env.EXAMPLE }} is great.
4 changes: 4 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ describe('create-an-issue', () => {

// Ensure that the filename input isn't set at the start of a test
delete process.env.INPUT_FILENAME

// Simulate an environment variable added for the action
process.env.EXAMPLE = 'foo'
})

it('creates a new issue', async () => {
Expand Down Expand Up @@ -69,6 +72,7 @@ describe('create-an-issue', () => {
it('creates a new issue with some template variables', async () => {
process.env.INPUT_FILENAME = '.github/variables.md'
await actionFn(tools)
expect(params).toMatchSnapshot()
expect(tools.log.success).toHaveBeenCalled()
expect(tools.log.success.mock.calls).toMatchSnapshot()
})
Expand Down

0 comments on commit dc9d69c

Please sign in to comment.