Skip to content

Commit ed93400

Browse files
committed
fix: keep the skip sentence short
Drop the config section from the verdict sentence so the common bot case reads "Skipped because author dependabot[bot] is in ignore_authors." once; the per-line reasons keep the section. Accept the CLI's new optional reason key in the real-binary contract test.
1 parent 874136e commit ed93400

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

‎main.py‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,10 +1053,16 @@ def _skip_count(results: list[ScopeResult]) -> int:
10531053
def _skip_reasons(results: list[ScopeResult]) -> str:
10541054
"""One sentence naming why checks were skipped, or ``""`` if unknown.
10551055
1056-
The verdict line is all most readers see; the per-scope reasons sit in
1057-
a collapsed block. Each distinct reason is named once, in order.
1056+
The verdict line is all most readers see, so it stays short: the config
1057+
section is dropped ("[commit].ignore_authors" and "[branch].ignore_authors"
1058+
both read "ignore_authors"), which folds the usual bot case into one
1059+
reason. The per-scope lines in the collapsed block keep the section.
10581060
"""
1059-
reasons = list(dict.fromkeys(s.skip_reason for s in results if s.skip_reason))
1061+
reasons = list(
1062+
dict.fromkeys(
1063+
re.sub(r"\[\w+\]\.", "", s.skip_reason) for s in results if s.skip_reason
1064+
)
1065+
)
10601066
return f"Skipped because {'; '.join(reasons)}." if reasons else ""
10611067

10621068

@@ -1240,8 +1246,7 @@ def _scope_value(scope: ScopeResult, max_len: int = 60) -> str:
12401246
#
12411247
# ⊘ **All 5 checks skipped** — nothing was validated
12421248
#
1243-
# Skipped because author dependabot[bot] is in [commit].ignore_authors;
1244-
# author dependabot[bot] is in [branch].ignore_authors.
1249+
# Skipped because author dependabot[bot] is in ignore_authors.
12451250
#
12461251
# ```text
12471252
# Commit message

‎main_test.py‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,7 +2778,7 @@ def test_skip_reason_is_shown_on_the_scope_and_under_the_verdict(self):
27782778
body = main.render_report(results)
27792779
self.assertIn(
27802780
"⊘ **All 3 checks skipped** — nothing was validated\n\n"
2781-
f"Skipped because {commit}; {branch}.\n",
2781+
"Skipped because author dependabot[bot] is in ignore_authors.\n",
27822782
body,
27832783
)
27842784
self.assertIn(f" ⊘ PR title (skipped: {commit})", body)
@@ -2789,7 +2789,8 @@ def test_skip_reason_follows_a_partial_skip_verdict(self):
27892789
results = [pass_scope("PR title"), skip_scope("Branch", reason=reason)]
27902790
body = main.render_report(results)
27912791
self.assertIn(
2792-
f"✅ **1 of 2 checks passed**, 1 skipped\n\nSkipped because {reason}.\n",
2792+
"✅ **1 of 2 checks passed**, 1 skipped\n\n"
2793+
"Skipped because author dependabot[bot] is in ignore_authors.\n",
27932794
body,
27942795
)
27952796

@@ -2798,14 +2799,20 @@ def test_skip_reason_reaches_the_step_log(self):
27982799
with patch("sys.stdout", new_callable=io.StringIO) as out:
27992800
main.render_step_log([skip_scope("PR title", reason=reason)])
28002801
self.assertIn(f" ⊘ PR title (skipped: {reason})", out.getvalue())
2801-
self.assertIn(f"Skipped because {reason}.", out.getvalue())
2802+
self.assertIn(
2803+
"Skipped because author dependabot[bot] is in ignore_authors.",
2804+
out.getvalue(),
2805+
)
28022806

28032807
def test_skip_reason_follows_a_partial_skip_in_the_step_log(self):
28042808
reason = "author dependabot[bot] is in [branch].ignore_authors"
28052809
results = [pass_scope("PR title"), skip_scope("Branch", reason=reason)]
28062810
with patch("sys.stdout", new_callable=io.StringIO) as out:
28072811
main.render_step_log(results)
2808-
self.assertIn(f"Skipped because {reason}.", out.getvalue())
2812+
self.assertIn(
2813+
"Skipped because author dependabot[bot] is in ignore_authors.",
2814+
out.getvalue(),
2815+
)
28092816

28102817
def test_a_passing_scope_has_no_skip_reason(self):
28112818
self.assertEqual(pass_scope("Branch", value="main").skip_reason, "")
@@ -3216,6 +3223,8 @@ def test_step_log_all_skipped_claims_no_pass(self):
32163223
"fix",
32173224
"docs_url",
32183225
}
3226+
#: Keys newer CLIs add on top: ``reason`` says why a check was skipped.
3227+
OPTIONAL_CHECK_KEYS = {"reason"}
32193228
STATUSES = {"pass", "fail", "warn", "skip"}
32203229

32213230

@@ -3278,7 +3287,8 @@ def _run(self, message: str) -> tuple[int, dict]:
32783287
self.assertIn("checks", data)
32793288
self.assertTrue(data["checks"], "CLI reported no checks")
32803289
for check in data["checks"]:
3281-
self.assertEqual(set(check), CHECK_KEYS, check)
3290+
self.assertLessEqual(CHECK_KEYS, set(check), check)
3291+
self.assertLessEqual(set(check), CHECK_KEYS | OPTIONAL_CHECK_KEYS, check)
32823292
self.assertIn(check["status"], STATUSES, check)
32833293
self.assertRegex(check["rule_id"], r"^CC\d{3}$")
32843294
self.assertTrue(

0 commit comments

Comments
 (0)