Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@BagToad
Copy link
Member

@BagToad BagToad commented Jun 3, 2025

Fixes #11064.

Adds tests for both issue edit and pr edit even though pr edit is the broken one.

This commit is a handful of changes around `gh pr edit --add-assignee` behavior.  Most notably, fixing a bug where the assigned actors weren't being dropped.

In addition to this, I was refactoring the testing setup to allow for individual test table scenarios could be contained.
@BagToad BagToad temporarily deployed to cli-automation June 3, 2025 13:28 — with GitHub Actions Inactive
@BagToad BagToad force-pushed the andyfeller/gh-pr-edit-assignees branch from 1c896d8 to ed4b901 Compare June 3, 2025 13:30
@BagToad BagToad marked this pull request as ready for review June 3, 2025 13:45
Copilot AI review requested due to automatic review settings June 3, 2025 13:45
@BagToad BagToad requested a review from a team as a code owner June 3, 2025 13:45
@BagToad BagToad requested a review from andyfeller June 3, 2025 13:45
@BagToad BagToad temporarily deployed to cli-automation June 3, 2025 13:45 — with GitHub Actions Inactive
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that assignees are preserved when running gh pr edit by tracking both display names and logins, and adds tests for both PR and issue editing workflows to cover actor-based assignments.

  • Populate Assignees.DefaultLogins in PR edit logic to preserve original assignees by login.
  • Refactor testSurveyor in PR edit tests and add a new interactive prompt test for display-name handling.
  • Update issue edit tests to assert on DefaultLogins and correct the mocked actor count.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/cmd/pr/edit/edit.go Set editable.Assignees.DefaultLogins when actors are used
pkg/cmd/pr/edit/edit_test.go Refactor testSurveyor, extend tests for actor display names
pkg/cmd/issue/edit/edit_test.go Adjust tests to check DefaultLogins and correct mock data
Comments suppressed due to low confidence (2)

pkg/cmd/issue/edit/edit_test.go:809

  • There's a typo in the function name mockIsssueNumberGetWithAssignedActors (extra 's'). It should be mockIssueNumberGetWithAssignedActors.
func mockIsssueNumberGetWithAssignedActors(_ *testing.T, reg *httpmock.Registry,

pkg/cmd/pr/edit/edit_test.go:536

  • [nitpick] The fieldsToEdit closures are nearly identical across multiple test cases. Consider extracting a helper function or fixture to reduce duplication and make test changes easier to maintain.
Surveyor: testSurveyor{

editable.Assignees.Default = pr.AssignedActors.DisplayNames()
editable.Assignees.DefaultLogins = pr.AssignedActors.Logins()
} else {
editable.Assignees.Default = pr.Assignees.Logins()
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

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

The DefaultLogins field is only set when AssignedActorsUsed is true. In the else branch, DefaultLogins remains nil, which could lead to missing login defaults in prompts. Consider also setting editable.Assignees.DefaultLogins = pr.Assignees.Logins() in the else block for consistency.

Suggested change
editable.Assignees.Default = pr.Assignees.Logins()
editable.Assignees.Default = pr.Assignees.Logins()
editable.Assignees.DefaultLogins = pr.Assignees.Logins()

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

I get it, but IDK man.

Copy link
Member

Choose a reason for hiding this comment

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

This is the kind of thing I meant when I said it was a bit "fragile". It's a bit "spooky action from a distance". It's hard to understand the relationship between these things. If you're up for it, we could spend a bit of time and see whether there is a design that we're happier with.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I think that'd be an interesting exercise.

Comment on lines 632 to +638
EditFieldsSurvey: func(p prShared.EditPrompter, eo *prShared.Editable, _ string) error {
// Checking that the display name is being used in the prompt.
require.Equal(t, eo.Assignees.Default, []string{"hubot", "MonaLisa (Mona Display Name)"})
require.Equal(t, []string{"hubot"}, eo.Assignees.Default)
require.Equal(t, []string{"hubot"}, eo.Assignees.DefaultLogins)

// Mocking a selection of only MonaLisa in the prompt.
eo.Assignees.Value = []string{"MonaLisa (Mona Display Name)"}
// Adding MonaLisa as PR assignee, should preserve hubot.
eo.Assignees.Value = []string{"hubot", "MonaLisa (Mona Display Name)"}
Copy link
Member Author

Choose a reason for hiding this comment

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

Thought: We are missing out on testing that eo.Assignees.Default is properly loaded with display names and not logins.

@williammartin williammartin merged commit 8baf5cc into trunk Jun 11, 2025
17 checks passed
@williammartin williammartin deleted the andyfeller/gh-pr-edit-assignees branch June 11, 2025 13:44
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jun 19, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | patch | `v2.74.1` -> `v2.74.2` |

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.74.2`](https://github.com/cli/cli/releases/tag/v2.74.2): GitHub CLI 2.74.2

[Compare Source](cli/cli@v2.74.1...v2.74.2)

#### What's Changed

##### πŸ› Fixes

- Fix assignees being dropped from `gh pr edit` by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11065
- Add accurate context when run rerun fails by [@&#8203;leudz](https://github.com/leudz) in cli/cli#10774
- Avoid requesting MR reviewer twice by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#11099
- Quote filenames suggested at the end of worklow run by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#11134
- Fix expected error output of TestRepo/repo-rename-transfer-ownership by [@&#8203;aconsuegra](https://github.com/aconsuegra) in cli/cli#10888

##### πŸ“š Docs & Chores

- Add instructions for MidnightBSD installation by [@&#8203;laffer1](https://github.com/laffer1) in cli/cli#10699
- docs: update install command for Debian by [@&#8203;MagneticNeedle](https://github.com/MagneticNeedle) in cli/cli#10935
- Fix step order for CodeQL workflow by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11145
- Add workflow to check `help wanted` labelling by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#11105
- Quote workflow conditional by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#11122
- Fix script path for help-wanted check by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11125
- Exclude 3rd party license compliance content from GHAS scanning by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#11127
- Second fix for file not found in help-wanted check by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11128
- Ensure gh executes in workflow check script by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#11133
- Improve help wanted check skipping logic by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11135

##### :dependabot: Dependencies

- Bump go to 1.24 by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#11142
- chore(deps): bump mislav/bump-homebrew-formula-action from 3.2 to 3.4 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#11066
- chore(deps): bump github.com/sigstore/protobuf-specs from 0.4.2 to 0.4.3 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#11092
- chore(deps): bump google.golang.org/grpc from 1.72.0 to 1.72.2 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#11033
- chore(deps): bump actions/attest-build-provenance from 2.3.0 to 2.4.0 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#11107
- chore(deps): bump github.com/in-toto/attestation from 1.1.1 to 1.1.2 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#11123
- chore(deps): bump github.com/google/go-containerregistry from 0.20.3 to 0.20.6 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#11120
- Bump golangci-lint to v2 by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#11121

#### New Contributors

- [@&#8203;MagneticNeedle](https://github.com/MagneticNeedle) made their first contribution in cli/cli#10935
- [@&#8203;laffer1](https://github.com/laffer1) made their first contribution in cli/cli#10699

**Full Changelog**: cli/cli@v2.74.1...v2.74.2

</details>

---

### Configuration

πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

β™» **Rebasing**: Whenever MR is behind base branch, 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:eyJjcmVhdGVkSW5WZXIiOiI0MC42MC4xIiwidXBkYXRlZEluVmVyIjoiNDAuNjAuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
bye976

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.

pr edit --add-assignee drops unspecified current assignees

5 participants