8000 Editing last comment on issue or pull request only creates comment if --create-if-none flag is set by andyfeller · Pull Request #10625 · cli/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Editing last comment on issue or pull request only creates comment if --create-if-none flag is set #10625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 19, 2025

Conversation

andyfeller
Copy link
Member
@andyfeller andyfeller commented Mar 18, 2025

Fixes #10580

On top of fixing the underlying bug with creating new comments by default if editing issue or pull requests without comments, the following changes focus heavily on testing along.

Manual acceptance test results

Using the following script, all new acceptance tests pass:

$ bash test.sh
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │                       TEST                       │             PACKAGE               │
│─────────┼─────────┼──────────────────────────────────────────────────┼───────────────────────────────────│
│  PASS   │    9.02 │ TestIssues/issue-comment-edit-last-with-comments │ github.com/cli/cli/v2/acceptance  │
│  PASS   │    0.00 │ TestIssues                                       │ github.com/cli/cli/v2/acceptance  │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             PACKAGE              │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │  9.54s  │ github.com/cli/cli/v2/acceptance │  --   │  2   │  0   │  0    │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │                            TEST                             │             PACKAGE               │
│─────────┼─────────┼─────────────────────────────────────────────────────────────┼───────────────────────────────────│
│  PASS   │    6.17 │ TestIssues/issue-comment-edit-last-without-comments-creates │ github.com/cli/cli/v2/acceptance  │
│  PASS   │    0.00 │ TestIssues                                                  │ github.com/cli/cli/v2/acceptance  │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             PACKAGE              │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │  6.68s  │ github.com/cli/cli/v2/acceptance │  --   │  2   │  0   │  0    │
└────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │                            TEST                            │             PACKAGE               │
│─────────┼─────────┼────────────────────────────────────────────────────────────┼───────────────────────────────────│
│  PASS   │    4.45 │ TestIssues/issue-comment-edit-last-without-comments-errors │ github.com/cli/cli/v2/acceptance  │
│  PASS   │    0.00 │ TestIssues                                                 │ github.com/cli/cli/v2/acceptance  │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             PACKAGE              │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │  4.96s  │ github.com/cli/cli/v2/acceptance │  --   │  2   │  0   │  0    │
└────────────────────────────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             TEST             │             PACKAGE               │
│─────────┼─────────┼──────────────────────────────┼───────────────────────────────────│
│  PASS   │    6.04 │ TestIssues/issue-comment-new │ github.com/cli/cli/v2/acceptance  │
│  PASS   │    0.00 │ TestIssues                   │ github.com/cli/cli/v2/acceptance  │
└──────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             PACKAGE              │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │  6.54s  │ github.com/cli/cli/v2/acceptance │  --   │  2   │  0   │  0    │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │                        TEST                         │             PACKAGE               │
│─────────┼─────────┼─────────────────────────────────────────────────────┼───────────────────────────────────│
│  PASS   │    9.63 │ TestPullRequests/pr-comment-edit-last-with-comments │ github.com/cli/cli/v2/acceptance  │
│  PASS   │    0.00 │ TestPullRequests                                    │ github.com/cli/cli/v2/acceptance  │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             PACKAGE              │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │ 10.15s  │ github.com/cli/cli/v2/acceptance │  --   │  2   │  0   │  0    │
└────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │                              TEST                              │             PACKAGE               │
│─────────┼─────────┼────────────────────────────────────────────────────────────────┼───────────────────────────────────│
│  PASS   │    8.43 │ TestPullRequests/pr-comment-edit-last-without-comments-creates │ github.com/cli/cli/v2/acceptance  │
│  PASS   │    0.00 │ TestPullRequests                                               │ github.com/cli/cli/v2/acceptance  │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             PACKAGE              │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │  8.99s  │ github.com/cli/cli/v2/acceptance │  --   │  2   │  0   │  0    │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │              TEST               │             PACKAGE               │
│─────────┼─────────┼─────────────────────────────────┼───────────────────────────────────│
│  PASS   │    7.78 │ TestPullRequests/pr-comment-new │ github.com/cli/cli/v2/acceptance  │
│  PASS   │    0.00 │ TestPullRequests                │ github.com/cli/cli/v2/acceptance  │
└─────────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             PACKAGE              │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │  8.34s  │ github.com/cli/cli/v2/acceptance │  --   │  2   │  0   │  0    │
└────────────────────────────────────────────────────────────────────────────────────┘
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │                             TEST                              │             PACKAGE               │
│─────────┼─────────┼───────────────────────────────────────────────────────────────┼───────────────────────────────────│
│  PASS   │    6.22 │ TestPullRequests/pr-comment-edit-last-without-comments-errors │ github.com/cli/cli/v2/acceptance  │
│  PASS   │    0.00 │ TestPullRequests                                              │ github.com/cli/cli/v2/acceptance  │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             PACKAGE              │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │  6.74s  │ github.com/cli/cli/v2/acceptance │  --   │  2   │  0   │  0    │
└────────────────────────────────────────────────────────────────────────────────────┘
Shell script for running acceptance tests

#! /usr/bin/env bash

export GH_ACCEPTANCE_TOKEN=$(gh auth token --hostname github.com)
export GH_ACCEPTANCE_HOST=github.com
export GH_ACCEPTANCE_ORG=gh-acceptance-testing

set -o pipefail && GH_ACCEPTANCE_SCRIPT=issue-comment-edit-last-with-comments.txtar            go test -tags acceptance -json -run ^TestIssues$ github.com/cli/cli/v2/acceptance  | tparse --all go test
set -o pipefail && GH_ACCEPTANCE_SCRIPT=issue-comment-edit-last-without-comments-creates.txtar go test -tags acceptance -json -run ^TestIssues$ github.com/cli/cli/v2/acceptance  | tparse --all go test
set -o pipefail && GH_ACCEPTANCE_SCRIPT=issue-comment-edit-last-without-comments-errors.txtar  go test -tags acceptance -json -run ^TestIssues$ github.com/cli/cli/v2/acceptance  | tparse --all go test
set -o pipefail && GH_ACCEPTANCE_SCRIPT=issue-comment-new.txtar                                go test -tags acceptance -json -run ^TestIssues$ github.com/cli/cli/v2/acceptance  | tparse --all go test

set -o pipefail && GH_ACCEPTANCE_SCRIPT=pr-comment-edit-last-with-comments.txtar               go test -tags acceptance -json -run ^TestPullRequests$ github.com/cli/cli/v2/acceptance  | tparse --all go test
set -o pipefail && GH_ACCEPTANCE_SCRIPT=pr-comment-edit-last-without-comments-creates.txtar    go test -tags acceptance -json -run ^TestPullRequests$ github.com/cli/cli/v2/acceptance  | tparse --all go test
set -o pipefail && GH_ACCEPTANCE_SCRIPT=pr-comment-new.txtar                                   go test -tags acceptance -json -run ^TestPullRequests$ github.com/cli/cli/v2/acceptance  | tparse --all go test
set -o pipefail && GH_ACCEPTANCE_SCRIPT=pr-comment-edit-last-without-comments-errors.txtar     go test -tags acceptance -json -run ^TestPullRequests$ github.com/cli/cli/v2/acceptance  | tparse --all go test

There is still a bit of work to get the gh pr comment tests in order, however this goes a way towards fixing the issue along with acceptance tests.

Also, it turns out some of the issue acceptance tests were really running `pr` tests.
This commit brings the `gh issue comment` and `gh pr comment` tests in line with one another while also addressing some corner cases that weren't previously tested.
@andyfeller andyfeller marked this pull request as ready for review March 18, 2025 20:24
@andyfeller andyfeller requested a review from a team as a code owner March 18, 2025 20:24
@andyfeller andyfeller requested a review from BagToad March 18, 2025 20:24
@@ -234,13 +235,29 @@ func Test_commentRun(t *testing.T) {
InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
},
emptyComments: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

While reviewing these tests, I felt it was important to try capturing the comment state more explicitly as an aid to maintainers. 🤔

}{
{
name: "interactive editor",
name: "creating new comment with interactive editor succeeds",
Copy link
Member Author

Choose a reason for hiding this comment

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

Test name changes were meant to aid maintainers in understanding the user experience under test

This comment was marked as spam.

Comment on lines +325 to +333
name: "updating last comment with non-interactive web errors because there are no comments",
input: &shared.CommentableOptions{
Interactive: false,
InputType: shared.InputTypeWeb,
Body: "",
EditLast: true,
CreateIfNone: true,

OpenInBrowser: func(u string) error {
assert.Contains(t, u, "#issuecomment-111")
return nil
},
Interactive: false,
InputType: shared.InputTypeWeb,
Body: "",
EditLast: true,
},
stderr: "Opening https://github.com/OWNER/REPO/issues/123 in your browser.\n",
emptyComments: true,
wantsErr: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

Honestly, I think we shouldn't error if navigating to the web browser, but this was previous behavior thus kept it as-is.

This comment was marked as spam.

@andyfeller andyfeller changed the title Initial pass fixing gh issue and gh pr comment Editing last comment on issue or pull request only creates comment if --create-if-none flag is set Mar 18, 2025
Copy link
Member
@williammartin williammartin left a comment

Choose a reason for hiding this comment

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

Approved with some nits. Very nice PR.

@andyfeller andyfeller enabled auto-merge March 19, 2025 12:09
@williammartin williammartin disabled auto-merge March 19, 2025 12:12
@andyfeller andyfeller merged commit 45ffa3c into trunk Mar 19, 2025
16 checks passed
@andyfeller andyfeller deleted the andyfeller/10580-edit-last-regression branch March 19, 2025 12:24
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Mar 26, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.68.1` -> `v2.69.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.69.0`](https://github.com/cli/cli/releases/tag/v2.69.0): GitHub CLI 2.69.0

[Compare Source](cli/cli@v2.68.1...v2.69.0)

#### What's Changed

##### Features

-   Commands that accept filepath arguments will do glob expansion for `*` characters, by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10413

##### Bug Fixes

-   `gh issue/pr comment --edit-last` no longer creates a comment in non-interactive mode if there weren't one. A new flag `--create-if-none` provides this behaviour, by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#10625
-   `gh repo sync` provides a more informative error for missing workflow permissions when the token is provided by a GitHub app, by [@&#8203;wata727](https://github.com/wata727) in cli/cli#10574
-   `gh api` no longer tries to encode URLs incorrectly, by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10630

##### Other

-   Add cli-discuss-automation environment to triage.md by [@&#8203;jtmcg](https://github.com/jtmcg) in cli/cli#10552
-   chore: remove redundant word in comment by [@&#8203;kevincatty](https://github.com/kevincatty) in cli/cli#10586
-   Bump golang.org/x/net from 0.34.0 to 0.36.0 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10593

#### New Contributors

-   [@&#8203;kevincatty](https://github.com/kevincatty) made their first contribution in cli/cli#10586
-   [@&#8203;wata727](https://github.com/wata727) made their first contribution in cli/cli#10574

**Full Changelog**: cli/cli@v2.68.1...v2.69.0

</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:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMTMuNSIsInVwZGF0ZWRJblZlciI6IjM5LjIxMy41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
@ghost

This comment was marked as spam.

@atomicbomb12

This comment was marked as spam.

1 similar comment
@atomicbomb12

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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gh pr comment --edit-last now creates if no previous comment
3 participants
0