Skip to content

Add --edit-last-or-create option or enhance the functionality of --edit-last for PR comments #6790

Description

@joe-sharp

Describe the feature or problem you’d like to solve

Currently running gh pr comment --edit-last will fail if there is not an existing comment from the author. It would be nice to prompt users and/or allow users to use the option (or a new option) that will edit the last comment if it it exists but creates a new one if not.

❯ gh pr comment 5 --edit-last --body 'This is just a test'
no comments found for current user

Proposed solution

Add an additional option for gh pr comment such as --edit-last-or-create that will not fail if the user hasn't yet commented on the PR, it will simply create a new comment.

❯ gh pr comment 5 --edit-last-or-create --body 'This is just a test'
https://github.com/joe-sharp/<redacted>/pull/5#issuecomment-<redacted>

How will it benefit CLI and its users?
Script writers will no longer need to worry about making a conditional to check if a comment exists before running the command. This is useful for commenting the results of a build or linting job without polluting the PR with multiple comments.

Additional context

Please let me know if additional context is needed, but this should be pretty straight forward.

Activity

  1. changed the title [-]Add --edit-last-if-exists option or enhance the functionality of --edit-last for PR comments[/-] [+]Add --edit-last-or-create option or enhance the functionality of --edit-last for PR comments[/+] on Dec 27, 2022
  2. vilmibm commented on Jan 3, 2023

    @vilmibm
    Contributor

    I'm wondering if there is harm in just having --edit-last just make a comment if no previous comment exists? we could output a warning, like:

    gh issue comment 123 --edit-last -b "hmmm"
    ! Warning: no previous comment
    :checkmark: added comment
    

    Adding the discuss label for our next sync meeting.

  3. added
    discussFeature changes that require discussion primarily among the GitHub CLI team
    on Jan 3, 2023
  4. joe-sharp commented on Jan 3, 2023

    @joe-sharp
    Author

    I was kinda leaning to just asking for that but decided I wanted to be open to other options. IMO the expected behavior would be to have it just work, but the warning is nice too. Maybe a config option could be added to change the warning to an error?

  5. vilmibm commented on Jan 9, 2023

    @vilmibm
    Contributor
  6. vilmibm commented on Jan 9, 2023

    @vilmibm
    Contributor

    Another option is to do something like this in your script:

    body="foobar" gh issue comment 123 --edit-last "$body" || gh issue comment 123 "$body"
    

    If neither build summaries or this scripting approach works for you, we can talk about adding a new flag. There is internal resistance to making --edit-last an upsert action.

  7. added
    more-info-neededMore info needed from user/contributor
    and removed
    discussFeature changes that require discussion primarily among the GitHub CLI team
    on Jan 9, 2023
  8. joe-sharp commented on Feb 3, 2023

    @joe-sharp
    Author

    The feature you pointed out won't work for us because we use other CI providers mostly. We did end up doing something similar to your last comment. I would think an extra flag would be useful and completely understand the pushback to modifying the existing flag.

  9. kumadee commented on Mar 1, 2023

    @kumadee

    I would appreciate if we had another flag which can enable upsert action to satisfy any resistance.

  10. joe-sharp commented on Mar 13, 2023

    @joe-sharp
    Author

    @vilmibm sorry for the ping. Just wanted to get this back on your radar.

  11. vilmibm commented on Mar 14, 2023

    @vilmibm
    Contributor

    I'm personally okay with an an --create-or-edit-last <body> flag that's mutually exclusive with --edit-last but would appreciate sign-off from @mislav and @samcoe . I see the merit for this kind of operation in non-Actions contexts and the bit of bash I pasted is a bit cumbersome.

  12. samcoe commented on Mar 16, 2023

    @samcoe
    Contributor

    @vilmibm I am still on the fence but I won't stand in the way of this feature getting implemented.

  13. joe-sharp commented on May 27, 2023

    @joe-sharp
    Author

    I am glad there was resistance on making the existing action an upsert action because now we actually rely on that due to a feature change in the script. Anyways, just wanted to update to say we are no longer blocked by this feature request but maybe someday having a --upsert action might be nice.

  14. added
    coreThis issue is not accepting PRs from outside contributors
    and removed
    more-info-neededMore info needed from user/contributor
    on Jun 23, 2023
  15. Shion1305 commented on Feb 2, 2024

    @Shion1305
    Contributor

    I'm interested in this feature. Will work on this.

  16. vyacheslav31 commented on Aug 7, 2024

    @vyacheslav31

    Would love for one of the proposals on this issue to go through - any one of them would work nicely with my current ci/cd setup.

  17. GriceTurrble commented on Mar 11, 2025

    @GriceTurrble

    FYI, duplicated by #10370 , which was fixed by #10427 .

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

    coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIgh-prrelating to the gh pr command

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions