Summary
forge api builds API base URLs from domain-name heuristics instead of the
resolved forge type. This breaks self-hosted instances whenever the domain name
does not contain the substring that forge api expects for that forge.
Reproduction
Given a self-hosted forge with a neutral domain name:
origin git@mylab.example.org:group/project.git
and a config declaring its type:
[mylab.example.org]
type = gitlab
or:
[mylab.example.org]
type = gitea
or:
[mylab.example.org]
type = forgejo
running:
does not reliably use the API root for the configured forge type.
Observed behavior and source
At upstream/main commit b3eb7489772377d24e9687a95f0d5bfdd5027d2d,
internal/cli/api.go chooses the API root by matching substrings in the
domain name.
This produces these built-in behaviors:
- domains containing
github get a GitHub-style API root
- domains containing
gitlab get /api/v4
- domains containing
bitbucket get Bitbucket Cloud's API root
- everything else falls back to
/api/v1
Examples:
- a GitLab instance at
mylab.example.org is treated as /api/v1 instead of
/api/v4
- a GitHub Enterprise instance at
vcs.example.org would not get the GitHub API
root
- any self-hosted forge whose hostname does not include the expected substring
can be routed to the wrong API root
Expected behavior
If the forge type is known from --forge-type, config, or resolution,
forge api should use that type to select the API root, independently of the
domain name.
For example:
[mylab.example.org]
type = gitlab
should imply:
https://mylab.example.org/api/v4
even though the domain does not contain gitlab.
Root cause
The behavior depends on hostname spelling rather than the actual forge type.
The repository/domain resolution already determines or can access the forge
type, but forge api does not use that information when constructing the API
base URL.
The API base URL should be derived in this order:
- explicit
--forge-type
- configured domain
type
- known-domain defaults
- legacy domain-name heuristics as a fallback
Summary
forge apibuilds API base URLs from domain-name heuristics instead of theresolved forge type. This breaks self-hosted instances whenever the domain name
does not contain the substring that
forge apiexpects for that forge.Reproduction
Given a self-hosted forge with a neutral domain name:
and a config declaring its type:
or:
or:
running:
forge api "<endpoint>"does not reliably use the API root for the configured forge type.
Observed behavior and source
At
upstream/maincommitb3eb7489772377d24e9687a95f0d5bfdd5027d2d,internal/cli/api.gochooses the API root by matching substrings in thedomain name.
This produces these built-in behaviors:
githubget a GitHub-style API rootgitlabget/api/v4bitbucketget Bitbucket Cloud's API root/api/v1Examples:
mylab.example.orgis treated as/api/v1instead of/api/v4vcs.example.orgwould not get the GitHub APIroot
can be routed to the wrong API root
Expected behavior
If the forge type is known from
--forge-type, config, or resolution,forge apishould use that type to select the API root, independently of thedomain name.
For example:
should imply:
even though the domain does not contain
gitlab.Root cause
The behavior depends on hostname spelling rather than the actual forge type.
The repository/domain resolution already determines or can access the forge
type, but
forge apidoes not use that information when constructing the APIbase URL.
The API base URL should be derived in this order:
--forge-typetype