Skip to content

Commit dc9d69c

Browse files
authored
Merge pull request #53 from JasonEtco/add-env-var-support
Add support for environment variables in issue templates
2 parents 7a1eb67 + ef639d9 commit dc9d69c

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,21 @@ title: Someone just pushed
2626
assignees: JasonEtco, matchai
2727
labels: bug, enhancement
2828
---
29-
Someone just pushed, oh no! Here's who did it: {{ payload.sender.login }}
29+
Someone just pushed, oh no! Here's who did it: {{ payload.sender.login }}.
3030
```
3131

32-
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).
32+
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:
33+
34+
```yaml
35+
- uses: JasonEtco/create-an-issue@v2
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
ADJECTIVE: great
39+
```
40+
41+
```markdown
42+
Environment variables are pretty {{ env.ADJECTIVE }}, right?
43+
```
3344

3445
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).
3546

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Toolkit.run(async tools => {
1717

1818
const templateVariables = {
1919
...tools.context,
20+
env: process.env,
2021
date: Date.now()
2122
}
2223

tests/__snapshots__/index.test.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ Array [
132132
`;
133133

134134
exports[`create-an-issue creates a new issue with some template variables 1`] = `
135+
Object {
136+
"assignees": Array [],
137+
"body": "The action create-an-issue is the best action.
138+
139+
Environment variable foo is great.
140+
",
141+
"labels": Array [],
142+
"title": "Hello create-an-issue",
143+
}
144+
`;
145+
146+
exports[`create-an-issue creates a new issue with some template variables 2`] = `
135147
Array [
136148
Array [
137149
"Created issue Hello create-an-issue#1: www",

tests/fixtures/.github/variables.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
22
title: Hello {{ action }}
33
---
4-
The action {{ action }} is the best action.
4+
The action {{ action }} is the best action.
5+
6+
Environment variable {{ env.EXAMPLE }} is great.

tests/index.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ describe('create-an-issue', () => {
4242

4343
// Ensure that the filename input isn't set at the start of a test
4444
delete process.env.INPUT_FILENAME
45+
46+
// Simulate an environment variable added for the action
47+
process.env.EXAMPLE = 'foo'
4548
})
4649

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

0 commit comments

Comments
 (0)