You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the feature or problem you’d like to solve
As part of CI, I'd like to drop a comment with the metrics of the PR.
For example like codecov does with coverage report.
As the PR is updated, I'd like to delete my initial comment and create a new one, or update my original comment.
Proposed solution
comment commands should support accepting a comment reference for example --update issuecomment-123123123 and update the comment instead of creating a new one.
--json comments should include comment IDs to be able to query them via jq.
This would be a really, reeeeally helpful enhancement, and obviate the need for a lot of custom actions / scripts that are currently needed to upsert comments on a PR. 🙏🏽
We've discussed this and decided that due to UI concerns, we wouldn't add a command to edit a comment by ID, since the user would be burdened with having to discover that ID in the first place, but we are open to a contribution that adds a command or flag that edits one's own last comment in a thread.
For example:
gh issue comment 123 --edit-last
#=> edit my own last comment in issue thread #123
@pete-woods@mnquintana Thanks for chiming in. Does the bot ever need to perform an upsert, meaning "use this text to create a new comment or update an existing one"? Do you feel that should be exposed as part of this functionality as well?
To clarify, the first thing I said was a feature that only edits an existing comment by the same actor. If the comment to edit does not exist, the operation would fail.
An "upsert" is a single operation that would (in the context of comments) edit an existing comment, and create a comment if one by the same actor doesn't exist. I thought that the upsert operation might be useful for bots.
Okay, got it. So what I need is definitely to be able to "upsert" somehow. Though I don't mind if it's multiple commands (like finding if I've already commented and then using an update comment command), as long as I don't have to start using curl.
We've discussed this and decided that due to UI concerns, we wouldn't add a command to edit a comment by ID, since the user would be burdened with having to discover that ID in the first place, but we are open to a contribution that adds a command or flag that edits one's own last comment in a thread.
Personally, I don't think needing to first find a comment's ID and then updating via that ID should be a blocker to supporting the ability to update comments directly. I mostly use gh CLI for scripting and often need to first find the PR or issue number before I can run commands against that issue, so I don't see why I wouldn't be able to do the same thing for comments.
I would be fine with an --edit-last flag as it would solve my immediate use case. But I think gh CLI would be incomplete without a way to edit comments directly. Especially since you can already do it via the rest API (although its a lot more code)
Reacted by Steffen Schneider, Pete Steyert-Woods, Jason Goldfine-Middleton, ryosebach, Andrei Neculau, Emily Bourne, tndhagedorn, Andrii Pavlenko, Noé, Emilgardis and 4 more
We've discussed this and decided that due to UI concerns, we wouldn't add a command to edit a comment by ID, since the user would be burdened with having to discover that ID in the first place, but we are open to a contribution that adds a command or flag that edits one's own last comment in a thread.
Personally, I don't think needing to first find a comment's ID and then updating via that ID should be a blocker to supporting the ability to update comments directly. I mostly use gh CLI for scripting and often need to first find the PR or issue number before I can run commands against that issue, so I don't see why I wouldn't be able to do the same thing for comments.
I would be fine with an --edit-last flag as it would solve my immediate use case. But I think gh CLI would be incomplete without a way to edit comments directly. Especially since you can already do it via the rest API (although its a lot more code)
I think --edit-last is a great solution for a lot of use cases, and I also agree with @Pearce-Ropion that it may not cover all use cases.
I may have a CI workflow that needs to post and then later update different comments on the PR. It might post one comment to link to build artifacts, and append this as the build progresses. Another comment might be updated to show test results as they progress.
It's true there's no standard approach to search for the comment to update, In my case I just index comments using a tag hidden inside an HTML comment at the start of the comment: <!--tag-->
I can then find the comment to update with something like:
Would it be possible to add the removal/deletion behavior that works similar to --edit-last?
e.g. gh pr comment --edit-last --delete or gh pr comment --remove-last
That way, deleting would be possible without the burden of associating a comment to an ID value.
Activity
[-]Support updating comments[/-][+]Support updating comments/reviews[/+]mnquintana commentedon Oct 28, 2021
This would be a really, reeeeally helpful enhancement, and obviate the need for a lot of custom actions / scripts that are currently needed to upsert comments on a PR. 🙏🏽
josesimoes commentedon Mar 24, 2022
Should be possible to delete comments as well.
mislav commentedon May 16, 2022
We've discussed this and decided that due to UI concerns, we wouldn't add a command to edit a comment by ID, since the user would be burdened with having to discover that ID in the first place, but we are open to a contribution that adds a command or flag that edits one's own last comment in a thread.
For example:
gh issue comment 123 --edit-last #=> edit my own last comment in issue thread #123How does this sound?
pete-woods commentedon May 16, 2022
That would cover my use case, at least (a bot that comments helm chart diffs)
mislav commentedon May 16, 2022
@pete-woods @mnquintana Thanks for chiming in. Does the bot ever need to perform an upsert, meaning "use this text to create a new comment or update an existing one"? Do you feel that should be exposed as part of this functionality as well?
pete-woods commentedon May 16, 2022
I thought that was the same as the previous thing you said. The bot wants to update its single comment with the latest version of the diff.
mislav commentedon May 17, 2022
To clarify, the first thing I said was a feature that only edits an existing comment by the same actor. If the comment to edit does not exist, the operation would fail.
An "upsert" is a single operation that would (in the context of comments) edit an existing comment, and create a comment if one by the same actor doesn't exist. I thought that the upsert operation might be useful for bots.
pete-woods commentedon May 17, 2022
Okay, got it. So what I need is definitely to be able to "upsert" somehow. Though I don't mind if it's multiple commands (like finding if I've already commented and then using an update comment command), as long as I don't have to start using curl.
Pearce-Ropion commentedon Aug 4, 2022
Personally, I don't think needing to first find a comment's ID and then updating via that ID should be a blocker to supporting the ability to update comments directly. I mostly use gh CLI for scripting and often need to first find the PR or issue number before I can run commands against that issue, so I don't see why I wouldn't be able to do the same thing for comments.
I would be fine with an
--edit-lastflag as it would solve my immediate use case. But I think gh CLI would be incomplete without a way to edit comments directly. Especially since you can already do it via the rest API (although its a lot more code)tndhagedorn commentedon Sep 22, 2023
I think
--edit-lastis a great solution for a lot of use cases, and I also agree with @Pearce-Ropion that it may not cover all use cases.I may have a CI workflow that needs to post and then later update different comments on the PR. It might post one comment to link to build artifacts, and append this as the build progresses. Another comment might be updated to show test results as they progress.
It's true there's no standard approach to search for the comment to update, In my case I just index comments using a tag hidden inside an HTML comment at the start of the comment:
<!--tag-->I can then find the comment to update with something like:
erawhctim commentedon Feb 3, 2025
Would it be possible to add the removal/deletion behavior that works similar to
--edit-last?e.g.
gh pr comment --edit-last --deleteorgh pr comment --remove-lastThat way, deleting would be possible without the burden of associating a comment to an ID value.
erawhctim commentedon Feb 3, 2025
Created a new issue for this so we can keep this thread dead - #10366