Skip to content

Fix pr edit when URL is provided #11057

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 1 commit into from
Jun 2, 2025
Merged

Fix pr edit when URL is provided #11057

merged 1 commit into from
Jun 2, 2025

Conversation

williammartin
Copy link
Member

@williammartin williammartin commented Jun 2, 2025

Description

Fixes #11055

The fundamental issue as described by @babakks here is that with the work done to support adding copilot as an issue assignee, pr edit started doing feature detection. However, when the argument provided to pr edit is a URL, there is a bit of a "race" between determining the base repo and constructing the feature detector.

When doing the projectsV1 deprecation work, I encountered this as well and took a shortcut for pr commands by pushing feature detection into the finder itself. The more correct solution is to do what I did with the issue commands and decouple argument parsing from API lookup. See #10811 for example. We should do this.

However, our team is about to have a number of days offsite together, and I am keen to get a patch release for this going, especially since it will take some time to roll out into actions images. Therefore this PR takes the shortest path I can think. It is very horrible, and that's a good thing because we won't let this sit around after our offsite.

It pushes the feature detection for actor assignees into the finder and exposes the fact that the server did or didn't support it on the PullRequest struct itself 🤮 .

E2E Tests

--- PASS: TestPullRequests (0.00s)
    --- PASS: TestPullRequests/pr-checkout-by-number (8.69s)
    --- PASS: TestPullRequests/pr-view (7.47s)
    --- PASS: TestPullRequests/pr-view-status-respects-simple-pushdefault (10.32s)
    --- PASS: TestPullRequests/pr-view-status-respects-remote-pushdefault (17.32s)
    --- PASS: TestPullRequests/pr-view-status-respects-push-destination (8.85s)
    --- PASS: TestPullRequests/pr-view-status-respects-branch-pushremote (17.09s)
    --- PASS: TestPullRequests/pr-view-same-org-fork (15.42s)
    --- PASS: TestPullRequests/pr-view-outside-repo (8.11s)
    --- PASS: TestPullRequests/pr-status-respects-cross-org (16.48s)
    --- PASS: TestPullRequests/pr-merge-rebase-strategy (12.88s)
    --- PASS: TestPullRequests/pr-merge-merge-strategy (11.27s)
    --- PASS: TestPullRequests/pr-list (7.52s)
    --- PASS: TestPullRequests/pr-create-without-upstream-config (8.06s)
    --- PASS: TestPullRequests/pr-create-with-metadata (9.79s)
    --- PASS: TestPullRequests/pr-create-respects-user-colon-branch-syntax (16.24s)
    --- PASS: TestPullRequests/pr-create-respects-simple-pushdefault (8.77s)
    --- PASS: TestPullRequests/pr-create-respects-remote-pushdefault (17.35s)
    --- PASS: TestPullRequests/pr-create-respects-push-destination (17.32s)
    --- PASS: TestPullRequests/pr-create-respects-branch-pushremote (18.46s)
    --- PASS: TestPullRequests/pr-create-remote-ref-with-branch-name-slash (17.07s)
    --- PASS: TestPullRequests/pr-create-push-default-upstream-no-merge-ref (8.28s)
    --- SKIP: TestPullRequests/pr-create-push-default-upstream-no-merge-ref-fork (0.01s)
    --- PASS: TestPullRequests/pr-create-no-local-repo (7.70s)
    --- PASS: TestPullRequests/pr-create-guesses-remote-from-sha (17.94s)
    --- PASS: TestPullRequests/pr-create-guesses-remote-from-sha-with-branch-name-slash (18.09s)
    --- PASS: TestPullRequests/pr-create-from-manual-merge-base (10.50s)
    --- PASS: TestPullRequests/pr-create-from-issue-develop-base (13.17s)
    --- PASS: TestPullRequests/pr-create-edit-with-project (19.56s)
    --- PASS: TestPullRequests/pr-create-basic (8.28s)
    --- PASS: TestPullRequests/pr-comment-new (9.38s)
    --- PASS: TestPullRequests/pr-comment-edit-last-without-comments-errors (9.32s)
    --- PASS: TestPullRequests/pr-comment-edit-last-without-comments-creates (9.36s)
    --- PASS: TestPullRequests/pr-comment-edit-last-with-comments (11.13s)
    --- PASS: TestPullRequests/pr-checkout (8.65s)
    --- PASS: TestPullRequests/pr-checkout-with-url-from-fork (18.82s)
PASS

@Copilot Copilot AI review requested due to automatic review settings June 2, 2025 13:04
@williammartin williammartin requested a review from a team as a code owner June 2, 2025 13:04
@williammartin williammartin requested a review from andyfeller June 2, 2025 13:04
Copy link
Contributor

@Copilot 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 patches pr edit to correctly request and handle assignable actors when a PR URL is provided by moving feature detection into the finder and exposing a flag on the PR struct.

  • Added end-to-end tests for actor assignment detection in the PR finder.
  • Updated the PR finder to detect assignedActors support and flag it on the returned PullRequest.
  • Simplified pr edit command to drive assignee behavior from the new AssignedActorsUsed flag; updated tests and API struct accordingly.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/cmd/pr/shared/finder_test.go Added TestFindAssignableActors to verify detection of assignedActors.
pkg/cmd/pr/shared/finder.go Injected feature detection for assignable actors and set a local flag.
pkg/cmd/pr/edit/edit_test.go Updated tests to supply Detector and set AssignedActorsUsed=true.
pkg/cmd/pr/edit/edit.go Removed inline detection, using pr.AssignedActorsUsed to adjust behavior.
api/queries_pr.go Introduced AssignedActorsUsed field on PullRequest with an explanatory comment.
Comments suppressed due to low confidence (1)

pkg/cmd/pr/shared/finder.go:245

  • [nitpick] The variable name actorAssigneesUsed differs from the struct field AssignedActorsUsed. Consider renaming it to assignedActorsUsed for consistency and clarity.
var actorAssigneesUsed bool

Copy link
Member

@babakks babakks left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉 Just a quick question/suggestion (feel free to ignore).

}

// If actors are assignable on this host then we additionally request the `assignedActors` field.
// Note that we don't remove the `assignees` field because some commands (`pr view`) do not display actor
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for explaining a question before raised

Copy link
Member

@BagToad BagToad left a comment

Choose a reason for hiding this comment

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

LGTM but yeah let's look at this again soon.

@williammartin williammartin merged commit c13f2f1 into trunk Jun 2, 2025
16 checks passed
@williammartin williammartin deleted the wm/fix-pr-edit branch June 2, 2025 15:44
@testak-m
Copy link

@williammartin @babakks @andyfeller @BagToad
Have you left for an offsite meeting?
I'm waiting for this fix to be reflected in Runner in Actions, it will take a while?

Copy link
Member

@babakks babakks left a comment

Choose a reason for hiding this comment

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

Re-reviewed this, and still looks okay. Just noticed a little semantic inconsistency in the newly added tests.

@babakks
Copy link
Member

babakks commented Jun 10, 2025

Just created #11090, as a follow-up issue to improve this fix.

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jun 13, 2025
This MR contains the following updates:

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

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

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

#### What's Changed

-   Document support for `@copilot` in `gh [pr|issue] edit --add-assignee` and `--remove-assignee` by [@&#8203;timrogers](https://github.com/timrogers) in cli/cli#11056
-   Fix pr edit when URL is provided by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#11057
-   Fix const in MR finder tests by [@&#8203;babakks](https://github.com/babakks) in cli/cli#11091

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

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

[Compare Source](cli/cli@v2.73.0...v2.74.0)

#### Security

A security vulnerability has been identified in a core `gh` dependency, `go-gh`, where an attacker-controlled GitHub Enterprise Server could result in executing arbitrary commands on a user's machine by replacing HTTP URLs provided by GitHub with local file paths for browsing.

This issue is addressed in this `gh` release by updating `go-gh` to a fixed version.

For more information, see GHSA-g9f5-x53j-h563

#### What's changed

##### ✨ Features

-   Add `preview prompter` command by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10745
-   \[gh run watch] Support `--compact` flag by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10629
-   Fix brew update notifications by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11024

##### 🐛 Fixes

-   Revert "\[gh config] Escape pipe symbol in Long desc for website manual" by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11004
-   Fix formatting in allowed values for `gh config --help` by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11003
-   fix: `gh gist edit` panic when no file in a gist by [@&#8203;phanen](https://github.com/phanen) in cli/cli#10627
-   Add retry logic when fetching TUF content in `gh attestation` commands by [@&#8203;malancas](https://github.com/malancas) in cli/cli#10943

##### 📚 Docs & Chores

-   Update README.md by [@&#8203;irhdab](https://github.com/irhdab) in cli/cli#11022
-   Add tests for `RenderJobs` and `RenderJobsCompact` by [@&#8203;babakks](https://github.com/babakks) in cli/cli#11013
-   Add example usage of `--head` option to `pr list` docs by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10979
-   Mention `pr create` will print the created MR's URL by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10980
-   Add Digest to ReleaseAsset struct by [@&#8203;bdehamer](https://github.com/bdehamer) in cli/cli#11030

##### :dependabot: Dependencies

-   Bump `go-gh` to v2.12.1 by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11043
-   chore(deps): bump github.com/gabriel-vasile/mimetype from 1.4.8 to 1.4.9 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10825
-   Update sigstore-go dependency to v1.0.0 by [@&#8203;malancas](https://github.com/malancas) in cli/cli#11028
-   chore(deps): bump github.com/sigstore/protobuf-specs from 0.4.1 to 0.4.2 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10999
-   chore(deps): bump github.com/yuin/goldmark from 1.7.8 to 1.7.12 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#11032

#### New Contributors

-   [@&#8203;irhdab](https://github.com/irhdab) made their first contribution in cli/cli#11022
-   [@&#8203;phanen](https://github.com/phanen) made their first contribution in cli/cli#10627

**Full Changelog**: cli/cli@v2.73.0...v2.74.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:eyJjcmVhdGVkSW5WZXIiOiI0MC41MC4wIiwidXBkYXRlZEluVmVyIjoiNDAuNTAuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
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 edit https://... --add-label ... does not deduce --repo from the URL automatically
5 participants