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:
@@ -350,6 +350,20 @@ def held(folder: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure |
|
||||
return config if isinstance(config, Failure) else load(config[0], config[0], home)
|
||||
|
||||
|
||||
def named(name: str, home: pathlib.Path) -> ProjectConfig | Failure | None:
|
||||
"""The config of the project whose main checkout is a folder called name, which may not exist yet, loaded as `held` does; None where no config names one. A config that cannot be read fails every name, since it may be the one asked for."""
|
||||
files = []
|
||||
for file in configs(home):
|
||||
config = read(file, home)
|
||||
if isinstance(config, Failure):
|
||||
return config
|
||||
if config[0].name == name:
|
||||
files.append(file)
|
||||
if len(files) > 1:
|
||||
return Failure(f"{' and '.join(str(file) for file in files)} each name a checkout called {name}; only one config may")
|
||||
return held(files[0].parent, home) if files else None
|
||||
|
||||
|
||||
def configs(home: pathlib.Path) -> list[pathlib.Path]:
|
||||
"""Every project's config file under home, in key order. do-epic's machine-wide config is not a project's."""
|
||||
return sorted(file for file in (home / PROJECTS).glob(f"*/{CONFIG}") if file.parent.name != DO_EPIC)
|
||||
|
||||
@@ -9,7 +9,7 @@ import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from project_config.settings import env_files, Epic, Finish, held, JiraScoring, load, NOTIFIERS, OUTSIDE, Page, ProjectConfig, SETTINGS, Unnamed
|
||||
from project_config.settings import env_files, Epic, Finish, held, JiraScoring, load, named, NOTIFIERS, OUTSIDE, Page, ProjectConfig, SETTINGS, Unnamed
|
||||
from failure import Failure
|
||||
from test_env import isolated_env
|
||||
from project_config.main import located, title_templates
|
||||
@@ -598,6 +598,32 @@ class HeldTest(ConfigCase):
|
||||
self.assertIsInstance(held(target, self.home), ProjectConfig, "git names the folder by its resolved path")
|
||||
|
||||
|
||||
class NamedTest(ConfigCase):
|
||||
def test_finds_the_config_of_the_project_whose_main_checkout_has_the_name_though_the_checkout_is_missing(self) -> None:
|
||||
folder = self.write("acme", CLIENT)
|
||||
found = named("acme-billing", self.home)
|
||||
assert isinstance(found, ProjectConfig), found
|
||||
self.assertEqual((found.folder, found.top), (folder, self.checkout))
|
||||
|
||||
def test_finds_none_where_no_config_names_a_checkout_of_that_name(self) -> None:
|
||||
self.write("acme", CLIENT)
|
||||
self.assertIsNone(named("billing", self.home), "a part of a name is not the name")
|
||||
self.assertIsNone(named("acme", self.home), "a config's key is not a repo's name")
|
||||
self.assertIsNone(named("do-epic", self.home))
|
||||
|
||||
def test_fails_where_two_configs_name_a_checkout_of_that_name(self) -> None:
|
||||
self.write("acme", CLIENT)
|
||||
self.write("acme-two", CLIENT.replace("~/code/acme-billing", "~/other/acme-billing"))
|
||||
found = named("acme-billing", self.home)
|
||||
assert isinstance(found, Failure), found
|
||||
self.assertIn("acme/config.toml and ", found.reason)
|
||||
self.assertIn("acme-two/config.toml each name a checkout called acme-billing", found.reason)
|
||||
|
||||
def test_fails_where_a_config_cannot_be_read_since_it_may_be_the_one_asked_for(self) -> None:
|
||||
self.write("acme", "this is not toml")
|
||||
self.assertIsInstance(named("acme-billing", self.home), Failure)
|
||||
|
||||
|
||||
class EnvFilesTest(ConfigCase):
|
||||
def test_lists_each_readable_configs_env_file_even_one_load_refuses(self) -> None:
|
||||
self.write("acme", CLIENT + 'env-file = "~/acme.env"\n')
|
||||
|
||||
Reference in New Issue
Block a user