From 11ce8f3ad6115eb8ca40ac416b777ce94f1ebffd Mon Sep 17 00:00:00 2001 From: Bart Veneman <1536852+bartveneman@users.noreply.github.com> Date: Thu, 9 Apr 2020 22:43:48 +0200 Subject: [PATCH] add option to make posting comment to PR optional (#9) Co-authored-by: Bart Veneman --- .github/workflows/main.yml | 1 + README.md | 1 + action.yml | 4 ++++ dist/index.js | 6 ++++++ src/index.js | 6 ++++++ 5 files changed, 18 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ec33ac7..f439eae 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,3 +16,4 @@ jobs: project-wallace-token: ${{ secrets.PROJECT_WALLACE_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }} css-path: ./style.css + post-pr-comment: true diff --git a/README.md b/README.md index 5e17281..95cf7f0 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This GitHub actions posts your CSS to [projectwallace.com](https://www.projectwa | `github-token` | _required_ | `github-token: ${{ secrets.GITHUB_TOKEN }}` | This Action uses this token to post a comment with the diff. | | `project-wallace-token` | _required_ | `project-wallace-token: ${{ secrets.PROJECT_WALLACE_TOKEN }}` | The webhook token for your project on projectwallace.com. You can find this token in the project settings. You must add this token to your [repository secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets) first! | | `css-path` | _required_ | `css-path: ./build/style.css` | Path to the CSS file that should be analyzed and compared to the data on projectwallace.com. | +| `post-pr-comment` | _optional_ | `true` | Whether this action should post a comment to the PR with changes | ### Example diff --git a/action.yml b/action.yml index a1dc086..b96db66 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,10 @@ inputs: css-path: description: 'Path to the CSS you want analyzed' required: true + post-pr-comment: + description: Whether this action should post a comment to the PR with changes + required: true + default: true runs: using: 'node12' diff --git a/dist/index.js b/dist/index.js index 049342e..f06cc2b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12784,6 +12784,7 @@ async function run() { const cssPath = core.getInput('css-path') const webhookToken = core.getInput('project-wallace-token') const githubToken = core.getInput('github-token') + const shouldPostPrComment = core.getInput('post-pr-comment') === 'true' const { eventName, payload } = github.context if (eventName !== 'pull_request') { @@ -12805,9 +12806,13 @@ async function run() { body: css, } ).catch((error) => { + core.setFailed(`Could not retrieve diff from projectwallace.com`) throw error }) const { diff } = JSON.parse(response.body) + console.log(JSON.stringify(diff, null, 2)) + + if (!shouldPostPrComment) return // POST the actual PR comment const formattedBody = createCommentMarkdown({ changes: diff }) @@ -12824,6 +12829,7 @@ async function run() { body: formattedBody, }) .catch((error) => { + core.warning(`Error ${error}: Failed to post comment to PR`) throw error }) } catch (error) { diff --git a/src/index.js b/src/index.js index df3ad03..1d793a8 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,7 @@ async function run() { const cssPath = core.getInput('css-path') const webhookToken = core.getInput('project-wallace-token') const githubToken = core.getInput('github-token') + const shouldPostPrComment = core.getInput('post-pr-comment') === 'true' const { eventName, payload } = github.context if (eventName !== 'pull_request') { @@ -30,9 +31,13 @@ async function run() { body: css, } ).catch((error) => { + core.setFailed(`Could not retrieve diff from projectwallace.com`) throw error }) const { diff } = JSON.parse(response.body) + console.log(JSON.stringify(diff, null, 2)) + + if (!shouldPostPrComment) return // POST the actual PR comment const formattedBody = createCommentMarkdown({ changes: diff }) @@ -49,6 +54,7 @@ async function run() { body: formattedBody, }) .catch((error) => { + core.warning(`Error ${error}: Failed to post comment to PR`) throw error }) } catch (error) {