Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions scripts/pr_review_copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ def matched(patterns: list[re.Pattern[str]], text: str) -> re.Match[str] | None:
return next((m for p in patterns if (m := p.fullmatch(text))), None)


def count_state(got: str, of: str) -> str:
"""A reviewed-of-changed count as `full`, `partial`, or `unknown` where either is too long or `got` exceeds `of`."""
if len(got) > COUNT_DIGITS or len(of) > COUNT_DIGITS or int(got) > int(of):
return "unknown"
return "full" if int(got) == int(of) else "partial"


def stated(match: re.Match[str]) -> int:
"""The count a matched label states: its `n` group, zero for a spelled none, one without one."""
value = match.groupdict().get("n")
Expand Down Expand Up @@ -347,11 +354,7 @@ def unread(note: str, start: int, end: int) -> None:
rank = {"full": 0, "unknown": 1, "partial": 2}
for h in html:
for m in FLEET_REVIEW.finditer(h):
got, of = m.group(1), m.group(2)
if len(got) > COUNT_DIGITS or len(of) > COUNT_DIGITS or int(got) > int(of):
state = "unknown"
else:
state = "full" if got == of else "partial"
state = count_state(m.group(1), m.group(2))
if coverage == "none" or rank[state] > rank[coverage]:
coverage, coverage_line = state, m.group(0)
# A body in another layout is one note, rather than one note per part of it.
Expand Down Expand Up @@ -518,8 +521,7 @@ def placed(n: int, t: Token) -> bool:
m = next((m for p in vocab["coverage_prose"] if (m := p.match(said))), None)
if m is None:
continue
got, of = int(m.group("got")[:COUNT_DIGITS]), int(m.group("of")[:COUNT_DIGITS])
state = "partial" if got < of else "full" if got == of else "unknown"
state = count_state(m.group("got"), m.group("of"))
if state == "unknown":
notes.append(f"a coverage count this reader cannot believe: `{said}`")
if coverage == "none" or rank[state] > rank[coverage]:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_pr_review_copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def test_a_count_stated_in_a_paragraph_of_its_own_is_read(self) -> None:
("Copilot reviewed 4 out of 4 changed files.", "full", False),
("Copilot reviewed 3 out of\n4 changed files.", "partial", False),
("Copilot reviewed 5 out of 4 changed files.", "unknown", True),
("Copilot reviewed 12345 out of 12345 changed files.", "unknown", True),
("Copilot reviewed 12340 out of 12349 changed files.", "unknown", True),
):
with self.subTest(line=line):
found = adapter.read(body(sections=line))
Expand Down
Loading