Skip to content

feat: add comment selector - #10850

Closed
shanduur wants to merge 9 commits into
cli:trunkfrom
shanduur:gh-comment-selector
Closed

shanduur wants to merge 9 commits into
cli:trunkfrom
shanduur:gh-comment-selector

Conversation

@shanduur

@shanduur shanduur commented Apr 23, 2025 •

Copy link
Copy Markdown
Contributor

This PR introduces the ability to select and edit a specific comment using a jq selector when using the --edit-last flag in issue comment and pr comment commands.

The previous behavior always edited the last comment by the current user. This change provides more flexibility, enabling users to programmatically pick the right comment based on content or metadata, which is particularly useful in automated or scripted environments.

  • New flag: --edit-selector
    Allows users to specify a jq expression to select a specific comment (instead of defaulting to the latest one).
    Example usage:

    gh pr comment --edit-last --edit-selector '. | select(.body | contains("<!-- some arbitrary tag -->"))'
    gh pr comment --edit-last --edit-selector '. | select(.id == "2823981412")'
  • Updated logic in CommentableOptions and updateComment():

    • When --edit-selector is used, the code attempts to evaluate the selector against the list of comments.
    • If a match is found, that comment is edited.
    • If no match is found, an error is returned.
  • Dependency update:

    • Moved github.com/itchyny/gojq v0.12.15 from indirect to direct dependency in go.mod.
  • Tests:

    • Added unit tests for selectComment() covering selector matches and failures.

Signed-off-by: Mateusz Urbanek <[email protected]>
@shanduur

shanduur commented Apr 23, 2025 •

Copy link
Copy Markdown
Contributor Author

EDIT: posted from gh $(./bin/gh --version) gh version 2.70.0-98-gc43590afe (2025-04-23)
https://github.com/cli/cli/releases/latest

@shanduur
shanduur force-pushed the gh-comment-selector branch from 4debf1d to c43590a Compare April 23, 2025 10:37
Signed-off-by: Mateusz Urbanek <[email protected]>
Signed-off-by: Mateusz Urbanek <[email protected]>
@shanduur
shanduur force-pushed the gh-comment-selector branch from 576df38 to 481df38 Compare April 23, 2025 11:25
@shanduur
shanduur marked this pull request as ready for review April 23, 2025 11:31
@shanduur
shanduur requested a review from a team as a code owner April 23, 2025 11:31
@shanduur
shanduur requested a review from williammartin April 23, 2025 11:31
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Apr 23, 2025
@cliAutomation

Copy link
Copy Markdown
Contributor

Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message.

@shanduur

Copy link
Copy Markdown
Contributor Author

Hi @williammartin! I think this is ready to review, I added necessary tests, and no functionality is broken. Do you have time to take a look? Thanks!

@BagToad

BagToad commented Apr 24, 2025 •

Copy link
Copy Markdown
Member

👋 Hey @shanduur ✨

I want to express our gratitude for your efforts to improve gh, especially ideating and developing new and interesting capabilities ❤️

I discussed this with @williammartin and the team, and we feel that the best next step would be to open an issue to discuss and scope out this feature - this is how we prefer contributions to start, excluding small changes like typos.

With that said, we want to close this PR for now, but we encourage you to open an issue for this so we can continue the discussion there and develop acceptance criteria for a feature like this.

Thank you again for your work here 🙏 ✨

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

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants