Repository navigation
Feat(url): Allow a Gerrit host to be declared - #520
Merged
ModeSevenIndustrialSolutions merged 1 commit intoSep 24, 2026
Conversation
ModeSevenIndustrialSolutions
temporarily deployed
to
integration
September 21, 2026 17:14 — with
GitHub Actions
Inactive
ModeSevenIndustrialSolutions
force-pushed
the
feat/declare-gerrit-host
branch
from
September 21, 2026 17:24
c319666 to
3a8efdf
Compare
ModeSevenIndustrialSolutions
temporarily deployed
to
integration
September 21, 2026 17:24 — with
GitHub Actions
Inactive
ModeSevenIndustrialSolutions
force-pushed
the
feat/declare-gerrit-host
branch
from
September 21, 2026 17:39
3a8efdf to
294c882
Compare
ModeSevenIndustrialSolutions
temporarily deployed
to
integration
September 21, 2026 17:39 — with
GitHub Actions
Inactive
ModeSevenIndustrialSolutions
force-pushed
the
feat/declare-gerrit-host
branch
from
September 21, 2026 17:50
294c882 to
e0a990d
Compare
ModeSevenIndustrialSolutions
temporarily deployed
to
integration
September 21, 2026 17:50 — with
GitHub Actions
Inactive
ModeSevenIndustrialSolutions
force-pushed
the
feat/declare-gerrit-host
branch
from
September 21, 2026 22:10
e0a990d to
e5eb078
Compare
ModeSevenIndustrialSolutions
temporarily deployed
to
integration
September 21, 2026 22:10 — with
GitHub Actions
Inactive
ModeSevenIndustrialSolutions
force-pushed
the
feat/declare-gerrit-host
branch
from
September 23, 2026 11:00
e5eb078 to
d091c43
Compare
ModeSevenIndustrialSolutions
temporarily deployed
to
integration
September 23, 2026 11:00 — with
GitHub Actions
Inactive
ModeSevenIndustrialSolutions
force-pushed
the
feat/declare-gerrit-host
branch
from
September 23, 2026 13:02
d091c43 to
c7024bd
Compare
ModeSevenIndustrialSolutions
temporarily deployed
to
integration
September 23, 2026 13:02 — with
GitHub Actions
Inactive
ModeSevenIndustrialSolutions
force-pushed
the
feat/declare-gerrit-host
branch
from
September 23, 2026 13:49
c7024bd to
9f7c3bf
Compare
ModeSevenIndustrialSolutions
marked this pull request as ready for review
September 23, 2026 13:49
ModeSevenIndustrialSolutions
temporarily deployed
to
integration
September 23, 2026 13:49 — with
GitHub Actions
Inactive
ModeSevenIndustrialSolutions
force-pushed
the
feat/declare-gerrit-host
branch
from
September 23, 2026 13:59
9f7c3bf to
5b16129
Compare
ModeSevenIndustrialSolutions
temporarily deployed
to
integration
September 23, 2026 13:59 — with
GitHub Actions
Inactive
GitHub Enterprise hosts are declared before they are addressed; Gerrit hosts were only inferred, from the shape of a URL path. Routing read that path alone, so a host declared as GitHub Enterprise was still handed to the Gerrit client whenever a URL carried /c/.../+/ or /q/topic: -- and the operator saw a Gerrit credential error for a host they had explicitly named as GitHub. A declaration is a statement about the host; a path shape is a guess about the URL. The declaration decides, which is the rule local_repo._looks_like_gerrit_remote already applies to remotes. --gerrit-host, DEPENDAMERGE_GERRIT_HOST and DEPENDAMERGE_GERRIT_HOSTS mirror the GitHub settings, lazily resolved and deferring a malformed value for the same reason iter_enterprise_hosts does. There is no Gerrit default to pick, and so no equivalent of default_github_host: a Gerrit target always names its own server. For the same reason the sources combine rather than rank: --gerrit-host adds a host, it does not override the environment. A malformed declaration is ignored while routing, so a stale entry for another server cannot fail an unrelated target. One naming the target's own host with a port is reported instead, since ignoring it sent a host the operator meant as Gerrit to GitHub guidance. Only a value that is exactly host:port counts: extra syntax changes which host is meant, and review:8443@evil.example names evil.example. The bare GERRIT_HOST variable is deliberately not read. It already chooses which server a GitHub2Gerrit change is submitted on, resolved from .gitreview first, so consuming it here would give an existing setting a second meaning without anyone asking for it. Declaring a host as both platforms is reported rather than resolved by precedence. Each declaration states where the operator's credentials may go, so honouring one would silently discard the other exactly where it mattered. It is checked first, before any shape check could answer for it, at every place a host is decided: the change, topic, repository and owner URL parsers, both bare-owner resolvers, the client's own pull request parser, and the local checkout -- the last because that branch exits with checkout guidance before any parser runs, and would otherwise never report a contradiction at all. Undeclared hosts keep today's structural inference untouched. Gerrit has no equivalent of github.com, so requiring a declaration before any Gerrit URL parsed would break every existing user. No probing is introduced, per the reasoning in lfreleng-actions#478: an unauthenticated probe still contacts a host that may be mistyped, which is what the declaration rule exists to prevent, and an authenticated one leaks the token to decide whether it should have been sent. Two overlaps had to be settled along the way. A Gerrit project may contain pull/<digits>, so /c/team/pull/123/+/456 satisfies both grammars; the anchored Gerrit shape now outranks the /pull/ heuristic except on a host that is GitHub, where the Gerrit reading is meaningless. And a port and a ;suffix are refused on every Gerrit answer, in the parser and the detector alike, because urlparse drops both and the client would then address a different target than the operator named. Both are checked after the declarations, so a malformed path never masks an authoritative host conflict. A declaration also settles a single-label scp remote. Without userinfo review:acme/widget.git is indistinguishable from a local path, and so was unreachable even with --gerrit-host review. A single letter stays a Windows drive whatever is declared. A malformed remote authority is no longer Gerrit evidence: a textual port check read ssh://[bad]:29418/project as Gerrit and extracting its identity raised. An empty topic (/q/topic:) is now refused as one rather than falling through to GitHub guidance, and a malformed term such as topic:a"b no longer matches its prefix. The topic and detector refusals redact the target instead of echoing the decoded query or the raw URL. url_parser/hosts.py crossed the size gate, so the routing decisions that combine both platforms' declarations move to gerrit_routing.py. local_repo.py crossed the size gate, so the pure remote-string decisions move to local_remote.py, with host_suggests_gerrit re-exported since it is public. Closes lfreleng-actions#478 Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
ModeSevenIndustrialSolutions
force-pushed
the
feat/declare-gerrit-host
branch
from
September 23, 2026 14:10
5b16129 to
2d5853f
Compare
ModeSevenIndustrialSolutions
temporarily deployed
to
integration
September 23, 2026 14:10 — with
GitHub Actions
Inactive
keanjapesan
approved these changes
Sep 24, 2026
ModeSevenIndustrialSolutions
merged commit Sep 24, 2026
6b4e503
into
lfreleng-actions:main
26 checks passed
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #478.
The gap
GitHub Enterprise hosts are declared before they are addressed; Gerrit hosts were only inferred, from the shape of a URL path. So routing read the path alone:
A declaration is a statement about the host; a path shape is a guess about the URL. The declaration decides — the rule
local_repo._looks_like_gerrit_remotealready applies to remotes, now applied to URLs too.Acceptance, item by item
--gerrit-host,DEPENDAMERGE_GERRIT_HOST,DEPENDAMERGE_GERRIT_HOSTSDecisions worth flagging
GERRIT_HOSTis deliberately not read. It already chooses which server a GitHub2Gerrit change is submitted on (_gerrit_submit.py, resolved from.gitreviewfirst). Consuming it here would give an existing setting a second meaning. A test pins that the bare variable does not declare.No Gerrit default host.
host_configresolves a default for shorthand; there is no Gerrit shorthand, so there is nothing to default.Conflicts are reported, not resolved. Each declaration says where the operator's credentials may go, so a precedence rule would silently discard one of two explicit statements. Checked at every place a host is decided — the change, topic, repository and owner URL parsers, both bare-owner resolvers, the client's own parser, and the local checkout. That last one matters because its branch exits with checkout guidance before any parser runs, so it would otherwise never report a contradiction at all.
Two grammar overlaps had to be settled. A Gerrit project may contain
pull/<digits>, so/c/team/pull/123/+/456satisfies both grammars — the anchored Gerrit shape outranks the/pull/heuristic, except on a host that is GitHub where the Gerrit reading is meaningless. And a port is refused on every Gerrit answer, parser and detector alike, becauseurlparsedrops it and the client would then address a different server than the operator named.A
;suffixand a port are refused after the declarations, on every Gerrit answer in the parser and the detector alike, so a malformed path never masks an authoritative "declared as both" or "it is a GitHub host" refusal, anddetect_sourcenever accepts a targetparse_change_urlrefuses.--gerrit-hostadds, it does not override. The sources combine, because Gerrit has no default host for one of them to replace.--github-hostoutranks the environment only because it also picks the shorthand default.A malformed declaration is ignored while routing, so a stale entry for another server cannot fail an unrelated target, except one naming the target's own host with a port, which is reported. Ignoring that one sent a host the operator plainly meant as Gerrit to GitHub guidance. Only a value that is exactly
host:portis matched, the one fault that leaves the intended hostname unambiguous;review:8443@evil.examplenamesevil.example, so it stays ignored.A declaration settles a single-label scp remote. Without userinfo,
review:acme/widget.gitis indistinguishable from a local path, so it was unreachable even with--gerrit-host review.url_parser/hosts.pycrossed the size gate, so the routing decisions that combine both platforms' declarations (is_declared_gerrit_host,reject_conflicting_host_declaration,reject_gerrit_on_github_host) live ingerrit_routing.py. That module importshostsandgerrit_hosts, and neither imports it, so no cycle.local_repo.pycrossed the size gate, so the pure remote-string decisions move tolocal_remote.py— split rather than suppressed, following_precommit_status/_precommit_wait.host_suggests_gerritis re-exported, being public.Tests
tests/test_gerrit_host_declaration.py(100) — the declaration mechanism, both Gerrit URL shapes, undeclared-host inference as the control, conflict reporting at every entry point, the local checkout, the overlapping grammar in both directions, an empty or malformed topic term, redaction of the topic and detector refusals, and CLI coverage:--gerrit-hostintrospected on all four target-taking commands plus end-to-end invocation, verified to fail when theapply_gerrit_hostcall is removed.tests/conftest.py's autouse isolation fixture clears the Gerrit variables too — load-bearing rather than tidiness, since a declaration left set decides routing and would send a target to the wrong platform's parser entirely.Known gaps
None open. The earlier list is resolved:
;suffixon a final segment: refused by Fix(url): Gate a repository taken from a URL #519'sreject_path_parameters, including for a checkout's remote, which reaches the same parsers (verified withhttps://github.com/acme/widget;otherandgit@github.com:acme/widget;other.git).ssh://[bad]:29418/project: the port is now read withurlsplitunder guard, so a malformed authority is no Gerrit evidence, and the identity extraction tolerates one too.hosts.pysize: split (above).Declined here, filed separately: a percent-encoded repository segment (
github.com/acme/my%5Frepo) is refused, although GitHub resolves one (github.com/pypa/get%2Dpip→ 200). That is #519's merged behaviour, not #478's, so it is #522.Validation
pytestmain)basedpyright --warnings src testsmypy src testsruff check/format --checkaislop ciprekReview history
This change went through 15 Copilot rounds in #519 before being split out. Every finding was real; several were serious — a valid Gerrit change URL parsed as a GitHub pull request, two valid repository URLs made unreachable, and a credential-redaction test silently disabled by a module split. Roughly half the later findings were defects in the previous round's fix, which is why it was split out. After #519 merged it was rebased onto
main, and 11 of the 12 open findings from its last round were fixed. The twelfth was declined and filed as #522.