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

Skip to content

Conversation

@williammartin
Copy link
Member

Description

Relates to: #10714
Builds on: #10911

This PR tackles projectv1 deprecation on pr creation for the interactive mode.

Reviewer Notes

DO NOT MERGE into base branch, wait for base branch to be merged into trunk.

You can verify the presence or absence of projects by running:

GH_DEBUG=api ./bin/gh pr create 2>&1

And proceeding through the interactive prompts to add a project, and submit a PR with a project added to the metadata.

This exists for queries RepositoryProjectList and OrganizationProjectList

@williammartin williammartin requested a review from a team as a code owner May 2, 2025 15:02
@williammartin williammartin requested review from andyfeller and removed request for a team May 2, 2025 15:02
@williammartin williammartin changed the title wm/projectsv1 deprecation pr create rest Feature detect v1 projects on interactive flow May 2, 2025
@williammartin williammartin changed the title Feature detect v1 projects on interactive flow Feature detect v1 projects on interactive pr create May 2, 2025
As far as I can see, when there is project metadata, the preview option
will never be shown in the interactive multiselect, so I don't believe
this change has any functional difference. However, I did use the
opportunity to drive out tests for generateCompareURL
@williammartin williammartin force-pushed the wm/projectsv1-deprecation-pr-create-rest branch from c237606 to 1a5b7ca Compare May 2, 2025 15:42
Base automatically changed from wm/projectsv1-deprecation-pr-web to trunk May 6, 2025 12:19
Copy link
Member

@andyfeller andyfeller left a comment

Choose a reason for hiding this comment

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

Looks good to me! ✨ Nothing blocking

Comment on lines +147 to +150
index, err := IndexFor(options, answer)
if err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

thought: this will return an error if any answer is not an available option. IndexFor returns -1 for the int index of the answer, which is necessary being a literal with anything 0 or more being a valid index while this has []int.

makes sense

httpmock.StringResponse(`
{ "data": { "repository": { "projects": {
"nodes": [
{ "name": "ProjectV1Title", "id": "PROJECTV1ID", "resourcePath": "/OWNER/REPO/projects/1" }
Copy link
Member

Choose a reason for hiding this comment

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

praise: thanks for the distinct v1 project info vs v2 project

ProjectTitles: []string{"ProjectTitle"},
},
projectsV1Support: gh.ProjectsV1Unsupported,
want: "https://github.com/OWNER/REPO/compare/main...feature?body=&expand=1&projects=OWNER%2FREPO%2F3",
Copy link
Member

Choose a reason for hiding this comment

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

nit: I wish there was a different way to craft this type of string as the URL encoding requires a bit of care from the review's part map the 3 in %2F3 as the resourcePath above

Copy link
Member Author

Choose a reason for hiding this comment

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

Would it help if I provided the unescaped URL and passed it into a function that did the escaping?

Copy link
Member

Choose a reason for hiding this comment

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

honestly, I struggled with a good suggestion that didn't feel over engineered, so I don't know if there is a simple solution but wish there was. 🤷

Comment on lines +2280 to +2287
// Register a handler to check for projects V2 just to avoid the registry panicking, even
// though we return a 500 error. This is because the project lookup is done in parallel
// so the previous error doesn't early exit.
reg.Register(
httpmock.GraphQL(`projectsV2`),
// Simulate a GraphQL error to early exit the test.
httpmock.StatusStringResponse(500, ""),
)
Copy link
Member

Choose a reason for hiding this comment

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

praise: thank you for the comment explaining this 🙇

Comment on lines +2296 to +2300
if p == "Title (required)" {
return "Test Title", nil
} else {
return "", prompter.NoSuchPromptErr(p)
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: I know it isn't functionally any different but 🤏 slimmer

Suggested change
if p == "Title (required)" {
return "Test Title", nil
} else {
return "", prompter.NoSuchPromptErr(p)
}
if p == "Title (required)" {
return "Test Title", nil
}
return "", prompter.NoSuchPromptErr(p)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Think I just copy and pasted this from somewhere.

Comment on lines +2303 to +2307
if p == "Body" {
return "Test Body", nil
} else {
return "", prompter.NoSuchPromptErr(p)
}
Copy link
Member

@andyfeller andyfeller May 6, 2025

Choose a reason for hiding this comment

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

Suggested change
if p == "Body" {
return "Test Body", nil
} else {
return "", prompter.NoSuchPromptErr(p)
}
if p == "Body" {
return "Test Body", nil
}
return "", prompter.NoSuchPromptErr(p)

Comment on lines +2356 to +2358
// Ignore the error because we have no way to really stub it without
// fully stubbing a GQL error structure in the request body.
_ = createRun(&opts)
Copy link
Member

Choose a reason for hiding this comment

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

question: what's your opinion on when to combine lines like this with the initialization on line 2323 versus separate?

genuine curiosity as they're functionally the same, just unsure if intentional.

_ = createRun(&CreateOptions{
Detector: &fd.EnabledDetectorMock{},
IO: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: reg}, nil
},
GitClient: &git.Client{
GhPath: "some/path/gh",
GitPath: "some/path/git",
},
Remotes: func() (context.Remotes, error) {
return context.Remotes{
{
Remote: &git.Remote{
Name: "upstream",
Resolved: "base",
},
Repo: ghrepo.New("OWNER", "REPO"),
},
}, nil
},
Finder: shared.NewMockFinder("feature", nil, nil),
HeadBranch: "feature",
TitleProvided: true,
BodyProvided: true,
Title: "Test Title",
Body: "Test Body",
// Required to force a lookup of projects
Projects: []string{"Project"},
})

Copy link
Member Author

Choose a reason for hiding this comment

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

Just copy and pasted from different locations. Happy to combine into one form if you prefer one or the other.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for confirming; I don't really care but making sure to ask curious question in case there was something.

Comment on lines +2391 to +2395
if p == "Title (required)" {
return "Test Title", nil
} else {
return "", prompter.NoSuchPromptErr(p)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if p == "Title (required)" {
return "Test Title", nil
} else {
return "", prompter.NoSuchPromptErr(p)
}
if p == "Title (required)" {
return "Test Title", nil
}
return "", prompter.NoSuchPromptErr(p)

Comment on lines +2398 to +2402
if p == "Body" {
return "Test Body", nil
} else {
return "", prompter.NoSuchPromptErr(p)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if p == "Body" {
return "Test Body", nil
} else {
return "", prompter.NoSuchPromptErr(p)
}
if p == "Body" {
return "Test Body", nil
}
return "", prompter.NoSuchPromptErr(p)

})

// Verify that our request contained projectCards
// Verify that our request did not contain projectCards
Copy link
Member

Choose a reason for hiding this comment

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

praise: thank you for catching and fixing this

@williammartin williammartin merged commit a2fcb9b into trunk May 6, 2025
14 checks passed
@williammartin williammartin deleted the wm/projectsv1-deprecation-pr-create-rest branch May 6, 2025 13:24
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request May 20, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.72.0` -> `v2.73.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.73.0`](https://github.com/cli/cli/releases/tag/v2.73.0): GitHub CLI 2.73.0

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

#### :copilot: Copilot Coding Agent Support

You can now assign issues to GitHub Copilot directly from `gh`, just as you would assign them to a teammate. Use `gh issue edit <number> --add-assignee @&#8203;copilot` to assign the GitHub Copilot coding agent, and Copilot will work in the background to understand the issue, propose a solution, and open a pull request when it's ready for your review. If you run `gh issue edit` interactively, `Copilot (AI)` will be displayed as a potential assignee. This feature is available for GitHub Copilot Pro+ and Copilot Enterprise subscribers. For more details, refer to [the full changelog post for Copilot coding agent](https://github.blog/changelog/2025-05-19-github-copilot-coding-agent-in-public-preview/).

#### What's Changed

##### ✨ Features

-   Copilot is assignable to issues and pull requests with `issue edit` and `pr edit` by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10992
    -   `gh issue edit`: actors are assignable to issues by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10960
    -   `gh pr edit`: Assign actors to pull requests by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10984
    -   `issue edit`, `pr edit`: handle display names in interactive assignee editing   by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10990
    -   `issue edit`, `pr edit`: Support special non-interactive (flags) assignee name `@copilot` by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10991
-   \[gh issue/pr comment] Add support for last comment delete for issues and MRs by [@&#8203;sinansonmez](https://github.com/sinansonmez) in cli/cli#10596
-   \[gh issue view] Expose `closedByPullRequestsReferences` JSON field by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10941
-   Accessible prompter always displays selection defaults in a format readable by a screen reader by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10937

##### 🐛 Fixes

-   Fix `StatusJSONResponse` usage by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10810
-   Fix panic on `gh pr view 0` by [@&#8203;nopcoder](https://github.com/nopcoder) in cli/cli#10729
-   Fix flakey test for accessible prompter by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10918
-   Fix accessible prompter flaky tests by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10977
-   Handle missing archive URLs on release download by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10947
-   Fix bug when removing all MR reviewers by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10975

##### 📚 Docs & Chores

-   Feature detect v1 projects on pr view by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10821
-   Feature detect v1 projects on non-interactive pr create by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10909
-   Feature detect v1 projects on web mode pr create by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10911
-   Feature detect v1 projects on interactive `pr create` by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10915
-   Feature detect v1 projects on pr edit by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10942
-   Move predicate type filtering in `gh attestation verify` by [@&#8203;malancas](https://github.com/malancas) in cli/cli#10670
-   Improve assertion for disabled echo mode by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10927

##### :dependabot: Dependencies

-   chore(deps): bump actions/attest-build-provenance from 2.2.2 to 2.3.0 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10886
-   chore(deps): bump github.com/cpuguy83/go-md2man/v2 from 2.0.6 to 2.0.7 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10869

#### What's Changed

#### New Contributors

-   [@&#8203;sinansonmez](https://github.com/sinansonmez) made their first contribution in cli/cli#10596
-   [@&#8203;nopcoder](https://github.com/nopcoder) made their first contribution in cli/cli#10729

**Full Changelog**: cli/cli@v2.72.0...v2.73.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:eyJjcmVhdGVkSW5WZXIiOiI0MC4xNS4wIiwidXBkYXRlZEluVmVyIjoiNDAuMTUuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
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.

3 participants