Skip to content

Support updating comments/reviews #3613

Description

@AudriusButkevicius

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.

Activity

  1. changed the title [-]Support updating comments[/-] [+]Support updating comments/reviews[/+] on May 10, 2021
  2. added
    coreThis issue is not accepting PRs from outside contributors
    needs-designAn engineering task needs design to proceed
    on May 18, 2021
  3. mnquintana commented on Oct 28, 2021

    @mnquintana

    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. 🙏🏽

  4. josesimoes commented on Mar 24, 2022

    @josesimoes

    Should be possible to delete comments as well.

  5. added and removed
    needs-designAn engineering task needs design to proceed
    coreThis issue is not accepting PRs from outside contributors
    on May 16, 2022
  6. mislav commented on May 16, 2022

    @mislav
    Contributor

    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

    How does this sound?

  7. pete-woods commented on May 16, 2022

    @pete-woods
    Contributor

    That would cover my use case, at least (a bot that comments helm chart diffs)

  8. mislav commented on May 16, 2022

    @mislav
    Contributor

    @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?

  9. pete-woods commented on May 16, 2022

    @pete-woods
    Contributor

    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.

  10. mislav commented on May 17, 2022

    @mislav
    Contributor

    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.

  11. pete-woods commented on May 17, 2022

    @pete-woods
    Contributor

    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.

  12. Pearce-Ropion commented on Aug 4, 2022

    @Pearce-Ropion

    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)

  13. tndhagedorn commented on Sep 22, 2023

    @tndhagedorn

    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:

    gh api \
      -H "Accept: application/vnd.github+json" \
      -H "X-GitHub-Api-Version: 2022-11-28" \
      /repos/OWNER/REPO/issues/PULL_NUMBER/comments  --jq 'map(select(.body|startswith("<!--tag-->"))) | .[0].id'  
    
  14. erawhctim commented on Feb 3, 2025

    @erawhctim

    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.

  15. erawhctim commented on Feb 3, 2025

    @erawhctim

    Created a new issue for this so we can keep this thread dead - #10366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIhelp wantedContributions welcome

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions