Skip to content
Latchkey

gh pr comment Command Reference

Post a comment on a pull request straight from your pipeline.

gh pr comment adds a comment to a pull request. CI jobs use it to post plan summaries, test results, or deploy links back onto the PR.

What it does

gh pr comment posts a comment on a PR (by number, URL, or the current branch). With --edit-last it updates the most recent comment by the same actor instead of adding a new one, keeping the PR thread tidy across re-runs.

Common flags and usage

  • --body / --body-file: comment text inline or from a file
  • --edit-last: update the previous comment instead of adding a new one
  • --create-if-none: with --edit-last, create one if none exists
  • [number | url | branch]: target a specific PR

Example

shell
- name: Post plan summary
  env:
    GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: |
    terraform show -no-color tfplan > plan.txt
    gh pr comment "${PR_NUMBER}" --body-file plan.txt --edit-last --create-if-none

In CI

Use --edit-last --create-if-none so repeated runs update a single comment rather than flooding the PR. --body-file is convenient for posting a rendered terraform plan or test report.

Key takeaways

  • --body-file posts file contents like a rendered plan or test report.
  • --edit-last --create-if-none keeps one updating comment across re-runs.
  • Target any PR by number, URL, or current branch.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →