From 5384b5bb3bf2c6b1c100a2a5821e1ddac8c38cae Mon Sep 17 00:00:00 2001 From: Zach Himsel Date: Mon, 5 Jun 2023 08:08:01 -0400 Subject: [PATCH 1/2] Add newline after the match token in error comments (#55) * Add newline after the match token in error comments For some reason, Github's rendering of markdown is disabled on any line that starts with a comment (``). However, markdown rendering resumes on the next line. This is an easy fix which just adds a newline after the match token. --------- Co-authored-by: Michael Heap --- index.js | 2 +- index.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1e5cce9..aba5a2f 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ const core = require("@actions/core"); const github = require("@actions/github"); -const matchToken = ``; +const matchToken = `\n`; async function action() { try { const token = core.getInput("token", { required: true }); diff --git a/index.test.js b/index.test.js index 1b22771..c6d0e1e 100644 --- a/index.test.js +++ b/index.test.js @@ -6,7 +6,7 @@ const mockedEnv = require("mocked-env"); const nock = require("nock"); nock.disableNetConnect(); -const matchToken = ``; +const matchToken = `\n`; describe("Required Labels", () => { let restore; From 65d195bf4a9b738e8f2a9c540d0cc182bb80df72 Mon Sep 17 00:00:00 2001 From: JJ Miller Date: Fri, 2 Jun 2023 15:12:21 -0400 Subject: [PATCH 2/2] Add `labels` output which will contain all the matching/intersecting labels if the action is successful. --- README.md | 29 +++++++++++++++++++++++++++++ action.yml | 3 +++ index.js | 1 + index.test.js | 16 +++++++++++----- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 41c39f5..5b33eda 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ This action has three required inputs; `labels`, `mode` and `count` This action calls the GitHub API to fetch labels for a PR rather than reading `event.json`. This allows the action to run as intended when an earlier step adds a label. It will use `github.token` by default, and you can set the `token` input to provide alternative authentication. +If successful, any matching labels will be output in `outputs.labels` as a comma separated string. + ## Examples ### Complete example @@ -149,3 +151,30 @@ jobs: - run: echo FAILURE && exit 1 if: needs.label.outputs.status == 'failure' ``` + +### Using Output Labels + +If the action was successful you can access the matching labels via `outputs.labels`. This is useful if you want to use the labels in a later step. + +```yaml +name: Pull Request Labels +on: + pull_request: + types: [opened, labeled, unlabeled, synchronize] +jobs: + label: + runs-on: ubuntu-latest + steps: + - id: check-labels + uses: mheap/github-action-required-labels@v4 + with: + mode: minimum + count: 1 + labels: "feature-1, feature-2, feature-3" + - run: | + echo "Enabled Features:" + for f in $(echo "{{steps.check-labels.outputs.labels}}" | sed "s/,/ /g") + do + echo "$f" + done +``` \ No newline at end of file diff --git a/action.yml b/action.yml index 6654ce7..f0e10d2 100644 --- a/action.yml +++ b/action.yml @@ -6,6 +6,9 @@ runs: branding: icon: check-square color: blue +outputs: + labels: + description: "The labels that were matched as a comma separated string" inputs: token: description: The GitHub token to use when calling the API diff --git a/index.js b/index.js index aba5a2f..362569d 100644 --- a/index.js +++ b/index.js @@ -103,6 +103,7 @@ async function action() { } } + core.setOutput("labels", intersection.join(",")); core.setOutput("status", "success"); } catch (e) { core.setFailed(e.message); diff --git a/index.test.js b/index.test.js index c6d0e1e..a8437da 100644 --- a/index.test.js +++ b/index.test.js @@ -58,8 +58,9 @@ describe("Required Labels", () => { mockLabels(["enhancement", "bug"]); await action(); - expect(core.setOutput).toBeCalledTimes(1); + expect(core.setOutput).toBeCalledTimes(2); expect(core.setOutput).toBeCalledWith("status", "success"); + expect(core.setOutput).toBeCalledWith("labels", "enhancement"); }); it("fetches the labels from the API (and fails)", async () => { @@ -134,8 +135,9 @@ describe("Required Labels", () => { await action(); - expect(core.setOutput).toBeCalledTimes(1); + expect(core.setOutput).toBeCalledTimes(2); expect(core.setOutput).toBeCalledWith("status", "success"); + expect(core.setOutput).toBeCalledWith("labels", "enhancement"); }); it("at least X", async () => { @@ -148,8 +150,9 @@ describe("Required Labels", () => { await action(); - expect(core.setOutput).toBeCalledTimes(1); + expect(core.setOutput).toBeCalledTimes(2); expect(core.setOutput).toBeCalledWith("status", "success"); + expect(core.setOutput).toBeCalledWith("labels", "enhancement,bug"); }); it("at most X", async () => { @@ -163,9 +166,11 @@ describe("Required Labels", () => { await action(); - expect(core.setOutput).toBeCalledTimes(1); + expect(core.setOutput).toBeCalledTimes(2); expect(core.setOutput).toBeCalledWith("status", "success"); + expect(core.setOutput).toBeCalledWith("labels", "enhancement,bug"); }); + }); describe("failure", () => { @@ -305,8 +310,9 @@ describe("Required Labels", () => { mockLabels(["bug"]); await action(); - expect(core.setOutput).toBeCalledTimes(1); + expect(core.setOutput).toBeCalledTimes(2); expect(core.setOutput).toBeCalledWith("status", "success"); + expect(core.setOutput).toBeCalledWith("labels", "bug"); }); }); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy