Park on a new review once requested changes are answered, never park a Gitea draft, and count a slot only for a window that started
This commit is contained in:
@@ -60,6 +60,11 @@ def approved(number: str, run: Run, sleep: typing.Callable[[float], None] = time
|
||||
return Failure(f"pull request {number} wasn't approved within {WAIT_SECONDS // 60} minutes; run chunk-pr merge again once it is")
|
||||
|
||||
|
||||
def left_to_park(number: str, run: Run) -> Failure:
|
||||
"""Why a merge under PARKS ends at once where pull request number passed its checks and awaits an approval, in place of waiting as `approved` does: a reviewer's comment waits for an answer, which the worker gives first, or else do-epic parks the chunk, so the worker ends its run."""
|
||||
return unanswered(number, run) or Failure(f"pull request {number} passed its checks and awaits an approval; end your run now, since do-epic parks the chunk and resumes this session once it is approved or a reviewer comments")
|
||||
|
||||
|
||||
def unanswered(number: str, run: Run) -> Failure | None:
|
||||
"""A Failure naming the files where a reviewer's comment waits for an answer on pull request number, as `waiting_threads` finds them, or saying why they cannot be read. None where no thread waits."""
|
||||
waiting = waiting_threads(number, run)
|
||||
|
||||
@@ -86,7 +86,7 @@ import sys
|
||||
import time
|
||||
import typing
|
||||
|
||||
from chunk_pr.approval import approval, approved, awaited, PARKS, unanswered
|
||||
from chunk_pr.approval import approval, approved, awaited, left_to_park, PARKS, unanswered
|
||||
from forge.pulls import checks_passed, merged_pull, open_pull, required_checks
|
||||
from failure import Failure
|
||||
from forge.commands import Forge, forge_of, gitea, Run, runner
|
||||
@@ -306,7 +306,7 @@ def finishes_of(given: list[str]) -> list[list[str]] | None:
|
||||
|
||||
|
||||
def merged(run: Run, config: Config, sleep: typing.Callable[[float], None] = time.sleep, finishes: typing.Sequence[list[str]] = (), parks: bool = False) -> str | Failure:
|
||||
"""Merge the branch's pull request in the project's merge queue. Each pass of the loop is one turn in the queue; a pull request that still wants its approval leaves the queue while it waits, so the next chunk merges meanwhile, and takes a new turn once approved. Where parks, it doesn't wait for the approval: it fails at once, telling the worker that do-epic parks the chunk."""
|
||||
"""Merge the branch's pull request in the project's merge queue. Each pass of the loop is one turn in the queue; a pull request that still wants its approval leaves the queue while it waits, so the next chunk merges meanwhile, and takes a new turn once approved. Where parks, it doesn't wait for the approval: it fails at once, as `left_to_park` says."""
|
||||
found = pull(run)
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
@@ -337,8 +337,10 @@ def merged(run: Run, config: Config, sleep: typing.Callable[[float], None] = tim
|
||||
taken = untaken or merge_turn(pull_request, finishes, loaded, run, sleep)
|
||||
if not isinstance(taken, AwaitsApproval):
|
||||
return taken if isinstance(taken, Failure) else taken + absent
|
||||
if parks:
|
||||
return left_to_park(number, run)
|
||||
# Out of the queue, so the project's other chunks merge while this one waits.
|
||||
waited = Failure(f"pull request {number} passed its checks and awaits an approval; end your run now, since do-epic parks the chunk and resumes this session once it is approved or a reviewer comments") if parks else approved(number, run, sleep)
|
||||
waited = approved(number, run, sleep)
|
||||
if isinstance(waited, Failure):
|
||||
return waited
|
||||
|
||||
|
||||
@@ -384,6 +384,15 @@ class Merge(unittest.TestCase):
|
||||
self.assertEqual(checkout.ran.count(GH_DECISION), 1)
|
||||
self.assertEqual(step(["merge"], self.requiring_approval(GITHUB, "REVIEW_REQUIRED"), checkout.config, parks=True), failed)
|
||||
|
||||
def test_a_merge_that_parks_reports_a_reviewers_unanswered_comment_before_the_approval_it_awaits(self):
|
||||
checkout = self.requiring_approval(GITHUB, "REVIEW_REQUIRED")
|
||||
checkout.threads = [MergeQueue.thread("bin/asked.py", "reviewer")]
|
||||
failed = merged(checkout, checkout.config, self.fail, parks=True)
|
||||
self.assertEqual(failed.reason, "a reviewer's comment on pull request 12 waits for an answer, in bin/asked.py; answer it in its thread, push any fix, and run chunk-pr merge again")
|
||||
checkout = self.requiring_approval(GITHUB, "REVIEW_REQUIRED")
|
||||
checkout.answers[tuple(GH_THREADS)] = Failure("gh api graphql failed")
|
||||
self.assertEqual(merged(checkout, checkout.config, self.fail, parks=True), Failure("gh api graphql failed"))
|
||||
|
||||
def test_a_merge_that_parks_merges_an_approved_pull_request(self):
|
||||
checkout = self.requiring_approval()
|
||||
self.assertEqual(merged(checkout, checkout.config, self.fail, parks=True), "Merged pull request #12 (merge).")
|
||||
|
||||
Reference in New Issue
Block a user