This commit is contained in:
@@ -17,6 +17,11 @@ REPO_NAME = r"\w[\w.-]*"
|
||||
CLONE_ADDRESS = rf"https://[\w.-]+(:\d+)?/\S+|ssh://[\w.@-]+(:\d+)?/\S+|\w[\w.-]*@[\w.-]+:[\w./~-]+"
|
||||
|
||||
|
||||
def shown(url: str) -> str:
|
||||
"""url without any `user:token@` after its scheme, since an Unsure may be posted where the team reads it."""
|
||||
return re.sub(r"^(\w+://)[^/@]*@", r"\1", url)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Located:
|
||||
"""checkout is the repo's git checkout, and config the project config that names it."""
|
||||
@@ -73,11 +78,11 @@ def place_of(name: str, others: list[pathlib.Path], git: Git) -> str | Failure:
|
||||
return Unsure(f"cannot read the origin of {other}: {origin.reason}. Where does {name} live?")
|
||||
beside = url_beside(origin.strip(), name)
|
||||
if beside is None:
|
||||
return Unsure(f"{other} has an origin, {origin.strip()}, with no place to put another repo in. Where does {name} live?")
|
||||
return Unsure(f"{other} has an origin, {shown(origin.strip())}, with no place to put another repo in. Where does {name} live?")
|
||||
urls.add(beside)
|
||||
if len(urls) > 1:
|
||||
return Unsure(f"The epic's other repos sit in more than one place, so {name} could be at {' or '.join(sorted(urls))}. Which holds it?")
|
||||
url = next(iter(urls))
|
||||
if not re.fullmatch(CLONE_ADDRESS, url):
|
||||
return Unsure(f"{url} is not an https, ssh or scp-style address. Where does {name} live?")
|
||||
return Unsure(f"{shown(url)} is not an https, ssh or scp-style address. Where does {name} live?")
|
||||
return url
|
||||
|
||||
@@ -131,6 +131,14 @@ class LocateTest(unittest.TestCase):
|
||||
self.assertIn("is not an https, ssh or scp-style address", self.unsure(git))
|
||||
self.assertEqual(git.cloned, [])
|
||||
|
||||
def test_leaves_the_credentials_of_an_origin_out_of_a_question(self) -> None:
|
||||
self.configure()
|
||||
self.origins[str(self.billing)] = "https://bot:s3cret@gitea.larvit.se/acme/billing"
|
||||
self.origins[str(self.payments)] = "https://bot:s3cret@gitea.larvit.se/acme/payments"
|
||||
asked = self.unsure(FakeGit(self.origins))
|
||||
self.assertIn("https://gitea.larvit.se/acme/ledger is not an https", asked)
|
||||
self.assertNotIn("s3cret", asked)
|
||||
|
||||
def test_fails_with_the_config_failure_where_a_config_cannot_be_read(self) -> None:
|
||||
(self.projects / "broken").mkdir(parents=True)
|
||||
(self.projects / "broken" / "config.toml").write_text("this is not toml", encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user