Skip to content

Commit

Permalink
fix: Autodetect PR Triggering Context
Browse files Browse the repository at this point in the history
Only attempt commenting if in a pr context. Otherwise don't
  • Loading branch information
Kludgy4 committed Dec 4, 2024
1 parent 8b79f01 commit 506aec6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 41 deletions.
4 changes: 0 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ inputs:
description: Whether to skip posting a pull request comment when no changes need to be performed.
required: true
default: "false"
should-comment:
description: Whether to attempt outputting the terraform plan as a PR comment
required: false
default: "true"
outputs:
plan-markdown:
description: The raw markdown output of the terraform plan
Expand Down
66 changes: 33 additions & 33 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/comment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as core from '@actions/core'
import type { GitHub } from '@actions/github/lib/utils'
import * as github from '@actions/github'
import type { PullRequestEvent } from '@octokit/webhooks-types'
Expand Down
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ async function run() {
terraformCmd: core.getInput('terraform-cmd', { required: true }),
workingDirectory: core.getInput('working-directory', { required: true }),
header: core.getInput('header', { required: true }),
skipEmpty: core.getBooleanInput('skip-empty', { required: true }),
shouldComment: core.getInput('should-comment', { required: false })
skipEmpty: core.getBooleanInput('skip-empty', { required: true })
}
const octokit = github.getOctokit(inputs.token)

Expand All @@ -26,6 +25,8 @@ async function run() {
)

if (!inputs.skipEmpty || !planIsEmpty(plan)) {
const prContext = 'pull_request' in github.context.payload

// 3) Render the plan diff markdown and set it as output
const planMarkdown = await core.group('Render plan diff markdown', () => {
const markdown = renderMarkdown({ plan, header: inputs.header })
Expand All @@ -34,7 +35,7 @@ async function run() {
})

// 4) Post comment with markdown (if applicable)
if (inputs.shouldComment === 'true') {
if (prContext === true) {
await core.group('Render comment', () => {
return createOrUpdateComment({ octokit, content: planMarkdown })
})
Expand Down

0 comments on commit 506aec6

Please sign in to comment.