Skip to content
Open
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
2 changes: 1 addition & 1 deletion build/github-tf-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
issue_number: context.issue.number,
})
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Terraform Initialization')
return comment.user.type === 'Bot' && comment.body.includes('Terraform Plan Validate All')
})
Comment on lines 80 to 82

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this change correctly fixes the bug, finding the comment by its visible title Terraform Plan Validate All is fragile. If this title text is changed in the future, this logic will break and the action will start creating duplicate comments again.

A more robust approach is to embed a unique, hidden identifier in the comment body and search for that instead. This decouples the search logic from the user-facing text.

You could implement this with two changes:

  1. Add a hidden HTML comment to the output variable (around line 107):

    const output = `
    ...
    </details>
    ${truncated_message}
    <!-- github-tf-pull-request-comment -->
    `;
  2. Update this find logic to search for the hidden identifier:

    const botComment = comments.find(comment => {
      return comment.user.type === 'Bot' && comment.body.includes('<!-- github-tf-pull-request-comment -->')
    })

This will make your action more resilient to future UI text changes.


const run_url = process.env.GITHUB_SERVER_URL + '/' + process.env.GITHUB_REPOSITORY + '/actions/runs/' + process.env.GITHUB_RUN_ID
Expand Down