Skip to content

Make --forge-type skip network detection for custom hosts#83

Merged
andrew merged 3 commits intomainfrom
forge-type-skips-detection
May 9, 2026
Merged

Make --forge-type skip network detection for custom hosts#83
andrew merged 3 commits intomainfrom
forge-type-skips-detection

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented May 8, 2026

Fixes #80, fixes #84.

--forge-type was only used to pick a default hostname (gitea -> codeberg.org); it never reached newClient, which only consulted the config file's type = entry before falling back to network probing. So --host src.suse.de --forge-type gitea still probed https://src.suse.de and failed when the server was unreachable or didn't expose the detection endpoints.

newClient now checks a forgeTypeOverride (set from --forge-type in PersistentPreRun) before the config file, so an explicit --forge-type registers the right client for any --host or git-remote domain without probing. This flows through ForgeForDomain and resolve.Repo, so it covers every command. The type switch is pulled out into forgeForType and now also handles github for GHE hosts.

Two follow-ups raised on this PR are also folded in:

DetectForgeType discarded the transport error from the initial header probe and fell through to API probes that failed the same way, so an unreachable host produced only could not detect forge type for https://... with no hint that it was a DNS or connection failure. The header-probe error is now wrapped and returned directly, and the resolve-layer error suggests --forge-type or config type = as a way to skip detection.

Gitea pagination loops broke on len(results) < perPage, but Gitea clamps the page size to MAX_RESPONSE_ITEMS (default 50), so --limit 1000 returned one clamped page and stopped. All paginated gitea calls now use a shared lastPage() that reads the SDK-parsed Link headers when present and falls back to the short-page heuristic, with pageSize() capping requests at 50. Covers repos, branches, issues, PRs, releases, labels, milestones, notifications, collaborators, deploy keys, secrets, reviews, forks, and CI runs.

@andrew andrew mentioned this pull request May 8, 2026
@hramrach
Copy link
Copy Markdown

hramrach commented May 8, 2026

This appears to work almost correctly

forge version 
forge 0.4.2+7.79a7436

The open server is still detected

forge repo list kernelbugs --limit 1000 --host src.opensuse.org
NAME                               DESCRIPTION                           LANGUAGE  STARS
kernelbugs/kernel-source           Automatically generated; do not edit  Perl      0
kernelbugs/kernel-source-rt        Automatically generated; do not edit  Perl      0
kernelbugs/kernel-source-vanilla   Automatically generated; do not edit  Perl      0
kernelbugs/kernel-source-longterm  Automatically generated; do not edit  Perl      0

When type is omitted the message telling to use type is produced:

forge repo list kernelbugs --limit 1000 --host src.suse.de
Error: unknown forge at src.suse.de: detecting forge type for src.suse.de: could not detect forge type for https://src.suse.de (use --forge-type, or set type under [src.suse.de] in config, to skip detection)

but only with type provided connection error is reported, connection error should take priority

forge repo list kernelbugs --limit 1000 --host src.suse.de --forge-type gitea
Error: Get "https://src.suse.de/api/v1/users/kernelbugs/repos?limit=1000&page=1": dial tcp: lookup src.suse.de on 192.168.1.1:53: no such host

Finally when the connection to the correct network is established some repositories are listed (50/174)

forge repo list kernelbugs --limit 1000 --host src.suse.de --forge-type gitea | wc -l
51

@andrew andrew mentioned this pull request May 8, 2026
@andrew
Copy link
Copy Markdown
Contributor Author

andrew commented May 8, 2026

Updated, thanks for the feedback

@hramrach
Copy link
Copy Markdown

hramrach commented May 8, 2026

This appears to work correctly

forge version 
forge 0.4.2+9.f891fb9
forge repo list kernelbugs --limit 1000 --host src.opensuse.org
NAME                               DESCRIPTION                           LANGUAGE  STARS
kernelbugs/kernel-source           Automatically generated; do not edit  Perl      0
kernelbugs/kernel-source-rt        Automatically generated; do not edit  Perl      0
kernelbugs/kernel-source-vanilla   Automatically generated; do not edit  Perl      0
kernelbugs/kernel-source-longterm  Automatically generated; do not edit  Perl      0
forge repo list kernelbugs --limit 1000 --host src.suse.de 
Error: unknown forge at src.suse.de: detecting forge type for src.suse.de: could not detect forge type for https://src.suse.de: Get "https://src.suse.de": dial tcp: lookup src.suse.de on 192.168.1.1:53: no such host (use --forge-type, or set type under [src.suse.de] in config, to skip detection)
forge repo list kernelbugs --limit 1000 --host src.suse.de --forge-type gitea | wc -l
175

Thanks!

@andrew andrew merged commit 3f45c50 into main May 9, 2026
7 checks passed
@andrew andrew deleted the forge-type-skips-detection branch May 9, 2026 07:03
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.

Not all repositories listed --forge-type ineffective

2 participants