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 support for environment variables in issue templates #53

Merged
merged 16 commits into from
Apr 4, 2020
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