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
{{ message }}
Repository navigation
gh pr comment --edit-last does not proceed if no comment already exists for the user #10370
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
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
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
Activity
[-]`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[/+]jtmcg commentedon Feb 4, 2025
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 commentuses 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 commentthen I have get the same behavior as I would running
gh pr comment(i.e. make sure
gh issue commentgets the same new functionality that's added togh pr commentby the above AC)Notes
optto hold the flag value and use it for setting with the prompter.createCommentexperience 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