Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ""
4 changes: 3 additions & 1 deletion tools/check_exercise_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion tools/check_first_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions tools/check_graduate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>.py`` at all.
doesn't add or change any ``graduates/<name>.py`` (a maintainer removing an
entry only deletes, so the bot stays quiet).
"""

from __future__ import annotations
Expand Down Expand Up @@ -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))
Expand Down
Loading