Answer stability round 1: 1 🔴, 5 🟡 (0 misread); hold a pull request's base on the forge to the recorded one, ask origin for the epic branch, and name where a chunk's work landed
CI / tests (pull_request) Successful in 3m46s
CI / tests (pull_request) Successful in 3m46s
This commit is contained in:
@@ -103,6 +103,37 @@ def unmergeable(forge: Forge, number: str, run: Run) -> str | None | Failure:
|
||||
return Failure(f"tea api answered pull request {number} in a shape that can't be read: {str(pull)[:200]}")
|
||||
|
||||
|
||||
def other_base(forge: Forge, number: str, base: str, run: Run) -> Failure | None:
|
||||
"""A Failure, naming both branches, where the forge merges pull request number into another branch than base, the one its checkout takes. None where the two agree.
|
||||
|
||||
A tool decides from the checkout's base who merges the pull request, so it doesn't act on one the forge would merge elsewhere."""
|
||||
onto = base_branch(forge, number, run)
|
||||
if isinstance(onto, Failure) or onto == base:
|
||||
return onto if isinstance(onto, Failure) else None
|
||||
return Failure(f"pull request #{number} merges into {onto} on the forge, but this checkout takes {base} as the base of its branch; a person settles which holds, and changes the pull request's base on the forge or the branch's `chunk-base` in git's config")
|
||||
|
||||
|
||||
def base_branch(forge: Forge, number: str, run: Run) -> str | Failure:
|
||||
"""The branch the forge merges pull request number into."""
|
||||
if forge == "gh":
|
||||
viewed = run(["gh", "pr", "view", number, "--json", "baseRefName"])
|
||||
if isinstance(viewed, Failure):
|
||||
return viewed
|
||||
try:
|
||||
name = json.loads(viewed)["baseRefName"]
|
||||
except (ValueError, KeyError, TypeError):
|
||||
name = None
|
||||
return name if name and isinstance(name, str) else Failure(f"gh pr view printed no base branch: {viewed.strip()[:200]}")
|
||||
pull = gitea(run, f"repos/{{owner}}/{{repo}}/pulls/{number}")
|
||||
if isinstance(pull, Failure):
|
||||
return pull
|
||||
try:
|
||||
name = pull["base"]["ref"]
|
||||
except (KeyError, TypeError):
|
||||
name = None
|
||||
return name if name and isinstance(name, str) else Failure(f"tea api answered pull request {number} in a shape that can't be read: {str(pull)[:200]}")
|
||||
|
||||
|
||||
def required_checks(forge: Forge, base: str, run: Run) -> set[str] | Failure:
|
||||
"""The checks, or glob patterns of checks, that the forge's protection of the branch base requires before a merge. None on GitHub, where gh's watch covers them.
|
||||
|
||||
|
||||
+29
-1
@@ -9,7 +9,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from forge.pulls import BEHIND, CheckFailed, checks_now, checks_passed, CONFLICTS, open_pull, Pending, POLL_SECONDS, ready_pulls, ReadyPull, required_checks, unmergeable, WAIT_SECONDS
|
||||
from forge.pulls import BEHIND, CheckFailed, checks_now, checks_passed, CONFLICTS, open_pull, other_base, Pending, POLL_SECONDS, ready_pulls, ReadyPull, required_checks, unmergeable, WAIT_SECONDS
|
||||
from failure import Failure
|
||||
from forge.commands import forge_of, gitea, runner, url_beside
|
||||
|
||||
@@ -86,6 +86,34 @@ class Unmergeable(unittest.TestCase):
|
||||
self.assertEqual(unmergeable("tea", "7", lambda command: '{"number": 7}').reason, "tea api answered pull request 7 in a shape that can't be read: {'number': 7}")
|
||||
|
||||
|
||||
class OtherBase(unittest.TestCase):
|
||||
ELSEWHERE = "pull request #7 merges into main on the forge, but this checkout takes ABC-12 as the base of its branch; a person settles which holds, and changes the pull request's base on the forge or the branch's `chunk-base` in git's config"
|
||||
|
||||
def test_a_github_pull_request_into_the_base_given_passes_and_one_into_another_fails_naming_both(self):
|
||||
commands: list[list[str]] = []
|
||||
self.assertIsNone(other_base("gh", "7", "main", lambda command: commands.append(command) or '{"baseRefName": "main"}'))
|
||||
self.assertEqual(commands, [["gh", "pr", "view", "7", "--json", "baseRefName"]])
|
||||
self.assertEqual(other_base("gh", "7", "ABC-12", lambda command: '{"baseRefName": "main"}'), Failure(self.ELSEWHERE))
|
||||
|
||||
def test_a_gitea_pull_request_into_the_base_given_passes_and_one_into_another_fails_naming_both(self):
|
||||
commands: list[list[str]] = []
|
||||
self.assertIsNone(other_base("tea", "7", "main", lambda command: commands.append(command) or '{"number": 7, "base": {"ref": "main"}}'))
|
||||
self.assertEqual(commands, [["tea", "api", "repos/{owner}/{repo}/pulls/7"]])
|
||||
self.assertEqual(other_base("tea", "7", "ABC-12", lambda command: '{"number": 7, "base": {"ref": "main"}}'), Failure(self.ELSEWHERE))
|
||||
|
||||
def test_fails_where_the_forge_cannot_be_read_or_names_no_base(self):
|
||||
unread = Failure("no network")
|
||||
for forge in ("gh", "tea"):
|
||||
with self.subTest(forge=forge):
|
||||
self.assertIs(other_base(forge, "7", "main", lambda command: unread), unread)
|
||||
self.assertEqual(other_base("gh", "7", "main", lambda command: LONG).reason, f"gh pr view printed no base branch: {LONG[:200]}")
|
||||
self.assertEqual(other_base("gh", "7", "main", lambda command: "not json").reason, "gh pr view printed no base branch: not json")
|
||||
self.assertEqual(other_base("gh", "7", "main", lambda command: '{"baseRefName": ""}').reason, 'gh pr view printed no base branch: {"baseRefName": ""}')
|
||||
self.assertEqual(other_base("tea", "7", "main", lambda command: LONG).reason, f"tea api answered pull request 7 in a shape that can't be read: {LONG[:200]}")
|
||||
self.assertEqual(other_base("tea", "7", "main", lambda command: '{"number": 7, "base": {}}').reason, "tea api answered pull request 7 in a shape that can't be read: {'number': 7, 'base': {}}")
|
||||
self.assertEqual(other_base("tea", "7", "main", lambda command: '{"number": 7, "base": {"ref": null}}').reason, "tea api answered pull request 7 in a shape that can't be read: {'number': 7, 'base': {'ref': None}}")
|
||||
|
||||
|
||||
def tea(statuses: typing.Iterable[str], branch: str = '{"name": "main"}') -> typing.Callable[[list[str]], str]:
|
||||
"""A tea answering each read of the head's status with the next of statuses, and of branch main with branch."""
|
||||
answers = iter(statuses)
|
||||
|
||||
Reference in New Issue
Block a user