Answer stability round 1: 1 🔴, 1 🟡 (0 misread); wait for a pull request at another head, and only where a review is owed
This commit is contained in:
+38
-29
@@ -43,9 +43,9 @@ ready marks the pull request ready for review. On Gitea a draft is a pull req
|
||||
as the pull request's title first; where that fails, the pull request stays a draft.
|
||||
push pushes the branch, setting its upstream. Where its pull request is open and goes into an
|
||||
epic's working branch, it then asks for a review as ready does. Use it for each push
|
||||
after ready there, and wait for that review as for any other. Where the pull request
|
||||
was open at the branch's old head, it waits up to a minute for the forge to show the
|
||||
new head on it, and fails, naming the pull request, where the forge never does.
|
||||
after ready there, and wait for that review as for any other. Before it asks, it waits up
|
||||
to a minute for the forge to show the pushed commit as the head of the branch's open
|
||||
pull request, and fails, naming the pull request, where the forge never does.
|
||||
merge merges the pull request in its turn: the chunks of one project on this machine take
|
||||
turns, one at a time. Run it in the background. In its turn it:
|
||||
1. fetches origin and merges its default branch into the branch, as sync does;
|
||||
@@ -122,7 +122,7 @@ import time
|
||||
import typing
|
||||
|
||||
from chunk_pr.approval import approval, approved, awaited, left_to_a_person, left_to_park, PARKS, unanswered
|
||||
from forge.pulls import checks_passed, merged_pull, open_pull, other_base, required_checks
|
||||
from forge.pulls import checks_passed, merged_pull, open_pull, other_base, pull_from, required_checks
|
||||
from git_cli.git_repo import CHUNK_BASE, Git
|
||||
from git_cli import epic_branch
|
||||
from failure import Failure
|
||||
@@ -240,7 +240,7 @@ class Base:
|
||||
|
||||
|
||||
def base_of(branch: str, run: Run) -> Base | Failure:
|
||||
"""The Base of the pull request from branch: the epic's working branch the checkout records for it (`git_repo.record_chunk_base`), else origin's default branch. A recorded base that is origin's default branch is no epic's: the pull request merges into the default branch, where a person may have to merge it."""
|
||||
"""The Base of the pull request from branch: the epic's working branch the checkout records for it (`git_repo.record_chunk_base`), else origin's default branch. A recorded base equal to origin's default branch isn't an epic's working branch: the pull request merges into the default branch, so `merge = "human"` and `wait-for-approval` apply to it."""
|
||||
default = default_branch(run)
|
||||
if isinstance(default, Failure):
|
||||
return default
|
||||
@@ -375,36 +375,49 @@ def pushed(run: Run, config: Config, sleep: typing.Callable[[float], None]) -> s
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
forge, branch, head = found
|
||||
old = run(["git", "ls-remote", "origin", f"refs/heads/{branch}"])
|
||||
if isinstance(old, Failure):
|
||||
return old
|
||||
sent = run(["git", "push", "--quiet", "--set-upstream", "origin", branch])
|
||||
number = sent if isinstance(sent, Failure) else shown_pull(forge, branch, head, old.split()[0] if old.strip() else "", run, sleep)
|
||||
if isinstance(number, Failure):
|
||||
return number
|
||||
asked = review_asked(forge, number, run, config) if number is not None else None
|
||||
if isinstance(asked, Failure):
|
||||
return Failure(f"pushed {branch}, but could not ask for a review: {asked.reason}")
|
||||
return f"Pushed {branch}, and asked for a review of pull request #{number} with “{asked}”." if asked else f"Pushed {branch}."
|
||||
if isinstance(sent, Failure):
|
||||
return sent
|
||||
comment = review_comment(run, config)
|
||||
number = None if comment is None or isinstance(comment, Failure) else shown_pull(forge, branch, head, run, sleep)
|
||||
if isinstance(comment, Failure):
|
||||
return Failure(f"pushed {branch}, but could not ask for a review: {comment.reason}")
|
||||
if isinstance(number, Failure) or number is None or comment is None:
|
||||
return number if isinstance(number, Failure) else f"Pushed {branch}."
|
||||
made = comment_on(forge, number, comment, run)
|
||||
return Failure(f"pushed {branch}, but could not ask for a review: {made.reason}") if isinstance(made, Failure) else f"Pushed {branch}, and asked for a review of pull request #{number} with “{comment}”."
|
||||
|
||||
|
||||
def shown_pull(forge: Forge, branch: str, head: str, old: str, run: Run, sleep: typing.Callable[[float], None]) -> str | None | Failure:
|
||||
"""The number of branch's open pull request at head, just pushed over old, the head origin had before. The forge may keep showing old for up to PUSH_SECONDS, so while it does, this polls; a Failure naming the pull request where it still does. None where no pull request is open at head or at old: `push` before `open` is normal."""
|
||||
stale = None
|
||||
def shown_pull(forge: Forge, branch: str, head: str, run: Run, sleep: typing.Callable[[float], None]) -> str | None | Failure:
|
||||
"""The number of branch's open pull request at head, just pushed. Right after a push the forge may still list the pull request at an older head, so this polls up to PUSH_SECONDS while it lists one at another head, and then fails naming it. None where no pull request from branch is open: `push` before `open` is normal."""
|
||||
other = None
|
||||
for waited in range(0, PUSH_SECONDS + 1, PUSH_POLL_SECONDS):
|
||||
number = open_pull(forge, branch, head, run)
|
||||
if number is not None or not old or old == head:
|
||||
if number is not None:
|
||||
return number
|
||||
stale = open_pull(forge, branch, old, run)
|
||||
if not isinstance(stale, str):
|
||||
return stale
|
||||
other = pull_from(forge, branch, run)
|
||||
if not isinstance(other, str):
|
||||
return other
|
||||
if waited < PUSH_SECONDS:
|
||||
sleep(PUSH_POLL_SECONDS)
|
||||
return Failure(f"pushed {branch}, but the forge still shows pull request #{stale} at {old[:12]}, not at {head[:12]}, after {PUSH_SECONDS} seconds, so no review was asked for; run chunk-pr push again")
|
||||
return Failure(f"pushed {branch}, but pull request #{other} still doesn't show {head[:12]} as its head after {PUSH_SECONDS} seconds, so no review was asked for; once it does, run chunk-pr push again")
|
||||
|
||||
|
||||
def review_asked(forge: Forge, number: str, run: Run, config: Config) -> str | None | Failure:
|
||||
"""Comment on the pull request numbered number with the config's `review-request-comment`, where the pull request goes into an epic's working branch: a forge's auto-reviewer may review only pull requests into the default branch unless asked. The comment made; None where the config names none or the pull request goes into the default branch."""
|
||||
"""Comment on the pull request numbered number as `review_comment` says. The comment made; None where it says none."""
|
||||
comment = review_comment(run, config)
|
||||
if comment is None or isinstance(comment, Failure):
|
||||
return comment
|
||||
made = comment_on(forge, number, comment, run)
|
||||
return made if isinstance(made, Failure) else comment
|
||||
|
||||
|
||||
def comment_on(forge: Forge, number: str, comment: str, run: Run) -> str | Failure:
|
||||
return run(["gh", "pr", "comment", number, "--body", comment] if forge == "gh" else ["tea", "comment", number, comment])
|
||||
|
||||
|
||||
def review_comment(run: Run, config: Config) -> str | None | Failure:
|
||||
"""The config's `review-request-comment` that a pull request from the branch checked out is owed, where it goes into an epic's working branch: a forge's auto-reviewer may review only pull requests into the default branch unless asked. None where the config names none or the pull request goes into the default branch."""
|
||||
branch = answers(run, ["symbolic-ref", "--short", "HEAD"])
|
||||
base = branch if isinstance(branch, Failure) else base_of(branch[0], run)
|
||||
if isinstance(base, Failure):
|
||||
@@ -412,11 +425,7 @@ def review_asked(forge: Forge, number: str, run: Run, config: Config) -> str | N
|
||||
if not base.to_epic:
|
||||
return None
|
||||
loaded = config()
|
||||
if isinstance(loaded, Failure) or loaded.review_request_comment is None:
|
||||
return loaded if isinstance(loaded, Failure) else None
|
||||
comment = loaded.review_request_comment
|
||||
made = run(["gh", "pr", "comment", number, "--body", comment] if forge == "gh" else ["tea", "comment", number, comment])
|
||||
return made if isinstance(made, Failure) else comment
|
||||
return loaded if isinstance(loaded, Failure) else loaded.review_request_comment
|
||||
|
||||
|
||||
def epic_opened(epic: str, title: str, body: str, run: Run, config: Config) -> str | Failure:
|
||||
|
||||
Reference in New Issue
Block a user