Skip to content

fix forge api base url construction#141

Merged
andrew merged 3 commits into
git-pkgs:mainfrom
pigam:api-base-url
Jul 23, 2026
Merged

fix forge api base url construction#141
andrew merged 3 commits into
git-pkgs:mainfrom
pigam:api-base-url

Conversation

@pigam

@pigam pigam commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Fix forge api API base URL selection for self-hosted forge instances.

forge api previously selected the API root using domain-name substring checks, for example by looking for gitlab in the hostname. This breaks self-hosted instances whose domain does not include the expected forge-specific substring.

Closes #140

Changes

  • Extract API base URL selection into apiBaseURL.
  • Resolve the API root from:
    1. explicit --forge-type
    2. configured domain type
    3. known-domain defaults
    4. existing hostname heuristics as fallback
  • Add unit tests for:
    • known domains
    • unknown domains with explicit forge type
    • unknown domains with configured forge type
    • unknown domains without type information

pigam added 2 commits July 20, 2026 17:56
Add unit tests covering known domains, explicit forge types, configured forge types, and unknown-domain fallback behavior.
@pigam
pigam marked this pull request as draft July 21, 2026 08:59
@pigam

pigam commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Further analysis : the api base url is a property of a forge.

resolve.Repo returns a Forge, but the result is ignored here.

_, owner, repoName, domain, err := resolve.Repo(flagRepo, flagForgeType)
^
# forge !

Normal, as the Forge interface has not yet a way to return this information.

I think a cleaner solution would be to add APIBaseURL to the Forge interface, but this would force the change on all actual forges backend.

An opinion ?

@andrew

andrew commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Agreed, the API base URL belongs to the resolved forge. I’d use a small companion interface such as APIBaseURLProvider rather than changing Forge, so external implementations do not break. Then forge api can use the resolved backend directly, including types found by probing and GitHub Enterprise’s /api/v3 URL.

Add an optional APIBaseURLProvider interface and implement it for the
built-in forge backends. Use the resolved forge in `forge api` to derive
the API root, while preserving the legacy domain heuristic as a fallback
for forge implementations that do not expose an API base URL.

Add tests for backend-provided API URLs, legacy fallback behavior, and
self-hosted GitLab domains configured with `type = gitlab`.
@pigam

pigam commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

The last version should be cleaner.

@pigam
pigam marked this pull request as ready for review July 23, 2026 06:43
@andrew
andrew merged commit 355ddfc into git-pkgs:main Jul 23, 2026
4 checks passed
This was referenced Jul 23, 2026
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.

🐛 forge api ignores forge type for base URL

2 participants