Commit f1b012efb2
Unsigned
Layout: unified · split
lib/checks/prepare-comment.py +36 −10
| @@ -42,10 +42,10 @@ def read_findings_count(new_body): | |||
| 42 | def _was_already_passing(existing_body): | 42 | def _was_already_passing(existing_body): |
| 43 | """Check if the most recent state in the comment is already all-clear.""" | 43 | """Check if the most recent state in the comment is already all-clear.""" |
| 44 | # If there's a previous "all passing" edit, the last state was passing | 44 | # 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): |
| 46 | return True | 46 | return True |
| 47 | # If there are no edits at all, check the original comment body | 47 | # 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): |
| 49 | return "All our automated checks have passed" in existing_body | 49 | return "All our automated checks have passed" in existing_body |
| 50 | return False | 50 | return False |
| 51 | 51 | ||
| @@ -53,17 +53,23 @@ def _was_already_passing(existing_body): | |||
| 53 | def _previous_failing_count(existing_body): | 53 | def _previous_failing_count(existing_body): |
| 54 | """Extract the findings count from the most recent state in the comment.""" | 54 | """Extract the findings count from the most recent state in the comment.""" |
| 55 | # Check edit lines first (most recent state) | 55 | # 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) |
| 57 | if matches: | 57 | if matches: |
| 58 | return int(matches[-1]) | 58 | return int(matches[-1]) |
| 59 | # No edits — count bullets in the original comment (before <details>) | 59 | # 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): |
| 61 | body_before_details = existing_body.split("<details>")[0] | 61 | body_before_details = existing_body.split("<details>")[0] |
| 62 | bullets = re.findall(r"^- .+$", body_before_details, re.MULTILINE) | 62 | bullets = re.findall(r"^- .+$", body_before_details, re.MULTILINE) |
| 63 | return len(bullets) if bullets else None | 63 | return len(bullets) if bullets else None |
| 64 | return None | 64 | return None |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | def _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 | |||
| 67 | def build_edit_line(existing_body, findings_count, check_run_id, repo): | 73 | def build_edit_line(existing_body, findings_count, check_run_id, repo): |
| 68 | """Build the edit line to append, or None if nothing to do.""" | 74 | """Build the edit line to append, or None if nothing to do.""" |
| 69 | run_tag = f"<!-- run:{check_run_id} -->" | 75 | run_tag = f"<!-- run:{check_run_id} -->" |
| @@ -79,20 +85,37 @@ def build_edit_line(existing_body, findings_count, check_run_id, repo): | |||
| 79 | return None | 85 | return None |
| 80 | 86 | ||
| 81 | # Count previous edits to determine the next number | 87 | # 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) |
| 83 | edit_count = len(edits) | 89 | edit_count = len(edits) |
| 84 | next_edit = edit_count + 1 | 90 | next_edit = edit_count + 1 |
| 85 | 91 | ||
| 86 | run_url = f"https://github.com/{repo}/actions/runs/{check_run_id}" | 92 | run_url = f"https://github.com/{repo}/actions/runs/{check_run_id}" |
| 87 | 93 | ||
| 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 | |||
| 88 | if findings_count == 0: | 102 | if findings_count == 0: |
| 89 | if edit_count == 0: | 103 | edit_label = "**Edit:**" if edit_count == 0 else f"**Edit {next_edit}:**" |
| 90 | return f"Edit: All checks are now passing \U0001f389 {run_tag}" | 104 | line = f"{edit_label} - All checks are now passing \U0001f389, see [here]({run_url}) for details {run_tag}" |
| 91 | return f"Edit {next_edit}: All checks are passing now \u2705 {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 | ||
| 92 | 114 | ||
| 93 | verb = "check is" if findings_count == 1 else "checks are" | 115 | verb = "check is" if findings_count == 1 else "checks are" |
| 116 | edit_label = f"**Edit {next_edit}:**" | ||
| 94 | return ( | 117 | return ( |
| 95 | f"Edit {next_edit}: {findings_count} {verb} still failing, " | 118 | f"{edit_label} - {resolved_prefix}{findings_count} {verb} still failing, " |
| 96 | f"see [here]({run_url}) for details {run_tag}" | 119 | f"see [here]({run_url}) for details {run_tag}" |
| 97 | ) | 120 | ) |
| 98 | 121 | ||
| @@ -135,7 +158,10 @@ def main(): | |||
| 135 | write_output("skip") | 158 | write_output("skip") |
| 136 | return | 159 | return |
| 137 | 160 | ||
| 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 | ||
| 139 | write_output("update", updated) | 165 | write_output("update", updated) |
| 140 | 166 | ||
| 141 | 167 | ||