Skip to content

Commit

Permalink
add option to make posting comment to PR optional (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Bart Veneman <[email protected]>
  • Loading branch information
bartveneman and bartveneman authored Apr 9, 2020
1 parent 0a509ce commit 11ce8f3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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 })
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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 })
Expand All @@ -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) {
Expand Down

0 comments on commit 11ce8f3

Please sign in to comment.