Find an epic repo's checkout and project config by its name, and clone a missing one from the place of the epic's other repos
CI / tests (pull_request) Failing after 4m35s
CI / tests (pull_request) Failing after 4m35s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Which forge a checkout's origin is on, and running that forge's CLI in the checkout."""
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
import typing
|
||||
|
||||
@@ -16,6 +17,14 @@ def forge_of(origin_url: str) -> Forge:
|
||||
return "gh" if "github.com" in origin_url else "tea"
|
||||
|
||||
|
||||
def url_beside(origin_url: str, name: str) -> str | None:
|
||||
"""The origin URL of the repo called name in the same place, host and owner, as origin_url's repo; None where origin_url has no place, such as a bare name. A trailing `.git` is dropped, since gh and tea clone without it."""
|
||||
trimmed = origin_url.rstrip("/").removesuffix(".git")
|
||||
place = re.fullmatch(r"(.+[/:])[^/:]+", trimmed)
|
||||
# A scheme's own `//` or `:` leaves no repo to put a name beside.
|
||||
return place.group(1) + name if place and not place.group(1).endswith("//") and not re.fullmatch(r"\w+:", place.group(1)) else None
|
||||
|
||||
|
||||
def runner(cwd: str) -> Run:
|
||||
def run(command: list[str]) -> str | Failure:
|
||||
try:
|
||||
|
||||
+13
-1
@@ -7,7 +7,7 @@ import unittest
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from forge.pulls import checks_passed, open_pull, POLL_SECONDS, required_checks, WAIT_SECONDS
|
||||
from forge.commands import forge_of, gitea
|
||||
from forge.commands import forge_of, gitea, url_beside
|
||||
|
||||
|
||||
class ForgeOf(unittest.TestCase):
|
||||
@@ -16,6 +16,18 @@ class ForgeOf(unittest.TestCase):
|
||||
self.assertEqual(forge_of("https://gitea.larvit.se/o/r.git"), "tea")
|
||||
|
||||
|
||||
class UrlBeside(unittest.TestCase):
|
||||
def test_names_a_repo_in_the_same_place_of_the_same_host_in_each_spelling_of_an_origin(self):
|
||||
self.assertEqual(url_beside("git@github.com:acme/billing.git", "ledger"), "git@github.com:acme/ledger")
|
||||
self.assertEqual(url_beside("https://gitea.larvit.se/acme/billing", "ledger"), "https://gitea.larvit.se/acme/ledger")
|
||||
self.assertEqual(url_beside("https://gitea.larvit.se/acme/billing.git/", "ledger"), "https://gitea.larvit.se/acme/ledger")
|
||||
|
||||
def test_names_none_where_the_origin_has_no_place_to_put_a_repo_in(self):
|
||||
self.assertIsNone(url_beside("billing", "ledger"))
|
||||
self.assertIsNone(url_beside("", "ledger"))
|
||||
self.assertIsNone(url_beside("https://gitea.larvit.se", "ledger"))
|
||||
|
||||
|
||||
# An answer no call can read, longer than the 200 characters of it that a failure quotes.
|
||||
LONG = "[" + ", ".join(["1"] * 100) + "]"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user