Skip to content

gh pr comment --edit-last does not proceed if no comment already exists for the user #10370

Description

@EdouardF

Describe the feature or problem you’d like to solve

As the title suggests, using the --edit-last flag for gh pr comment will return no comments found for the current user and fail

One way to circumvent this is to check for existing comments and either comment if no comment already exists or --edit-last if one comment exists

But to me it'd make more sense for the flag to have the logic inside

Proposed solution

While this makes sense, what would possibly make more sense is to comment anyway if no comment is found, as this would be the first comment for the user, and then indeed it'll get edited in the future using the flag

Activity

  1. changed the title [-]`gh pr comment --édit-last` does not proceed if no comment already exists for the user[/-] [+]`gh pr comment --edit-last` does not proceed if no comment already exists for the user[/+] on Feb 4, 2025
  2. jtmcg commented on Feb 4, 2025

    @jtmcg
    Contributor

    Hey @EdouardF, I could see how that might be a convenient addition to gh pr comment --edit-last. I think the right approach, here, is not to add this functionality natively to --edit-last, but instead add a flag for non-TTY use-cases and a prompt for TTY use cases.

    It's worth calling out that gh issue comment uses a lot of the same code, here, so we probably want to maintain parity between those two experiences. My proposed AC is below:

    Acceptance Criteria

    Given I have no comments on an existing PR
    when I run gh pr comment [<number> | <url> | <branch>] --edit-last --create-if-none --body <body> (non-interactively)
    then a comment is created instead of erroring

    Given I have no comments on an existing PR
    when I run gh pr comment [<number> | <url> | <branch>] --edit-last (interactively)
    then I am prompted that no comment exists and whether or not I'd like to create a new comment. If I select Y, then I have the same experience as though I ran gh pr comment [<number> | <url> | <branch>]

    Given I have no comments on an existing PR
    when I run gh pr comment [<number> | <url> | <branch>] --edit-last --create-if-none (interactively)
    then I am told that no comments exist and I am creating a new comment. Then I have the same experience as though I ran gh pr comment [<number> | <url> | <branch>]

    Given I have no comments on an existing issue
    when I run any of the above scenarios using gh issue comment
    then I have get the same behavior as I would running gh pr comment
    (i.e. make sure gh issue comment gets the same new functionality that's added to gh pr comment by the above AC)

    Notes

    • I think we can use a single opt to hold the flag value and use it for setting with the prompter.
    • We should probably make a new error for the condition where no comments exist and check for it in CommentableRun. We can then fall through to the createComment experience from here if the new flag is set. Note: this might be an oversimplification of the problem, but I wanted to bread-crumb the implementation of this
  3. added
    gh-prrelating to the gh pr command
    gh-issuerelating to the gh issue command
    and removed on Feb 4, 2025
  4. self-assigned this
    on Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementa request to improve CLIgh-issuerelating to the gh issue commandgh-prrelating to the gh pr commandhelp wantedContributions welcome

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions