From a38d1032b61bb141954d6f4716f499d487bfd514 Mon Sep 17 00:00:00 2001 From: thejesh23 <35212698+thejesh23@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:23:56 -0800 Subject: [PATCH] Bots: stay quiet on a pull request that only deletes entries A maintainer removing a test graduate would have got a red check and a 'fix your file' comment. Deleted files no longer make a PR a learner's. Only a passing check ever merges, so nothing gets in this way. Co-Authored-By: Claude Opus 5.5 --- tests/test_workflows.py | 40 +++++++++++++++++++++++++++++++++++++ tools/check_exercise_2.py | 4 +++- tools/check_first_commit.py | 3 ++- tools/check_graduate.py | 7 +++++-- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 56c48d5..dd9def9 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -72,3 +72,43 @@ def test_bug_report_bot_only_comments(): # The issue text reaches the checker only through env: never ${{ }} inside run: for block in re.findall(r"run: \|\n((?:\s{10}.*\n?)+)", text): assert "${{" not in block + + +def test_the_bots_stay_quiet_when_a_maintainer_only_deletes_entries(tmp_path, monkeypatch, capsys): + """Removing a graduate or a first commit is maintainer clean-up, not a learner's PR to check.""" + import subprocess + import sys + + sys.path.insert(0, str(WORKFLOWS.parent.parent / "tools")) + import check_exercise_2 + import check_first_commit + import check_graduate + + def git(*args): + return subprocess.run(["git", *args], cwd=tmp_path, check=True, capture_output=True, text=True).stdout.strip() + + git("init", "-q", "-b", "main") + git("config", "user.email", "t@example.com") + git("config", "user.name", "t") + files = { + "graduates/ada.py": 'name = "Ada"\ngithub = "ada"\npr = "https://github.com/o/r/pull/1"\nmessage = "hi"\n', + "first-commits/ada.py": 'name = "Ada"\ngithub = "ada"\nmessage = "hi"\n', + "practice/greetings/ada.py": "def greet(name: str) -> str:\n return name\n", + "practice/tests/test_ada.py": "from greetings.ada import greet\n", + } + for path, text in files.items(): + (tmp_path / path).parent.mkdir(parents=True, exist_ok=True) + (tmp_path / path).write_text(text) + git("add", ".") + git("commit", "-qm", "entries") + base = git("rev-parse", "HEAD") + git("rm", "-q", *files) + git("commit", "-qm", "maintainer removes the test entries") + head = git("rev-parse", "HEAD") + monkeypatch.chdir(tmp_path) + + args = ["--login", "maintainer", "--base", base, "--head", head] + assert check_graduate.main(args) == check_graduate.NOT_A_LEARNER_PR + assert check_first_commit.main(args) == check_first_commit.NOT_A_LEARNER_PR + assert check_exercise_2.main([*args, "--tests", "success"]) == check_exercise_2.NOT_A_LEARNER_PR + assert capsys.readouterr().out == "" diff --git a/tools/check_exercise_2.py b/tools/check_exercise_2.py index 3163468..2cd7128 100644 --- a/tools/check_exercise_2.py +++ b/tools/check_exercise_2.py @@ -288,7 +288,9 @@ def main(argv: list[str] | None = None) -> int: parser.add_argument("--tests", required=True, help="conclusion of the Exercise 2 tests run") parser.add_argument("--run-url", default="") args = parser.parse_args(argv) - if not is_learner_pr(_git("diff", "--no-renames", "--name-only", f"{args.base}...{args.head}").splitlines()): + if not is_learner_pr( + _git("diff", "--no-renames", "--diff-filter=d", "--name-only", f"{args.base}...{args.head}").splitlines() + ): return NOT_A_LEARNER_PR result = validate(args.login, args.base, args.head) print(format_comment(result, args.login, args.tests, args.run_url)) diff --git a/tools/check_first_commit.py b/tools/check_first_commit.py index 3d97700..60c69b1 100644 --- a/tools/check_first_commit.py +++ b/tools/check_first_commit.py @@ -220,7 +220,8 @@ def main(argv: list[str] | None = None) -> int: parser.add_argument("--base", required=True) parser.add_argument("--head", required=True) args = parser.parse_args(argv) - paths = _git("diff", "--no-renames", "--name-only", f"{args.base}...{args.head}").splitlines() + # Deleted files are left out: a maintainer removing an entry isn't a learner's PR, so the bot stays quiet. + paths = _git("diff", "--no-renames", "--diff-filter=d", "--name-only", f"{args.base}...{args.head}").splitlines() if not is_learner_pr(paths): return NOT_A_LEARNER_PR from check_exercise_2 import is_learner_pr as is_exercise_2_pr # imported here: that module imports this one diff --git a/tools/check_graduate.py b/tools/check_graduate.py index d83d700..16daadc 100644 --- a/tools/check_graduate.py +++ b/tools/check_graduate.py @@ -21,7 +21,8 @@ python tools/check_graduate.py --login LOGIN --base BASE --head HEAD Prints a Markdown comment; exits 0 if valid, 1 if not, 3 (silently) if the PR -doesn't touch ``graduates/.py`` at all. +doesn't add or change any ``graduates/.py`` (a maintainer removing an +entry only deletes, so the bot stays quiet). """ from __future__ import annotations @@ -198,7 +199,9 @@ def main(argv: list[str] | None = None) -> int: parser.add_argument("--base", required=True) parser.add_argument("--head", required=True) args = parser.parse_args(argv) - if not is_learner_pr(_git("diff", "--no-renames", "--name-only", f"{args.base}...{args.head}").splitlines()): + if not is_learner_pr( + _git("diff", "--no-renames", "--diff-filter=d", "--name-only", f"{args.base}...{args.head}").splitlines() + ): return NOT_A_LEARNER_PR result = validate(args.login, args.base, args.head) print(format_comment(result, args.login))