From bd722a788df45eda37accf85df560f56f501f6de Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Fri, 3 Apr 2020 20:47:58 +0100 Subject: [PATCH 01/16] Update index.js --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 16dce00..9dc4217 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ Toolkit.run(async tools => { const templateVariables = { ...tools.context, + env: process.env, date: Date.now() } From d9b44608a8ab23b8c2c3cd236fc40f3c5327a4d5 Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Fri, 3 Apr 2020 20:58:58 +0100 Subject: [PATCH 02/16] Update variables.md --- tests/fixtures/.github/variables.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/.github/variables.md b/tests/fixtures/.github/variables.md index 4f7b94a..3004042 100644 --- a/tests/fixtures/.github/variables.md +++ b/tests/fixtures/.github/variables.md @@ -1,4 +1,5 @@ --- title: Hello {{ action }} --- -The action {{ action }} is the best action. \ No newline at end of file +The action {{ action }} is the best action. +An `env` variable will be displayed here: {{env_test}}! From 5b89c9975157485044fc139c06897884776d26d4 Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Fri, 3 Apr 2020 21:01:52 +0100 Subject: [PATCH 03/16] Create test-issue-env.yml --- .github/workflows/test-issue-env.yml | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/test-issue-env.yml diff --git a/.github/workflows/test-issue-env.yml b/.github/workflows/test-issue-env.yml new file mode 100644 index 0000000..a9d731d --- /dev/null +++ b/.github/workflows/test-issue-env.yml @@ -0,0 +1,34 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: test-issue-env + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + +# strategy: +# matrix: +# node-version: [10.x, 12.x] + + steps: + - uses: actions/checkout@v2 +# - name: Use Node.js ${{ matrix.node-version }} +# uses: actions/setup-node@v1 +# with: +# node-version: ${{ matrix.node-version }} +# - run: npm ci +# - run: npm run build --if-present + - uses: sunt05/create-an-issue@master + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + test: 'a simple test message' + with: + filename: '.github/variables.md' From bbc788703929fa926c7d08e38bc1dc92ff5d469f Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Fri, 3 Apr 2020 21:04:26 +0100 Subject: [PATCH 04/16] Update test-issue-env.yml --- .github/workflows/test-issue-env.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-issue-env.yml b/.github/workflows/test-issue-env.yml index a9d731d..a4a9598 100644 --- a/.github/workflows/test-issue-env.yml +++ b/.github/workflows/test-issue-env.yml @@ -31,4 +31,4 @@ jobs: GITHUB_TOKEN: ${{ secrets.PAT }} test: 'a simple test message' with: - filename: '.github/variables.md' + filename: 'tests/fixtures/.github/variables.md' From 62ed4c3ac0cf3f057a163208cc3bc9ab2935c7d0 Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Fri, 3 Apr 2020 21:21:58 +0100 Subject: [PATCH 05/16] Update test-issue-env.yml --- .github/workflows/test-issue-env.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-issue-env.yml b/.github/workflows/test-issue-env.yml index a4a9598..c677819 100644 --- a/.github/workflows/test-issue-env.yml +++ b/.github/workflows/test-issue-env.yml @@ -29,6 +29,6 @@ jobs: - uses: sunt05/create-an-issue@master env: GITHUB_TOKEN: ${{ secrets.PAT }} - test: 'a simple test message' + env_test: 'a simple test message' with: filename: 'tests/fixtures/.github/variables.md' From c6fe68a65cff36b10b285ecd437ce098672f475e Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Fri, 3 Apr 2020 21:26:59 +0100 Subject: [PATCH 06/16] Update variables.md --- tests/fixtures/.github/variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/.github/variables.md b/tests/fixtures/.github/variables.md index 3004042..36b39bd 100644 --- a/tests/fixtures/.github/variables.md +++ b/tests/fixtures/.github/variables.md @@ -2,4 +2,4 @@ title: Hello {{ action }} --- The action {{ action }} is the best action. -An `env` variable will be displayed here: {{env_test}}! +An `env` variable will be displayed here: {{env}}! From 72d2cca80a109c5b86bd271ad23ffe39e05f177a Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Fri, 3 Apr 2020 21:29:53 +0100 Subject: [PATCH 07/16] Update variables.md --- tests/fixtures/.github/variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/.github/variables.md b/tests/fixtures/.github/variables.md index 36b39bd..3c1ba87 100644 --- a/tests/fixtures/.github/variables.md +++ b/tests/fixtures/.github/variables.md @@ -2,4 +2,4 @@ title: Hello {{ action }} --- The action {{ action }} is the best action. -An `env` variable will be displayed here: {{env}}! +An `env` variable will be displayed here: {{env.env_test}}! From d1e9ab4f79f7a4e5fbc32073f2813531b1b76343 Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Fri, 3 Apr 2020 21:55:57 +0100 Subject: [PATCH 08/16] Delete test-issue-env.yml --- .github/workflows/test-issue-env.yml | 34 ---------------------------- 1 file changed, 34 deletions(-) delete mode 100644 .github/workflows/test-issue-env.yml diff --git a/.github/workflows/test-issue-env.yml b/.github/workflows/test-issue-env.yml deleted file mode 100644 index c677819..0000000 --- a/.github/workflows/test-issue-env.yml +++ /dev/null @@ -1,34 +0,0 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: test-issue-env - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - -# strategy: -# matrix: -# node-version: [10.x, 12.x] - - steps: - - uses: actions/checkout@v2 -# - name: Use Node.js ${{ matrix.node-version }} -# uses: actions/setup-node@v1 -# with: -# node-version: ${{ matrix.node-version }} -# - run: npm ci -# - run: npm run build --if-present - - uses: sunt05/create-an-issue@master - env: - GITHUB_TOKEN: ${{ secrets.PAT }} - env_test: 'a simple test message' - with: - filename: 'tests/fixtures/.github/variables.md' From ec216fde4a8a24fcbc533f513a88075c141e4d0d Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Fri, 3 Apr 2020 22:00:36 +0100 Subject: [PATCH 09/16] Update variables.md --- tests/fixtures/.github/variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/.github/variables.md b/tests/fixtures/.github/variables.md index 3c1ba87..382824a 100644 --- a/tests/fixtures/.github/variables.md +++ b/tests/fixtures/.github/variables.md @@ -2,4 +2,4 @@ title: Hello {{ action }} --- The action {{ action }} is the best action. -An `env` variable will be displayed here: {{env.env_test}}! +An `env` variable `env_test` will be displayed here: {{env.env_test}}! From 76951e49510c15b22d1338bf4d49a7caec4b3d2d Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Fri, 3 Apr 2020 22:05:23 +0100 Subject: [PATCH 10/16] Update README.md add explanation for `env` variables. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4bc752d..70071c0 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,12 @@ 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 }}. +And here is an environment variable `env_test`: {{env.env_test}} ``` 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). +Besides, an environment variables `var` is accessible via the `env.var` syntax. 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). From 4b045a88ef9f21f51f17fd77ea80d4c6086e3673 Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Fri, 3 Apr 2020 22:06:11 +0100 Subject: [PATCH 11/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 70071c0..d7dfd4d 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ And here is an environment variable `env_test`: {{env.env_test}} ``` 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). -Besides, an environment variables `var` is accessible via the `env.var` syntax. +Besides, an environment variable `var` is accessible via the `env.var` syntax. 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). From 29c793dd6703501a180c3b910dce3f7d84ec8283 Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Fri, 3 Apr 2020 21:09:51 -0400 Subject: [PATCH 12/16] Tweak README wording --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d7dfd4d..b1db986 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,20 @@ assignees: JasonEtco, matchai labels: bug, enhancement --- Someone just pushed, oh no! Here's who did it: {{ payload.sender.login }}. -And here is an environment variable `env_test`: {{env.env_test}} ``` 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). -Besides, an environment variable `var` is accessible via the `env.var` syntax. + +You can also use environment variables: + +```markdown +--- +title: Someone just pushed +assignees: JasonEtco, matchai +labels: bug, enhancement +--- +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). From bfdf15bacf015681378aa8fcc015209a1298ef71 Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Fri, 3 Apr 2020 21:09:57 -0400 Subject: [PATCH 13/16] Improve fixture wording --- tests/fixtures/.github/variables.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/.github/variables.md b/tests/fixtures/.github/variables.md index 382824a..61b3f1a 100644 --- a/tests/fixtures/.github/variables.md +++ b/tests/fixtures/.github/variables.md @@ -2,4 +2,5 @@ title: Hello {{ action }} --- The action {{ action }} is the best action. -An `env` variable `env_test` will be displayed here: {{env.env_test}}! + +Environment variable {{ env.EXAMPLE }} is great. From 63de5b95a4e617e1f86ed9ee37040de60f9015c4 Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Fri, 3 Apr 2020 21:11:34 -0400 Subject: [PATCH 14/16] Add env definition to tests --- tests/index.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/index.test.js b/tests/index.test.js index a147430..6022f0b 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -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 () => { From 64db8bdd62e16071d5b19965e6577babff87745a Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Fri, 3 Apr 2020 21:13:08 -0400 Subject: [PATCH 15/16] Add psnapshot to existing test --- tests/__snapshots__/index.test.js.snap | 12 ++++++++++++ tests/index.test.js | 1 + 2 files changed, 13 insertions(+) diff --git a/tests/__snapshots__/index.test.js.snap b/tests/__snapshots__/index.test.js.snap index ed533c9..a0cf922 100644 --- a/tests/__snapshots__/index.test.js.snap +++ b/tests/__snapshots__/index.test.js.snap @@ -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", diff --git a/tests/index.test.js b/tests/index.test.js index 6022f0b..a9d6790 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -72,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() }) From ef639d9f0ea8983e27dd0fb2011ddfdc5264e21c Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Fri, 3 Apr 2020 21:18:45 -0400 Subject: [PATCH 16/16] Tweak example code --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b1db986..e692282 100644 --- a/README.md +++ b/README.md @@ -29,16 +29,16 @@ labels: bug, enhancement 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: -You can also use environment variables: +```yaml +- uses: JasonEtco/create-an-issue@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ADJECTIVE: great +``` ```markdown ---- -title: Someone just pushed -assignees: JasonEtco, matchai -labels: bug, enhancement ---- Environment variables are pretty {{ env.ADJECTIVE }}, right? ```