Run do-epic end to end against a sandbox Jira epic with do-epic-e2e
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""What the e2e command needs to know about its sandbox: three environment variables, so that neither the site nor the credentials' place is in the repo (docs/decisions.md → `do-epic: drives one Jira epic …`)."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import re
|
||||
import typing
|
||||
|
||||
from atlassian.client import basic_auth
|
||||
from failure import Failure
|
||||
from project_config.settings import SITE
|
||||
|
||||
JIRA_URL = "DO_EPIC_E2E_JIRA_URL"
|
||||
ENV_FILE = "DO_EPIC_E2E_ENV_FILE"
|
||||
PROJECT = "DO_EPIC_E2E_PROJECT"
|
||||
PROJECT_KEY = r"[A-Z][A-Z0-9]+"
|
||||
MEANING = {
|
||||
JIRA_URL: "the sandbox Jira site's https address without a path, such as https://acme.atlassian.net",
|
||||
ENV_FILE: "the absolute path of the file holding the sandbox account's ATLASSIAN_EMAIL and ATLASSIAN_API_TOKEN",
|
||||
PROJECT: "the key of the sandbox project, a team-managed space where the account may create, edit, transition, comment on and delete issues, such as SBX",
|
||||
}
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Sandbox:
|
||||
jira_url: str
|
||||
env_file: pathlib.Path
|
||||
project: str
|
||||
|
||||
|
||||
def read(env: typing.Mapping[str, str]) -> Sandbox | Failure:
|
||||
"""The sandbox that env names; a Failure naming each setting that is missing or misspelt, and what the sandbox's env-file lacks."""
|
||||
values = {name: env.get(name, "").strip() for name in MEANING}
|
||||
url, project = values[JIRA_URL], values[PROJECT]
|
||||
env_file = pathlib.Path(values[ENV_FILE]) if values[ENV_FILE] else None
|
||||
faults = [
|
||||
*(f"{name} is missing: set it to {meaning}" for name, meaning in MEANING.items() if not values[name]),
|
||||
*([f"{JIRA_URL} is {url!r}, not an https address without a path"] if url and not re.fullmatch(SITE, url) else []),
|
||||
*([f"{PROJECT} is {project!r}, not a project key such as SBX"] if project and not re.fullmatch(PROJECT_KEY, project) else []),
|
||||
*([f"{ENV_FILE} is {values[ENV_FILE]!r}, not an absolute path"] if values[ENV_FILE] and env_file is not None and not env_file.is_absolute() else []),
|
||||
]
|
||||
if not faults and env_file is not None:
|
||||
login = basic_auth(env_file)
|
||||
if isinstance(login, Failure):
|
||||
faults.append(login.reason)
|
||||
if faults:
|
||||
return Failure("; ".join(faults))
|
||||
assert env_file is not None
|
||||
return Sandbox(url, env_file, project)
|
||||
Reference in New Issue
Block a user