Skip to content

Commit 547ffd0

Browse files
committed
fix: let the agent prompt change the files a finding names
The prompt opened with "without changing any code" and then asked for a file to be taken out of a commit. With a files finding it now reads "changing only the files they name".
1 parent 73fb8a8 commit 547ffd0

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎main.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,10 @@ def _diff_block(results: list[ScopeResult], status: str = "fail") -> list[str]:
19551955

19561956
#: First line of the prompt "How to fix" offers for an AI coding agent.
19571957
AGENT_PROMPT = "Fix these Commit Check findings without changing any code:"
1958+
#: The same line when a finding is about a file, which then has to change.
1959+
AGENT_PROMPT_FILES = (
1960+
"Fix these Commit Check findings, changing only the files they name:"
1961+
)
19581962
BRANCH_HELP = (
19591963
"**Branch name.** Rename the branch and push it. A pull request cannot "
19601964
"change its branch, so open a new one from the renamed branch:"
@@ -1980,7 +1984,8 @@ def _agent_prompt(failing: list[ScopeResult]) -> list[str]:
19801984
19811985
A files scope gets a line per finding: each is about a path of its own.
19821986
"""
1983-
lines = [AGENT_PROMPT]
1987+
about_files = any(scope.label == FILES_LABEL for scope in failing)
1988+
lines = [AGENT_PROMPT_FILES if about_files else AGENT_PROMPT]
19841989
for scope in failing:
19851990
if scope.label == FILES_LABEL:
19861991
label = f"Files of commit {scope.sha[:7]}" if scope.sha else scope.label
@@ -2215,7 +2220,9 @@ def _all_checks(results: list[ScopeResult]) -> list[str]:
22152220
# ("Commit 1/11") stays bare in the `result` output.
22162221
# - With `files: true` each commit also gets a row in a "Files" group, for the
22172222
# files it changes. Its hunk reads `@@ 5584f46 files @@`, with a red line per
2218-
# path a rule found and the rule's advice under it.
2223+
# path a rule found and the rule's advice under it. The agent prompt then
2224+
# opens with "changing only the files they name" in place of "without
2225+
# changing any code".
22192226
# - One check is one thing that was checked — a commit message, the branch, the
22202227
# author — not one rule evaluation. The totals therefore match the number of
22212228
# ✔/✖ rows the reader can count in the listing, and do not grow with the

‎main_test.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5533,6 +5533,15 @@ def test_how_to_fix_gives_each_finding_a_line_and_no_reword_commands(self):
55335533
self.assertNotIn("Reword", how)
55345534
self.assertNotIn(main.FILES_HELP, "\n".join(main._how_to_fix([fail_scope()])))
55355535

5536+
def test_the_prompt_lets_the_named_files_change(self):
5537+
"""Taking a file out of a commit cannot be done "without changing any code"."""
5538+
self.assertEqual(main._agent_prompt([fail_scope()])[0], AGENT_PROMPT)
5539+
for failing in ([files_scope()], [fail_scope(), files_scope()]):
5540+
self.assertEqual(
5541+
main._agent_prompt(failing)[0],
5542+
"Fix these Commit Check findings, changing only the files they name:",
5543+
)
5544+
55365545
def test_each_finding_is_an_annotation_about_its_own_path(self):
55375546
out = io.StringIO()
55385547
with patch("sys.stdout", out), patch("main.DRY_RUN_ENABLED", False):

0 commit comments

Comments
 (0)