Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[gh issue/pr comment] Add --create-if-none and prompts to create a comment if no comment already exists - #10427

#10427
Merged
BagToad merged 2 commits into
cli:trunkcli/cli:trunkfrom
latzskim:create-if-nonelatzskim/cli:create-if-noneCopy head branch name to clipboard
Feb 19, 2025
Merged

[gh issue/pr comment] Add --create-if-none and prompts to create a comment if no comment already exists #10427
BagToad merged 2 commits into
cli:trunkcli/cli:trunkfrom
latzskim:create-if-nonelatzskim/cli:create-if-noneCopy head branch name to clipboard

Conversation

@latzskim

Copy link
Copy Markdown
Contributor

Fixes #10370

I've run the following test scenarios:

pr comment:

// 1
gh pr comment --edit-last --create-if-none --body "test-comment"
https://github.com/latzskim/gqlc/pull/1#issuecomment-2654734453

// 2 
 gh pr comment --edit-last
? No comments found. Create one? Yes
- Press Enter to draft your comment in nano...
? Submit? Yes
https://github.com/latzskim/gqlc/pull/1#issuecomment-2654741928

// 3
 gh pr comment --edit-last --create-if-none
No comments found. Creating a new comment.
- Press Enter to draft your comment in nano...
? Submit? Yes
https://github.com/latzskim/gqlc/pull/1#issuecomment-2654744152

// 4
gh pr comment --edit-last
? No comments found. Create one? No
no comments found for current user

// 5
gh pr comment --create-if-none
`--create-if-none` can only be used with `--edit-last`

issue comment:

// 1
gh issue comment 2 --edit-last --create-if-none --body "test-comment"
https://github.com/latzskim/gqlc/issues/2#issuecomment-2654748574

// 2
 gh issue comment 2 --edit-last
? No comments found. Create one? Yes
- Press Enter to draft your comment in nano...
? Submit? Yes
https://github.com/latzskim/gqlc/issues/2#issuecomment-2654751145

// 3
 gh issue comment 2 --edit-last --create-if-none
No comments found. Creating a new comment.
- Press Enter to draft your comment in nano...
? Submit? Yes
https://github.com/latzskim/gqlc/issues/2#issuecomment-2654752583

// 4
 gh issue comment 2 --edit-last
? No comments found. Create one? No
no comments found for current user

// 5
 gh issue comment 2 --create-if-none
`--create-if-none` can only be used with `--edit-last`

This is my first open-source contribution. Please be verbose if anything needs to be adjusted.

@latzskim
latzskim requested a review from a team as a code owner February 12, 2025 20:22
@latzskim
latzskim requested a review from BagToad February 12, 2025 20:22
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Feb 12, 2025
@latzskim latzskim changed the title [gh issue/pr comment] Create a comment if no comment already [gh issue/pr comment] Create a comment if no comment already exists Feb 12, 2025
@BagToad BagToad self-assigned this Feb 18, 2025

@BagToad BagToad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Hey @latzskim - thanks for taking this work on! 💪 ✨

Everything is looking good. I have left some comments for you to review before we ship it 😁


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

gh pr comment 27 --edit-last --create-if-none --body=test | cat
https://github.com/BagToad/testing-public-1/pull/27#issuecomment-2666795264

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>]

gh pr comment 27 --edit-last
? No comments found. Create one? Yes
- Press Enter to draft your comment in vi... 
? Submit? Yes
https://github.com/BagToad/testing-public-1/pull/27#issuecomment-2666790644

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>]

gh pr comment 27 --edit-last --create-if-none
No comments found. Creating a new comment.
- Press Enter to draft your comment in vi... 
? Submit? Yes
https://github.com/BagToad/testing-public-1/pull/27#issuecomment-2666792494

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)

# noninteractive
gh issue comment 26 --edit-last --create-if-none --body=test | cat
https://github.com/BagToad/testing-public-1/issues/26#issuecomment-2666799061

# interactive w/ prompt to create
gh issue comment 26 --edit-last                                   
? No comments found. Create one? Yes
- Press Enter to draft your comment in vi... 
? Submit? Yes
https://github.com/BagToad/testing-public-1/issues/26#issuecomment-2666801050

# interactive w/o prompt to create
gh issue comment 26 --edit-last --create-if-none
No comments found. Creating a new comment.
- Press Enter to draft your comment in vi... 
? Submit? Yes
https://github.com/BagToad/testing-public-1/issues/26#issuecomment-2666803605

Comment thread pkg/cmd/pr/shared/commentable.go Outdated
Comment thread pkg/cmd/pr/shared/commentable.go Outdated

@BagToad BagToad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for this @latzskim ❤️ ✨ Everything looks good 🥂

@BagToad
BagToad enabled auto-merge February 19, 2025 19:18
@BagToad
BagToad merged commit ab9f685 into cli:trunk Feb 19, 2025
@BagToad BagToad changed the title [gh issue/pr comment] Create a comment if no comment already exists [gh issue/pr comment] Add --create-if-none and prompts to create a comment if no comment already exists Feb 19, 2025
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Mar 6, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.67.0` -> `v2.68.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.68.0`](https://github.com/cli/cli/releases/tag/v2.68.0): GitHub CLI 2.68.0

[Compare Source](cli/cli@v2.67.0...v2.68.0)

#### What's Changed

##### ✨ Features

-   \[gh repo view] Improve error message for forked repo by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10334
-   Add signer-digest, source-ref, and source-digest options for `gh attestation verify` by [@&#8203;malancas](https://github.com/malancas) in cli/cli#10308
-   \[gh pr checkout] Add --no-tags option to git fetch commands in checkout by [@&#8203;latzskim](https://github.com/latzskim) in cli/cli#10479
-   \[`gh issue/pr comment`] Add `--create-if-none` and prompts to create a comment if no comment already exists  by [@&#8203;latzskim](https://github.com/latzskim) in cli/cli#10427
-   \[gh cache delete --all] Add `--succeed-on-no-caches` flag to return exit code 0 by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10327
-   \[gh release create] Fail when there are no new commits since the last release by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10398
-   update default upstream when forking repo during MR creation by [@&#8203;daviddl9](https://github.com/daviddl9) in cli/cli#10458

##### 🐛 Fixes

-   Refactor `GetLocalAttestations` and clean up custom registry transport by [@&#8203;malancas](https://github.com/malancas) in cli/cli#10382
-   Check `GH_REPO` too in addition to `--repo` for disambiguation by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10539
    -   (Fixes `gh secret` subcommands not working outside of a repository)
-   Fix unhandled panic in FindWorkflow and add tests by [@&#8203;jtmcg](https://github.com/jtmcg) in cli/cli#10521
-   Fix checkout when URL arg is from fork and cwd is upstream by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10512
-   \[gh api] Escape package name (URL encoding) for packages endpoint by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10384
-   Fix `remoteResolver` caching issue by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10456
-   Fix gh project item-edit to allow --number 0 as a valid value by [@&#8203;aryanbhosale](https://github.com/aryanbhosale) in cli/cli#10417
-   Add mutex to fix race in attestation test client by [@&#8203;codysoyland](https://github.com/codysoyland) in cli/cli#10439
-   Base64 decode GPG passphrase in deployment workflow by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10546

##### 📚 Docs & Chores

-   Deep Dive Document Release Process by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10503
-   Inconsistent format of examples in help text by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10508
-   Inconsistent format of description of flags (starting with lowercase letter) by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10507
-   Update Go version to 1.23 in CONTRIBUTING.md by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10504
-   Fix minor auth login help typo by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10501
-   docs: document how to revoke `gh` OAuth tokens in `auth logout`'s help by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10490
-   chore: update codespaces Go version by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10491
-   Allow injection of TUFMetadataDir in tests by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10478
-   refactor: use a more straightforward return value by [@&#8203;beforetech](https://github.com/beforetech) in cli/cli#10489
-   Use subtests in attestation verification integration tests by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10463
-   Fix typo in README by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10445
-   Update usage to lower-kebab-case by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10447
-   Standardize URLs by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10429
-   Remove trailing whitespace by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10430

##### :dependabot: Dependencies

-   Bump actions/attest-build-provenance from 2.2.0 to 2.2.2 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10518
-   Bump github.com/go-jose/go-jose/v4 from 4.0.2 to 4.0.5 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10499
-   Bump github.com/spf13/pflag from 1.0.5 to 1.0.6 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10338

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xODYuMCIsInVwZGF0ZWRJblZlciI6IjM5LjE4Ni4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
@ghost

This comment was marked as spam.

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.

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

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.