Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed May 21, 2024
1 parent 20b075f commit 1ff9fb6
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions .github/workflows/plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Terraform Plan
id: plan
run: |
out="$(terraform plan -no-color)"
out="$(terraform plan -no-color | grep -v -E '^(module\..+|Reading|Read complete|Refreshing state)')"
out="${out//'%'/'%25'}"
out="${out//$'\n'/'%0A'}"
out="${out//$'\r'/'%0D'}"
Expand All @@ -71,8 +71,12 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Plan 📖
\`${{ steps.plan.outcome }}\`
const issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const commentIdentifier = '<!-- terraform-plan-comment -->';
const newCommentBody = `#### Terraform Plan 📖
${commentIdentifier}
<details><summary>Show Plan</summary>
\`\`\`terraform
Expand All @@ -81,9 +85,30 @@ jobs:
</details>`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
// Get existing comments
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number
});
// Find existing comment
const existingComment = comments.find(comment => comment.body.includes(commentIdentifier));
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body: newCommentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: newCommentBody
});
}

0 comments on commit 1ff9fb6

Please sign in to comment.