Skip to content

Feat(url): Allow a Gerrit host to be declared - #520

Merged
ModeSevenIndustrialSolutions merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:feat/declare-gerrit-host
Sep 24, 2026
Merged

ModeSevenIndustrialSolutions merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:feat/declare-gerrit-host

Conversation

@ModeSevenIndustrialSolutions

@ModeSevenIndustrialSolutions ModeSevenIndustrialSolutions commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

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:

$ export DEPENDAMERGE_GITHUB_HOSTS=ghe.corp.example.com
$ dependamerge merge https://ghe.corp.example.com/c/project/+/123
WARNING - No netrc credentials found for ghe.corp.example.com
❌ Gerrit credentials not found.

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_remote already applies to remotes, now applied to URLs too.

Acceptance, item by item

#478 asks Result
Declared from CLI and environment --gerrit-host, DEPENDAMERGE_GERRIT_HOST, DEPENDAMERGE_GERRIT_HOSTS
A GitHub-declared host is not routed to Gerrit Refused, naming the conflict
Declaring both is reported, not resolved by precedence Refused, naming both sources
Undeclared hosts keep structural inference Unchanged — asserted
No network probing None introduced

Decisions worth flagging

GERRIT_HOST is deliberately not read. It already chooses which server a GitHub2Gerrit change is submitted on (_gerrit_submit.py, resolved from .gitreview first). 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_config resolves 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/+/456 satisfies 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, because urlparse drops it and the client would then address a different server than the operator named.

A ;suffix and 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, and detect_source never accepts a target parse_change_url refuses.

--gerrit-host adds, it does not override. The sources combine, because Gerrit has no default host for one of them to replace. --github-host outranks 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:port is matched, the one fault that leaves the intended hostname unambiguous; review:8443@evil.example names evil.example, so it stays ignored.

A declaration settles a single-label scp remote. Without userinfo, review:acme/widget.git is indistinguishable from a local path, so it was unreachable even with --gerrit-host review.

url_parser/hosts.py crossed 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 in gerrit_routing.py. That module imports hosts and gerrit_hosts, and neither imports it, so no cycle.

local_repo.py crossed the size gate, so the pure remote-string decisions move to local_remote.py — split rather than suppressed, following _precommit_status/_precommit_wait. host_suggests_gerrit is 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-host introspected on all four target-taking commands plus end-to-end invocation, verified to fail when the apply_gerrit_host call 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:

  • ;suffix on a final segment: refused by Fix(url): Gate a repository taken from a URL #519's reject_path_parameters, including for a checkout's remote, which reaches the same parsers (verified with https://github.com/acme/widget;other and git@github.com:acme/widget;other.git).
  • Single-label scp remote: classified once declared (above).
  • ssh://[bad]:29418/project: the port is now read with urlsplit under guard, so a malformed authority is no Gerrit evidence, and the identity extraction tolerates one too.
  • hosts.py size: 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

Check Result
pytest 2863 passed, 20 skipped (2763 on main)
basedpyright --warnings src tests 0 errors, 0 warnings
mypy src tests Success, 301 files
ruff check / format --check All checks passed
aislop ci score 100, 0 errors, 0 warnings
prek All hooks passed

Review 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.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings September 23, 2026 13:59

This comment was marked as outdated.

This comment was marked as outdated.

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Host-routing and credential-boundary behavior spans numerous parsing and CLI entry points, warranting final human review.

Review effort: Balanced
Findings: None

Resolved since last review (2)

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit 6b4e503 into lfreleng-actions:main Sep 24, 2026
26 checks passed

This branch was previously deployed

1 inactive deployment
integration — 2d5853fb Deployed Sep 23, 2026 by ModeSevenIndustrialSolutions via Live dry-run integration tests #358
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Allow a Gerrit host to be declared explicitly

3 participants