Commit f1b012efb2

f1b012efb20fe1a27fb2d263d6355b658ac4d7aa

parent: 930bc76031

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-03-07 15:57 UTC

Adds functionality to tag myself, when a PR is ready for review

Layout: unified · split

lib/checks/prepare-comment.py +36 −10
@@ -42,10 +42,10 @@ def read_findings_count(new_body):
4242def _was_already_passing(existing_body):
4343 """Check if the most recent state in the comment is already all-clear."""
4444 # If there's a previous "all passing" edit, the last state was passing
45 if re.search(r"^Edit(?: \d+)?: All checks are (now passing|passing now)", existing_body, re.MULTILINE):
45 if re.search(r"^(?:\*\*)?Edit(?: \d+)?(?:\*\*)?: (?:- )?All checks are (now passing|passing now)", existing_body, re.MULTILINE):
4646 return True
4747 # If there are no edits at all, check the original comment body
48 if not re.search(r"^Edit(?: \d+)?:", existing_body, re.MULTILINE):
48 if not re.search(r"^(?:\*\*)?Edit(?: \d+)?(?:\*\*)?:", existing_body, re.MULTILINE):
4949 return "All our automated checks have passed" in existing_body
5050 return False
5151
@@ -53,17 +53,23 @@ def _was_already_passing(existing_body):
5353def _previous_failing_count(existing_body):
5454 """Extract the findings count from the most recent state in the comment."""
5555 # Check edit lines first (most recent state)
56 matches = re.findall(r"^Edit(?: \d+)?: (\d+) checks? (?:is|are) still failing", existing_body, re.MULTILINE)
56 matches = re.findall(r"^(?:\*\*)?Edit(?: \d+)?(?:\*\*)?: (?:- )?(\d+) checks? (?:is|are) still failing", existing_body, re.MULTILINE)
5757 if matches:
5858 return int(matches[-1])
5959 # No edits — count bullets in the original comment (before <details>)
60 if not re.search(r"^Edit(?: \d+)?:", existing_body, re.MULTILINE):
60 if not re.search(r"^(?:\*\*)?Edit(?: \d+)?(?:\*\*)?:", existing_body, re.MULTILINE):
6161 body_before_details = existing_body.split("<details>")[0]
6262 bullets = re.findall(r"^- .+$", body_before_details, re.MULTILINE)
6363 return len(bullets) if bullets else None
6464 return None
6565
6666
67def _extract_pr_author(existing_body):
68 """Extract the PR author username from the 'Hello @user' greeting."""
69 match = re.search(r"Hello @([\w-]+)", existing_body)
70 return match.group(1) if match else None
71
72
6773def build_edit_line(existing_body, findings_count, check_run_id, repo):
6874 """Build the edit line to append, or None if nothing to do."""
6975 run_tag = f"<!-- run:{check_run_id} -->"
@@ -79,20 +85,37 @@ def build_edit_line(existing_body, findings_count, check_run_id, repo):
7985 return None
8086
8187 # Count previous edits to determine the next number
82 edits = re.findall(r"^Edit(?: \d+)?:", existing_body, re.MULTILINE)
88 edits = re.findall(r"^(?:\*\*)?Edit(?: \d+)?(?:\*\*)?:", existing_body, re.MULTILINE)
8389 edit_count = len(edits)
8490 next_edit = edit_count + 1
8591
8692 run_url = f"https://github.com/{repo}/actions/runs/{check_run_id}"
8793
94 # Build resolved-issue prefix
95 prev_count = _previous_failing_count(existing_body)
96 resolved_prefix = ""
97 if prev_count is not None and prev_count > findings_count:
98 resolved = prev_count - findings_count
99 noun = "issue was" if resolved == 1 else "issues were"
100 resolved_prefix = f"{resolved} {noun} resolved, but "
101
88102 if findings_count == 0:
89 if edit_count == 0:
90 return f"Edit: All checks are now passing \U0001f389 {run_tag}"
91 return f"Edit {next_edit}: All checks are passing now \u2705 {run_tag}"
103 edit_label = "**Edit:**" if edit_count == 0 else f"**Edit {next_edit}:**"
104 line = f"{edit_label} - All checks are now passing \U0001f389, see [here]({run_url}) for details {run_tag}"
105 # Add thank-you when transitioning from failures to passing
106 if prev_count is not None and prev_count > 0:
107 author = _extract_pr_author(existing_body)
108 if author:
109 line += (
110 f"\n\nThank you @{author} for fixing those issues! \U0001f607\n"
111 f"This PR is now ready for human review, looping in @Lissy93 \U0001fae1"
112 )
113 return line
92114
93115 verb = "check is" if findings_count == 1 else "checks are"
116 edit_label = f"**Edit {next_edit}:**"
94117 return (
95 f"Edit {next_edit}: {findings_count} {verb} still failing, "
118 f"{edit_label} - {resolved_prefix}{findings_count} {verb} still failing, "
96119 f"see [here]({run_url}) for details {run_tag}"
97120 )
98121
@@ -135,7 +158,10 @@ def main():
135158 write_output("skip")
136159 return
137160
138 updated = existing_body.rstrip() + "\n\n" + edit_line
161 if "### Updates" in existing_body:
162 updated = existing_body.rstrip() + "\n" + edit_line
163 else:
164 updated = existing_body.rstrip() + "\n\n---\n\n### Updates\n\n" + edit_line
139165 write_output("update", updated)
140166
141167