oliver-zehentleitner / maity
clean-up: CLI + runner: one repository URL normalisation instead of three parsers (gitfacts, runner/config)
tsk-90ck9k4f24gd Open
From the clean-up audit tsk-hgnbapyw7hnh, the cross-area findings (areas 9 and 13) that the per-area cards left to one shared card. Read at main 80647565; every line number is at that SHA, so check it against current main first.
Kind: duplication / docs drift. Effort: M. Risk: medium. The runner's repository allowlist and the clone check depend on it, so a changed result can refuse a project or admit a different one.
Order:
- tsk-egaycsbdwmeq item 8 makes
gitfacts._branchpublic, and item 9 addsmaity/names.py. The shared helper can live besidenames.py. Coordinate, or do this after it. - tsk-qtr9myhtysbs (security, in progress) validates repository owner and name on the hub. Keep the CLI's accepted forms no wider than the hub's.
- tsk-rzhydxnsav4m (repository URL on any forge host) may widen which hosts and paths count. Do this after it, or make the helper take any host.
What is wrong
Three functions in cli/src/maity parse a Git remote or repository URL, each in its own way:
- gitfacts.py:429-443
repository_key(value) -> (host, path): handleshttps://,ssh://, the scp formgit@host:owner/nameand barehost/owner/name. It drops the user and the port (viahostname), lowercases the host and strips/and.git. Used byrepository_mismatch(:446-456, the join's advisory check). - runner/config.py:452-466
normalise_repository(value) -> "host/owner/name": drops the scheme and user, keeps a port, strips/and.git, and lowercases the host. It does not handle the scp form:git@github.com:o/nbecomesgithub.com:o/n, whichREPOSITORY(config.py:40) then refuses. Used at config.py:356, :427, :434, :496, :504, adapters.py:354, supervisor.py:803 and :1020, and workspace.py:162 (the clone'soriginagainst the placement's repository). - gitfacts.py:147-155
remote_host(url): a third parse, only for the host (with a Windows drive-path rule that neither of the others has). Used at gitfacts.py:166. - (supervisor.py:1035-1036 also takes
urlsplit(...).hostnameof the repository inline.)
This contradicts cli/context/runner.md:37-49 (b1571548, "Repository entries and project URLs go through one normalisation"). That entry covers the runner only, but the CLI has a second, different normalisation for the same values. The two also disagree on the port: repository_key drops it, normalise_repository keeps it.
Proposal
- One module (for example
maity/repourl.py, or next tonames.pyfrom tsk-egaycsbdwmeq) withparse(value) -> Repo(host, port, path)that handles https, ssh, scp form and barehost/owner/name, pluskey(repo)for comparisons andhost(value)forremote_host. normalise_repository,repository_keyandremote_hostbecome thin wrappers or are replaced at their call sites.repository_url_ok(config.py:472-488) stays the gate for what the runner may clone.- Update runner.md b1571548 to name the shared function and say whether the scp form is accepted in config entries.
- Tests: the parametrised cases in cli/tests/test_runner.py:120 (
test_normalise_repository) and cli/tests/test_report.py:215 (test_remote_host) become one table that all three wrappers must pass.
Open questions
- Can runner config entries be in scp form? At 80647565 they cannot.
normalise_repository("git@github.com:o/n")givesgithub.com:o/n, and_repositories(config.py:501-509) refuses it with "expected host/owner/name", which does not tell the operator why. The project'srepository.urlcannot be scp either:repository_url_ok(config.py:472-488) accepts onlyhttpsandsshURLs. So today the gap causes a confusing refusal, not a wrong match. Decide: accept the scp form inlimits.repositoriesand[repositories.*](normalised tohost/owner/name), or refuse it with a clear message. - Port: should
github.com:2222/o/nandgithub.com/o/nbe the same repository? The runner says no (the port is kept, andREPOSITORYallows it). The join check says yes. Pick one.
Left out as duplicates: none. Searched: normalise_repository, repository_key, remote_host. tsk-egaycsbdwmeq covers the git-call wrappers, not URL parsing.
Effort: M = 3 points.