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-noneIn 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
gh pr create Command ReferenceReference for gh pr create in CI/CD: open a pull request non-interactively with title, body, base, and labels…
gh pr merge Command ReferenceReference for gh pr merge in CI/CD: merge a pull request non-interactively with squash, merge, or rebase stra…
gh api Command ReferenceReference for gh api in CI/CD: call any REST or GraphQL endpoint with authentication handled, pass fields, pa…