Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to turn off comment header and footer #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ inputs:
default: "true"
required: false

show-header:
description: include header in the comment
default: "true"
required: false

show-footer:
description: include footer in the comment
default: "true"
required: false

remove-stale-reports:
description: remove report comments for old commits?
default: "false"
Expand Down
40 changes: 18 additions & 22 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ import github from '@actions/github'

export default function (data) {
// extract relevant variables
const { diff: { summary, patches }, textContent, customHeader } = data
const { diff: { summary, patches }, textContent, customHeader, showHeader, showFooter } = data
const { runId, repo, sha } = github.context
/* c8 ignore next 4 */
const headerText = customHeader || ':robot: *Terraform Report*'

data.header = headerText
data.footer = `This comment was generated by [Terraform Pull Request Report Generator](https://github.com/ahmadnassri/action-terraform-report) - action run [\`#${runId}\`](https://github.com/${repo.owner}/${repo.repo}/actions/runs/${runId}) - commit ${sha}`

data.body = `
### ${data.header}
data.header = showHeader
? `
### ${headerText}
---`
: ''

data.footer = showFooter
? `
---
> This comment was generated by [Terraform Pull Request Report Generator](https://github.com/ahmadnassri/action-terraform-report) - action run [\`#${runId}\`](https://github.com/${repo.owner}/${repo.repo}/actions/runs/${runId}) - commit ${sha}
`
: ''

data.body = `${header}
##### Plan: \`${summary.create}\` to add, \`${summary.update}\` to change, \`${summary.delete}\` to destroy
`

Expand All @@ -24,8 +32,7 @@ export default function (data) {
${textContent}
\`\`\`
</details>

`
${data.footer}`
}

if (data.showDiff === 'true') {
Expand All @@ -38,23 +45,12 @@ ${diff}
`
}

data.body += `
---
> ${data.footer}
`

const commentMaximumLength = 65536

if (data.body.length > commentMaximumLength) {
data.body = `
### ${data.header}
---
data.body = `${data.header}
##### Plan: \`${summary.create}\` to add, \`${summary.update}\` to change, \`${summary.delete}\` to destroy
##### Warning: The generated comment is too long, check [the output](https://github.com/${repo.owner}/${repo.repo}/actions/runs/${runId}) for the full detail.`

data.body += `
---
> ${data.footer}
`
##### Warning: The generated comment is too long, check [the output](https://github.com/${repo.owner}/${repo.repo}/actions/runs/${runId}) for the full detail.
${data.footer}`
}
}