Skip to content

Commit 843d556

Browse files
committed
fix: added ambigous rule count on PR comment
1 parent 6b2eda6 commit 843d556

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/event_processors/pull_request/processor.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ async def process(self, task: Task) -> ProcessingResult:
8585
# Agentic: scan repo only when relevant (PR targets default branch)
8686
# Use the PR head ref so we scan the branch being proposed, not main.
8787
suggested_rules_yaml: str | None = None
88+
suggested_rules_translated = 0
89+
suggested_rules_ambiguous: list[Any] = []
8890
if is_relevant_pr(task.payload):
8991
scan_start = time.time()
9092
try:
@@ -108,6 +110,8 @@ async def process(self, task: Task) -> ProcessingResult:
108110
"from_agent": from_agent,
109111
},
110112
)
113+
suggested_rules_translated = rules_count
114+
suggested_rules_ambiguous = list(ambiguous) if ambiguous else []
111115
if rules_count > 0:
112116
suggested_rules_yaml = rules_yaml
113117
except Exception:
@@ -196,6 +200,20 @@ async def process(self, task: Task) -> ProcessingResult:
196200
except yaml.YAMLError as e:
197201
logger.warning("Failed to parse suggested rules YAML: %s", e)
198202

203+
# Surface translation summary to the user (parity with push-event PR body)
204+
# Post when we have any scan result: translated and/or ambiguous, so users see X enforced and Y not translated
205+
if pr_number and (suggested_rules_translated > 0 or suggested_rules_ambiguous):
206+
try:
207+
comment_body = github_formatter.format_suggested_rules_ambiguous_comment(
208+
rules_translated=suggested_rules_translated,
209+
ambiguous=suggested_rules_ambiguous,
210+
)
211+
await self.github_client.create_pull_request_comment(
212+
repo_full_name, pr_number, comment_body, installation_id
213+
)
214+
except Exception as comment_err:
215+
logger.warning("Could not post suggested-rules translation summary comment: %s", comment_err)
216+
199217
# 3. Check for existing acknowledgments
200218
previous_acknowledgments = {}
201219
if pr_number:

src/presentation/github_formatter.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,45 @@ def format_rules_not_configured_comment(
190190
)
191191

192192

193+
def format_suggested_rules_ambiguous_comment(
194+
rules_translated: int,
195+
ambiguous: list[dict[str, Any]],
196+
max_statement_len: int = 200,
197+
max_reason_len: int = 150,
198+
) -> str:
199+
"""Format a PR comment when some AI rule statements could not be translated (parity with push PR body)."""
200+
count = len(ambiguous)
201+
lines = [
202+
"## Watchflow: Translation summary (AI rule files)",
203+
"",
204+
"**Translation summary:**",
205+
f"- {rules_translated} rule(s) successfully translated and enforced as pre-merge checks.",
206+
f"- {count} rule statement(s) could not be translated (low confidence or infeasible).",
207+
"",
208+
]
209+
if ambiguous:
210+
lines.append("**Could not be translated:**")
211+
lines.append("")
212+
for i, item in enumerate(ambiguous[:20], 1): # cap at 20 for comment length
213+
st = (item.get("statement") or "") if isinstance(item, dict) else ""
214+
path = (item.get("path") or "") if isinstance(item, dict) else ""
215+
reason = (item.get("reason") or "") if isinstance(item, dict) else ""
216+
if len(st) > max_statement_len:
217+
st = st[:max_statement_len].rstrip() + "…"
218+
if len(reason) > max_reason_len:
219+
reason = reason[:max_reason_len].rstrip() + "…"
220+
lines.append(f"{i}. `{path}`: {st}")
221+
if reason:
222+
lines.append(f" - *Reason:* {reason}")
223+
lines.append("")
224+
if len(ambiguous) > 20:
225+
lines.append(f"*…and {len(ambiguous) - 20} more.*")
226+
lines.append("")
227+
lines.append("---")
228+
lines.append("*This comment was automatically posted by [Watchflow](https://watchflow.dev).*")
229+
return "\n".join(lines)
230+
231+
193232
def format_violations_comment(violations: list[Violation], content_hash: str | None = None) -> str:
194233
"""Format violations as a GitHub comment.
195234

0 commit comments

Comments
 (0)