feat(ai_review): parse .pr-review.json:static_message + render as banner

Repos can pin a free-text notice (e.g. 'this repo is in maintenance mode',
or 'reviewers: focus on the public API only for this quarter') in
.pr-review.json:static_message. The string is stripped and capped at 400
chars (mirror of the existing instructions cap), then rendered as a
Markdown blockquote (> {msg}) directly under the REVIEW_HEADER so it
surfaces on every review without scrolling.

Plumbing: parse_repo_config exposes 'static_message'; format_review_body
accepts a static_message kwarg and inserts the blockquote before the
'### Summary of Changes' section; review_pr threads
config.get('static_message') to both call sites (salvage path + happy
path). Empty / non-string values are silently dropped, mirroring the
parser's 'ignore blank' handling for every other text field.
This commit is contained in:
Marcos
2026-08-22 14:43:59 +00:00
parent b6b8173ccb
commit 7f37a36722
2 changed files with 52 additions and 1 deletions
+34
View File
@@ -401,6 +401,24 @@ def test_parse_repo_config_partial_and_bad():
assert parse_repo_config('{"instructions":" "}') == {}
def test_parse_repo_config_reads_static_message():
cfg = parse_repo_config(json.dumps({"static_message": " NOTE: this repo is in maintenance mode "}))
assert cfg == {"static_message": "NOTE: this repo is in maintenance mode"}
def test_parse_repo_config_static_message_caps_length():
long_text = "x" * 9999
cfg = parse_repo_config(json.dumps({"static_message": long_text}))
assert "static_message" in cfg
assert len(cfg["static_message"]) <= 400
def test_parse_repo_config_static_message_ignores_blank():
assert "static_message" not in parse_repo_config(json.dumps({"static_message": " "}))
assert "static_message" not in parse_repo_config(json.dumps({"static_message": ""}))
assert "static_message" not in parse_repo_config(json.dumps({"static_message": 42}))
# ---------------------------------------------------------------------------
# dedupe / prior-context parsing
# ---------------------------------------------------------------------------
@@ -823,6 +841,22 @@ def test_format_review_body_no_usage_section_omitted():
assert "AI usage" not in body
def test_format_review_body_renders_static_message_banner():
body = format_review_body(
"", "glm-5.2:cloud", "abcdef1234567890",
static_message="NOTE: this repo is in maintenance mode.",
)
assert "> NOTE: this repo is in maintenance mode." in body
# Banner sits under the header and above the rest of the body.
assert body.index("NOTE") > body.index("🤖")
assert body.index("NOTE") < body.index("### Summary of Changes")
def test_format_review_body_omits_static_message_when_blank():
body = format_review_body("", "glm-5.2:cloud", "abcdef1234567890")
assert "> " not in body
def test_format_review_body_with_summary_changes_and_risks():
body = format_review_body(
"", "glm-5.2:cloud", "abcdef1234567890",