Skip to content

fix(spm): derive API URL from host for self-hosted instances#8955

Merged
jdx merged 3 commits intojdx:mainfrom
ThomasDutartre:fix/github-enterprise-spm-backend
Apr 7, 2026
Merged

fix(spm): derive API URL from host for self-hosted instances#8955
jdx merged 3 commits intojdx:mainfrom
ThomasDutartre:fix/github-enterprise-spm-backend

Conversation

@ThomasDutartre
Copy link
Copy Markdown
Contributor

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_ba always falls back to api.github.com for version resolution because api_url is not set in the tool options.

This causes a 404 when resolving versions, and there is no way to pass api_url when installing via mise use -g.

Solution

When api_url is not explicitly set, parse the tool name as a URL and derive the API URL from the host if it differs from github.com / gitlab.com:

  • GitHub Enterprise: {scheme}://{host}/api/v3
  • GitLab self-hosted: {scheme}://{host}/api/v4

Explicit api_url option still takes precedence. No behavior change for github.com / gitlab.com or shorthand notation.

Changes

  • src/backend/spm.rs: add derive_api_url_from_tool_name to GitProvider, called from from_ba when api_url is absent
  • src/github.rs: add API_PATH constant (/api/v3)
  • src/gitlab.rs: add API_PATH constant (/api/v4)
  • 4 new unit tests covering self-hosted GHE, self-hosted GitLab, public github.com, and explicit api_url precedence

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/backend/spm.rs Outdated
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 7, 2026

Greptile Summary

This PR fixes the SPM backend falling back to api.github.com when a full self-hosted GHE or GitLab URL is used as the tool name. The new derive_api_url_from_tool_name helper parses the tool name as a URL and, for any host other than github.com/gitlab.com, constructs the appropriate API URL by cloning the parsed URL struct and calling set_path — an approach that correctly preserves non-standard ports.

Confidence Score: 5/5

Safe 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

Filename Overview
src/backend/spm.rs Adds derive_api_url_from_tool_name to GitProvider; uses url.clone()+set_path to derive self-hosted API URLs (port-safe); 4 new unit tests covering GHE, self-hosted GitLab, public github.com, and explicit api_url precedence
src/github.rs Adds API_PATH constant '/api/v3' consumed by spm.rs for self-hosted GHE URL construction
src/gitlab.rs Adds API_PATH constant '/api/v4' consumed by spm.rs for self-hosted GitLab URL construction

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
Loading

Reviews (3): Last reviewed commit: "Apply feedbacks" | Re-trigger Greptile

Comment thread src/backend/spm.rs
Comment thread src/backend/spm.rs Outdated
@ThomasDutartre ThomasDutartre changed the title Support github enterprise url for spm backend fix(spm): derive API URL from host for self-hosted instances Apr 7, 2026
@ThomasDutartre ThomasDutartre marked this pull request as ready for review April 7, 2026 14:02
@jdx jdx merged commit b628d95 into jdx:main Apr 7, 2026
34 checks passed
mise-en-dev added a commit that referenced this pull request Apr 7, 2026
### 🚀 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)
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.

2 participants