Skip to content

Commit 6b2eda6

Browse files
committed
fix: added more information for PR and removed duplication for PR creation
1 parent 3ee6e4d commit 6b2eda6

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

src/api/recommendations.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,35 @@ def generate_pr_body(
471471
return "\n".join(body_lines)
472472

473473

474+
def generate_pr_body_for_suggested_rules(
475+
repo_full_name: str,
476+
rules_yaml: str,
477+
rules_translated: int = 0,
478+
rules_ambiguous: int = 0,
479+
installation_id: int | None = None,
480+
) -> str:
481+
"""
482+
Generate PR body for push-triggered "suggested rules" PRs (AI rule files translated to YAML).
483+
484+
Used by the push processor when creating a PR from translated AI rule files. Keeps
485+
PR body formatting in one place alongside generate_pr_body (repository-analysis flow).
486+
"""
487+
extracted_total = rules_translated + rules_ambiguous
488+
summary_lines = [
489+
f"- {extracted_total} rule statement(s) extracted from AI rule files",
490+
f"- {rules_translated} rule(s) successfully translated to Watchflow YAML",
491+
f"- {rules_ambiguous} rule(s) could not be translated (low confidence or infeasible)",
492+
]
493+
translation_summary = "\n".join(summary_lines)
494+
return (
495+
"This PR was auto-generated by Watchflow because AI rule files (e.g. `rules.md`, "
496+
"`*guidelines*.md`) were updated. It proposes updating `.watchflow/rules.yaml` with "
497+
"the translated rules so your team can review the auto-generated constraints before merging.\n\n"
498+
"**Translation Summary:**\n"
499+
f"{translation_summary}"
500+
)
501+
502+
474503
def generate_pr_title(recommendations: list[Any]) -> str:
475504
"""
476505
Generate a professional, concise PR title based on recommendations.

src/event_processors/push.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any
44

55
from src.agents import get_agent
6-
from src.api.recommendations import get_suggested_rules_from_repo
6+
from src.api.recommendations import generate_pr_body_for_suggested_rules, get_suggested_rules_from_repo
77
from src.core.config import config
88
from src.core.models import Severity, Violation
99
from src.core.utils.event_filter import NULL_SHA
@@ -122,6 +122,8 @@ async def process(self, task: Task) -> ProcessingResult:
122122
github_token=github_token,
123123
rules_yaml=rules_yaml,
124124
push_sha=payload.get("after") or payload.get("head_commit", {}).get("sha"),
125+
rules_translated=rules_count,
126+
rules_ambiguous=len(ambiguous),
125127
)
126128
except Exception as e:
127129
latency_ms = int((time.time() - scan_start) * 1000)
@@ -234,6 +236,8 @@ async def _create_pr_with_suggested_rules(
234236
github_token: str,
235237
rules_yaml: str,
236238
push_sha: str | None,
239+
rules_translated: int = 0,
240+
rules_ambiguous: int = 0,
237241
) -> None:
238242
"""
239243
Self-improving loop: create a branch with proposed .watchflow/rules.yaml and open a PR
@@ -366,10 +370,12 @@ async def _create_pr_with_suggested_rules(
366370
)
367371
return
368372

369-
pr_body = (
370-
"This PR was auto-generated by Watchflow because AI rule files (e.g. `rules.md`, "
371-
"`*guidelines*.md`) were updated. It proposes updating `.watchflow/rules.yaml` with "
372-
"the translated rules so your team can review the auto-generated constraints before merging."
373+
pr_body = generate_pr_body_for_suggested_rules(
374+
repo_full_name=repo_full_name,
375+
rules_yaml=rules_yaml,
376+
rules_translated=rules_translated,
377+
rules_ambiguous=rules_ambiguous,
378+
installation_id=installation_id,
373379
)
374380
pr_result = await self.github_client.create_pull_request(
375381
repo_full_name,

0 commit comments

Comments
 (0)