fix(spm): derive API URL from host for self-hosted instances#8955
fix(spm): derive API URL from host for self-hosted instances#8955
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements logic to automatically derive API URLs for self-hosted GitHub and GitLab instances when the tool name is a full URL. It also adds corresponding unit tests and API path constants. Feedback was provided to improve the robustness of URL derivation by using Url crate methods instead of manual string formatting, ensuring support for custom ports, credentials, and IPv6 hosts.
Greptile SummaryThis PR fixes the SPM backend falling back to Confidence Score: 5/5Safe to merge; the fix is well-scoped and the previous port-handling concern from the review thread is addressed. No P0 or P1 issues remain. The implementation uses url.clone()+set_path which preserves port numbers, the explicit api_url opt still takes precedence, and all four new unit tests pass the expected behavior. The only pre-existing limitation (self-hosted GitLab at non-gitlab.com domains requires an explicit provider=gitlab opt) is documented by the new test. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[GitProvider::from_ba] --> B{api_url opt set?}
B -- Yes --> C[Use explicit api_url]
B -- No --> D[derive_api_url_from_tool_name]
D --> E{tool_name parseable\nas URL?}
E -- No --> F[Fallback: default public API URL]
E -- Yes --> G{host == github.com\nor gitlab.com?}
G -- Yes --> F
G -- No --> H[Clone URL struct\ncall set_path\npreserves port & scheme]
H --> I{kind?}
I -- GitHub --> J[path = /api/v3]
I -- GitLab --> K[path = /api/v4]
J --> L[Return derived API URL]
K --> L
Reviews (3): Last reviewed commit: "Apply feedbacks" | Re-trigger Greptile |
### 🚀 Features - **(config)** Add Tera template support to miserc.toml by @richardthe3rd in [#8867](#8867) ### 🐛 Bug Fixes - **(env)** include tools-only redactions in `mise env --redacted` by @jakedgy in [#8956](#8956) - **(env)** pass dependency env to vfox backend plugin hooks by @cprecioso in [#8952](#8952) - **(shim)** fix race condition when removing in make_shim, when multiple plugins provide the same shim by @brander-john in [#8947](#8947) - **(spm)** derive API URL from host for self-hosted instances by @ThomasDutartre in [#8955](#8955) - **(task)** resolve env vars in usage tera templates when flags are provided by @jdx in [#8957](#8957) ### 📚 Documentation - **(python)** clarify attestation settings must be under [settings] in mise.toml by @fru1tworld in [#8939](#8939) ### 📦 Registry - added sing-box by @tony-sol in [#8944](#8944) ### Chore - **(ci)** remove auto-draft PR workflow by @jdx in [#8945](#8945) ### New Contributors - @ThomasDutartre made their first contribution in [#8955](#8955) - @jakedgy made their first contribution in [#8956](#8956) - @brander-john made their first contribution in [#8947](#8947) - @fru1tworld made their first contribution in [#8939](#8939)
Problem
When using the SPM backend with a full URL pointing to a self-hosted GitHub Enterprise or GitLab instance (e.g.
spm:https://ghe.acme.com/org/Tool.git),GitProvider::from_baalways falls back toapi.github.comfor version resolution becauseapi_urlis not set in the tool options.This causes a 404 when resolving versions, and there is no way to pass
api_urlwhen installing viamise use -g.Solution
When
api_urlis not explicitly set, parse the tool name as a URL and derive the API URL from the host if it differs fromgithub.com/gitlab.com:{scheme}://{host}/api/v3{scheme}://{host}/api/v4Explicit
api_urloption still takes precedence. No behavior change forgithub.com/gitlab.comor shorthand notation.Changes
src/backend/spm.rs: addderive_api_url_from_tool_nametoGitProvider, called fromfrom_bawhenapi_urlis absentsrc/github.rs: addAPI_PATHconstant (/api/v3)src/gitlab.rs: addAPI_PATHconstant (/api/v4)api_urlprecedence