From d63783aba6fddf2e96ea0c5e27267c2f0fce3f7f Mon Sep 17 00:00:00 2001 From: thejesh23 <35212698+thejesh23@users.noreply.github.com> Date: Sat, 21 Nov 2026 19:28:53 -0800 Subject: [PATCH] Bots check and comment; a maintainer reviews and merges The first-commit, Exercise 2 and graduate bots no longer merge. They check the PR, comment, and say a maintainer will review it, so they now need only read access to the repo's code. The leftover congratulation step (its token was removed) goes too. Lessons, READMEs, the curriculum, the landing copy and the lesson 02 and 05 video scripts now describe the maintainer merge. Co-Authored-By: Claude Opus 5.5 --- .github/congrats/README.md | 13 -------- .github/congrats/exercise-2.md | 3 -- .github/congrats/first-commit.md | 5 ---- .github/workflows/ci.yml | 2 -- .github/workflows/exercise-2-merge.yml | 31 ++------------------ .github/workflows/first-commit.yml | 31 ++------------------ .github/workflows/graduate.yml | 13 ++------ .github/workflows/graduates-wall.yml | 6 ++-- CURRICULUM.md | 2 +- README.md | 4 +-- first-commits/README.md | 2 +- lessons/02-first-pr-in-browser/README.md | 5 ++-- lessons/02-first-pr-in-browser/exercise.md | 2 +- lessons/02-first-pr-in-browser/script.md | 15 ++++++---- lessons/05-second-pr-from-terminal/README.md | 4 +-- lessons/05-second-pr-from-terminal/script.md | 6 ++-- lessons/13-capstone/README.md | 4 +-- practice/README.md | 2 +- publishing/udemy-landing.md | 2 +- tests/test_check_exercise_2.py | 4 +-- tests/test_congrats.py | 27 ----------------- tests/test_workflows.py | 22 ++++++++++++++ tools/check_exercise_2.py | 7 +++-- tools/check_first_commit.py | 9 +++--- tools/check_graduate.py | 3 +- 25 files changed, 73 insertions(+), 151 deletions(-) delete mode 100644 .github/congrats/README.md delete mode 100644 .github/congrats/exercise-2.md delete mode 100644 .github/congrats/first-commit.md delete mode 100644 tests/test_congrats.py create mode 100644 tests/test_workflows.py diff --git a/.github/congrats/README.md b/.github/congrats/README.md deleted file mode 100644 index 00206e3..0000000 --- a/.github/congrats/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Maintainer congratulations - -When a learner's first commit (Lesson 02) or Exercise 2 pull request (Lesson 05) -passes the bot's checks, the workflow approves the pull request with one of -these messages, posted from the maintainer's own GitHub account, then merges it. - -`{login}` is replaced with the learner's GitHub username. Edit the messages -freely; they're read from `main` on every run. - -The review is posted with the `MAINTAINER_TOKEN` repository secret: a -fine-grained personal access token for this repository only, with -**Pull requests: Read and write**. Without the secret the step is skipped and -the bot still merges. diff --git a/.github/congrats/exercise-2.md b/.github/congrats/exercise-2.md deleted file mode 100644 index 0856721..0000000 --- a/.github/congrats/exercise-2.md +++ /dev/null @@ -1,3 +0,0 @@ -Great work, @{login}! 🎉 A Python function, a test for it, and green CI: that's exactly how real projects work. - -You've now done the whole loop from the terminal. Lesson 06 shows you the house rules every project has, and then you're ready for the real world. diff --git a/.github/congrats/first-commit.md b/.github/congrats/first-commit.md deleted file mode 100644 index 4d1a226..0000000 --- a/.github/congrats/first-commit.md +++ /dev/null @@ -1,5 +0,0 @@ -Congratulations on your first commit, @{login}! 🎉 - -That's a real contribution, merged into a real repository. Welcome to open source, I'm really glad you're here. - -See you in Lesson 03, where you set up git on your own machine. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b1d15b..cdd8628 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,8 +15,6 @@ jobs: check: runs-on: ubuntu-latest steps: - - name: Runner tools the bots' token step relies on - run: /usr/bin/gh --version && /usr/bin/sed --version | head -1 - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5 - run: uv run ruff check . diff --git a/.github/workflows/exercise-2-merge.yml b/.github/workflows/exercise-2-merge.yml index 52ec39d..91db30f 100644 --- a/.github/workflows/exercise-2-merge.yml +++ b/.github/workflows/exercise-2-merge.yml @@ -2,7 +2,8 @@ name: Exercise 2 review # Runs after "Exercise 2 tests" finishes, with a write token. It never checks # out or runs the PR's code: it reads the PR's files with git show and -# tools/check_exercise_2.py (from main), comments, and merges if all is well. +# tools/check_exercise_2.py (from main) and comments. A maintainer reviews and +# merges. # PRs that don't touch a learner's exercise files (status 3) get no comment. on: @@ -11,7 +12,7 @@ on: types: [completed] permissions: - contents: write + contents: read pull-requests: write jobs: @@ -73,32 +74,6 @@ jobs: PR: ${{ steps.pr.outputs.number }} run: gh pr comment "$PR" --repo "$GITHUB_REPOSITORY" --body-file comment.md - - name: Congratulate from the maintainer's account - # Posts .github/congrats/exercise-2.md as an approving review from the - # MAINTAINER_TOKEN owner. Optional: skipped without the secret, and a - # failure here never blocks the merge. The token is only in this step's - # env, and this step runs only bash and the runner image's own /usr/bin tools. - if: steps.pr.outputs.number && steps.check.outputs.status == '0' - continue-on-error: true - env: - GH_TOKEN: ${{ secrets.MAINTAINER_TOKEN }} - PR: ${{ steps.pr.outputs.number }} - LOGIN: ${{ steps.pr.outputs.login }} - run: | - if [ -z "$GH_TOKEN" ]; then echo "No MAINTAINER_TOKEN secret; skipping."; exit 0; fi - # GitHub logins are only letters, digits and hyphens, so they are safe in sed. - case "$LOGIN" in *[!A-Za-z0-9-]*|"") echo "Unexpected login"; exit 1;; esac - /usr/bin/sed "s/{login}/$LOGIN/g" .github/congrats/exercise-2.md > congrats.md - /usr/bin/gh pr review "$PR" --repo "$GITHUB_REPOSITORY" --approve --body-file congrats.md - - - name: Merge - if: steps.pr.outputs.number && steps.check.outputs.status == '0' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR: ${{ steps.pr.outputs.number }} - HEAD_SHA: ${{ github.event.workflow_run.head_sha }} - run: gh pr merge "$PR" --repo "$GITHUB_REPOSITORY" --merge --match-head-commit "$HEAD_SHA" - - name: Fail when the PR needs fixes if: steps.pr.outputs.number && steps.check.outputs.status != '0' && steps.check.outputs.status != '3' run: exit 1 diff --git a/.github/workflows/first-commit.yml b/.github/workflows/first-commit.yml index c487bb4..3bd3037 100644 --- a/.github/workflows/first-commit.yml +++ b/.github/workflows/first-commit.yml @@ -1,7 +1,8 @@ name: Validate first commit # pull_request_target runs this workflow from the base branch with a write -# token, so a fork's PR can be commented on and merged. To stay safe, the PR's +# token, so a fork's PR can be commented on. A maintainer reviews and merges. +# To stay safe, the PR's # code is never checked out or executed: the validator comes from the base # branch and only reads the learner's file with git show + ast.parse. # PRs that don't touch first-commits/.py (status 3) get no comment. @@ -13,7 +14,7 @@ on: paths: ["first-commits/**"] permissions: - contents: write + contents: read pull-requests: write concurrency: @@ -58,32 +59,6 @@ jobs: PR: ${{ github.event.pull_request.number }} run: gh pr comment "$PR" --repo "$GITHUB_REPOSITORY" --body-file comment.md - - name: Congratulate from the maintainer's account - # Posts .github/congrats/first-commit.md as an approving review from the - # MAINTAINER_TOKEN owner. Optional: skipped without the secret, and a - # failure here never blocks the merge. The token is only in this step's - # env, and this step runs only bash and the runner image's own /usr/bin tools. - if: steps.check.outputs.status == '0' - continue-on-error: true - env: - GH_TOKEN: ${{ secrets.MAINTAINER_TOKEN }} - PR: ${{ github.event.pull_request.number }} - LOGIN: ${{ github.event.pull_request.user.login }} - run: | - if [ -z "$GH_TOKEN" ]; then echo "No MAINTAINER_TOKEN secret; skipping."; exit 0; fi - # GitHub logins are only letters, digits and hyphens, so they are safe in sed. - case "$LOGIN" in *[!A-Za-z0-9-]*|"") echo "Unexpected login"; exit 1;; esac - /usr/bin/sed "s/{login}/$LOGIN/g" .github/congrats/first-commit.md > congrats.md - /usr/bin/gh pr review "$PR" --repo "$GITHUB_REPOSITORY" --approve --body-file congrats.md - - - name: Merge - if: steps.check.outputs.status == '0' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR: ${{ github.event.pull_request.number }} - HEAD: ${{ github.event.pull_request.head.sha }} - run: gh pr merge "$PR" --repo "$GITHUB_REPOSITORY" --merge --match-head-commit "$HEAD" - - name: Fail the check when the file needs fixes if: steps.check.outputs.status != '0' && steps.check.outputs.status != '3' run: exit 1 diff --git a/.github/workflows/graduate.yml b/.github/workflows/graduate.yml index 0bbbc81..07b7d34 100644 --- a/.github/workflows/graduate.yml +++ b/.github/workflows/graduate.yml @@ -3,7 +3,8 @@ name: Validate graduate # Same safety model as first-commit.yml: runs from the base branch, never # checks out or runs the PR's code, reads graduates/.py with git show + # ast.parse, and looks up the linked PR with the GitHub API (read-only). -# PRs that don't touch graduates/.py (status 3) get no comment. +# PRs that don't touch graduates/.py (status 3) get no comment. The bot +# only checks and comments; a maintainer reviews and merges. on: pull_request_target: @@ -12,7 +13,7 @@ on: paths: ["graduates/**"] permissions: - contents: write + contents: read pull-requests: write concurrency: @@ -58,14 +59,6 @@ jobs: PR: ${{ github.event.pull_request.number }} run: gh pr comment "$PR" --repo "$GITHUB_REPOSITORY" --body-file comment.md - - name: Merge - if: steps.check.outputs.status == '0' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR: ${{ github.event.pull_request.number }} - HEAD: ${{ github.event.pull_request.head.sha }} - run: gh pr merge "$PR" --repo "$GITHUB_REPOSITORY" --merge --match-head-commit "$HEAD" - - name: Fail the check when the file needs fixes if: steps.check.outputs.status != '0' && steps.check.outputs.status != '3' run: exit 1 diff --git a/.github/workflows/graduates-wall.yml b/.github/workflows/graduates-wall.yml index cca9b07..350433f 100644 --- a/.github/workflows/graduates-wall.yml +++ b/.github/workflows/graduates-wall.yml @@ -3,9 +3,9 @@ name: Update graduates wall # Regenerates graduates/README.md whenever a graduate file lands on main. # The files were validated before merging and are only parsed, never run. # -# The graduate bot merges with GITHUB_TOKEN, and GitHub doesn't start new -# workflows from pushes made with that token, so the push trigger alone would -# miss every bot merge. workflow_run fires after "Validate graduate" finishes. +# A maintainer merges graduate PRs, so the push trigger catches them. +# workflow_run (after "Validate graduate") also keeps working if a merge is +# ever made with GITHUB_TOKEN, whose pushes don't start new workflows. on: push: diff --git a/CURRICULUM.md b/CURRICULUM.md index 5b67fec..bbc7d9f 100644 --- a/CURRICULUM.md +++ b/CURRICULUM.md @@ -39,7 +39,7 @@ Each long video also gets one 60-second clip for Shorts/Reels. | # | Lesson | Hands-on | Status | |---|---|---|---| | 01 | [What counts as a contribution](lessons/01-what-counts/) | Pick the kind of contribution you'll make first | Drafted | -| 02 | [Star, fork, and your first commit, in the browser](lessons/02-first-pr-in-browser/) | Add `first-commits/YOU.py` to this repo; the bot merges it | Drafted | +| 02 | [Star, fork, and your first commit, in the browser](lessons/02-first-pr-in-browser/) | Add `first-commits/YOU.py` to this repo; the bot checks it and a maintainer merges it | Drafted | ## Part 2: Real tools diff --git a/README.md b/README.md index 9a811a3..5edc47a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A free video course that takes you from "I've never opened a pull request" to a merged contribution to a real Python project. - **Lesson 02 needs no install.** You open your first pull request in the - browser and a bot merges it within minutes. + browser. A bot checks it within minutes and a maintainer merges it. - **Then the real tools:** git, GitHub CLI, virtualenvs, pytest, ruff, pre-commit — the things maintainers will actually check. - **Then a real project:** finding an issue nobody else is working on, @@ -16,7 +16,7 @@ to a merged contribution to a real Python project. The hands-on exercises happen right here: in Lesson 02 you star and fork this repo, then add your own file to [`first-commits/`](first-commits/) as -your first commit. A bot checks it and merges it. +your first commit. A bot checks it, then a maintainer reviews and merges it. ## How this course is made diff --git a/first-commits/README.md b/first-commits/README.md index 75256c2..5e2e307 100644 --- a/first-commits/README.md +++ b/first-commits/README.md @@ -10,4 +10,4 @@ message = "Why you're learning Python" ``` A bot checks your file with Python's parser (it never runs it), comments on -your pull request, and merges it if everything's right. +your pull request. If everything's right, a maintainer reviews and merges it. diff --git a/lessons/02-first-pr-in-browser/README.md b/lessons/02-first-pr-in-browser/README.md index b13ddd9..cfe9542 100644 --- a/lessons/02-first-pr-in-browser/README.md +++ b/lessons/02-first-pr-in-browser/README.md @@ -71,8 +71,9 @@ Within a minute or two: - A check called **Validate first commit** runs. Scroll down on your PR to see it. -- If your file is right, the bot comments 🎉 and **merges your PR**. The - purple **Merged** badge means your commit is now part of the project. +- If your file is right, the bot comments 🎉, and a **maintainer reviews + and merges your PR**, usually within a day. The purple **Merged** badge + means your commit is now part of the project. - If something's wrong, the bot comments with exactly what to fix. Fix it in your fork (open your file, click the ✏️ pencil, commit). Your PR updates automatically and the check runs again. diff --git a/lessons/02-first-pr-in-browser/exercise.md b/lessons/02-first-pr-in-browser/exercise.md index bf79729..e12807b 100644 --- a/lessons/02-first-pr-in-browser/exercise.md +++ b/lessons/02-first-pr-in-browser/exercise.md @@ -12,7 +12,7 @@ - [ ] Open a pull request to `thejesh23/first-python-contribution` - [ ] Wait for the **Validate first commit** check and the bot's comment -- [ ] See the purple **Merged** badge +- [ ] See the purple **Merged** badge once a maintainer merges it **Stuck?** Read the bot's comment first: it names the problem. Then check the "Common problems" table in the [lesson](README.md). Still stuck? diff --git a/lessons/02-first-pr-in-browser/script.md b/lessons/02-first-pr-in-browser/script.md index 32da337..2d4fabf 100644 --- a/lessons/02-first-pr-in-browser/script.md +++ b/lessons/02-first-pr-in-browser/script.md @@ -131,7 +131,7 @@ highlight: 56,99,260,36 ## Scene 9: The bot visual: browser url: https://github.com/thejesh23/first-python-contribution/pull/1 -caption: The bot explains what to fix, then merges when it's right +caption: The bot explains what to fix, then hands over to a maintainer image: captures/bot-merges.png height: 2400 crop: 100,580,900,600 @@ -140,8 +140,9 @@ crop: 100,580,900,600 > runs. It reads your file with Python's own parser, the same way Python > reads your code before running it. -> If your file is right, the bot comments, and merges your pull request. If -> something is wrong, the bot tells you exactly what to fix. Fix it in your +> If your file is right, the bot says so, and a maintainer reviews and +> merges your pull request. If something is wrong, the bot tells you +> exactly what to fix. Fix it in your > fork, and commit. Your pull request updates automatically, and the check > runs again. @@ -157,10 +158,12 @@ bullets: - Automated checks - Merge -> See the purple Merged badge? Your commit is now part of a public project. +> When the maintainer merges it, you get the purple Merged badge. Your +> commit is now part of a public project. > And that is the same workflow behind every open source contribution. Fork, > commit, pull request, automated checks, merge. -> In real projects, a human reviews it too, and the checks run real tests. -> You'll do both later in this course. Next, we set up your own machine. +> Real projects work the same way: the checks run first, then a human +> reviews and merges. Their checks also run real tests. You'll write some +> later in this course. Next, we set up your own machine. diff --git a/lessons/05-second-pr-from-terminal/README.md b/lessons/05-second-pr-from-terminal/README.md index 7a5b44a..08c0e5f 100644 --- a/lessons/05-second-pr-from-terminal/README.md +++ b/lessons/05-second-pr-from-terminal/README.md @@ -191,8 +191,8 @@ like Steps 5 and 6. When it finishes, a separate review bot checks your file names and that your code only contains what it should. It doesn't appear in the checks list: -about a minute later it **comments** on your PR, and if everything passed, it -merges. +about a minute later it **comments** on your PR. If everything passed, a +maintainer reviews your PR and merges it. Read the bot's comment with: diff --git a/lessons/05-second-pr-from-terminal/script.md b/lessons/05-second-pr-from-terminal/script.md index cc33086..8a92a55 100644 --- a/lessons/05-second-pr-from-terminal/script.md +++ b/lessons/05-second-pr-from-terminal/script.md @@ -332,7 +332,7 @@ focus: 1 | 2 | 3 notes: - Watch the check run, live - The check runs `ruff format --check`, `ruff check` and `pytest` -- Then the review bot comments, and merges +- Then the review bot comments, and a maintainer merges code: ``` (.venv) $ gh pr checks --watch @@ -347,8 +347,8 @@ code: > {pytest|pie test} on your code. The same three commands you just ran. > After it passes, a review bot looks at your file names and your code. About -> a minute later, it leaves a comment. If everything passed, it merges your -> pull request. Read the comment with {gh pr view --comments|g h, p r, view, +> a minute later, it leaves a comment. If everything passed, a maintainer +> reviews and merges your pull request. Read the comment with {gh pr view --comments|g h, p r, view, > dash dash comments}. ## Scene 16: When a test fails diff --git a/lessons/13-capstone/README.md b/lessons/13-capstone/README.md index f23dfef..1d86304 100644 --- a/lessons/13-capstone/README.md +++ b/lessons/13-capstone/README.md @@ -93,8 +93,8 @@ Once your PR is merged, in **this course repo**: The **Validate graduate** bot looks up your PR on GitHub and checks it's merged, yours, merged by someone else, and in a real project you don't own. -If everything checks out, it comments 🎓, merges, and you appear on the -[graduates wall](../../graduates/). If not, its comment says exactly what's +If everything checks out, it comments 🎓, and once a maintainer merges it you +appear on the [graduates wall](../../graduates/). If not, its comment says exactly what's wrong. Contributed somewhere other than GitHub (GitLab, Codeberg, a mailing list)? diff --git a/practice/README.md b/practice/README.md index e28d9f3..a4317c3 100644 --- a/practice/README.md +++ b/practice/README.md @@ -28,7 +28,7 @@ ruff format practice ruff check practice ``` -When your pull request's tests pass, a bot merges it. +When your pull request's tests pass, a bot comments, and a maintainer reviews and merges it. **Rules for your greeting** (checked by `tests/test_all_greetings.py` and the bot): diff --git a/publishing/udemy-landing.md b/publishing/udemy-landing.md index 885ac41..af31c4c 100644 --- a/publishing/udemy-landing.md +++ b/publishing/udemy-landing.md @@ -17,7 +17,7 @@ From never opening a pull request to a merged contribution: git, GitHub, pytest, Never opened a pull request? This course takes you from zero to a merged contribution in a real open source Python project, one small, practical step at a time. -You start with a win in the first 15 minutes: you star and fork the course's GitHub repository and make your first commit, entirely in the browser. A bot checks your work and merges it within minutes. Then you set up the real tools (git, the GitHub CLI and Python), learn just enough git to never feel lost, and open a second pull request from the terminal with a Python function and its test. That one has to pass CI before it's merged. +You start with a win in the first 15 minutes: you star and fork the course's GitHub repository and make your first commit, entirely in the browser. A bot checks your work within minutes, and a maintainer merges it. Then you set up the real tools (git, the GitHub CLI and Python), learn just enough git to never feel lost, and open a second pull request from the terminal with a Python function and its test. That one has to pass CI before it's merged. Then you go out into the real world. You learn the house rules every project has (CONTRIBUTING files, Contributor License Agreements, DCO sign-offs and AI policies), how to set up any Python project whatever tools it uses, how to find an issue nobody else is working on, and how to make a change maintainers want to merge. You practise rebasing, merge conflicts and code review in a safe lab on your own computer, and you learn how to use AI tools honestly and well. diff --git a/tests/test_check_exercise_2.py b/tests/test_check_exercise_2.py index 35c4e94..e90f055 100644 --- a/tests/test_check_exercise_2.py +++ b/tests/test_check_exercise_2.py @@ -96,9 +96,9 @@ def test_pytest_import_allowed(): def test_comment_success_and_failure(): from check_first_commit import Result - assert "Merging" in format_comment(Result(), "ada", "success", "u") + assert "A maintainer will review" in format_comment(Result(), "ada", "success", "u") failed = format_comment(Result(), "ada", "failure", "https://run") - assert "https://run" in failed and "Merging" not in failed + assert "https://run" in failed and "maintainer will review" not in failed def test_validate_against_real_git(tmp_path, monkeypatch): diff --git a/tests/test_congrats.py b/tests/test_congrats.py deleted file mode 100644 index 07cc9e6..0000000 --- a/tests/test_congrats.py +++ /dev/null @@ -1,27 +0,0 @@ -"""The maintainer congratulation messages the bot workflows post.""" - -import re -from pathlib import Path - -ROOT = Path(__file__).resolve().parent.parent -WORKFLOWS = ["first-commit.yml", "exercise-2-merge.yml"] - - -def test_each_workflow_posts_an_existing_message_before_merging(): - for name in WORKFLOWS: - text = (ROOT / ".github" / "workflows" / name).read_text(encoding="utf-8") - files = re.findall(r"\.github/congrats/([\w-]+\.md)", text) - assert files, f"{name} posts no congratulation" - for file in files: - message = (ROOT / ".github" / "congrats" / file).read_text(encoding="utf-8") - assert "@{login}" in message, f"{file} should greet the learner" - assert text.index("Congratulate from the maintainer") < text.index("- name: Merge") - assert "secrets.MAINTAINER_TOKEN" in text - token_step = text[text.index("Congratulate from the maintainer") : text.index("- name: Merge")] - assert "python" not in token_step, "the token step must not run tools a previous step installed" - - -def test_every_action_is_pinned_to_a_commit(): - for path in (ROOT / ".github" / "workflows").glob("*.yml"): - for ref in re.findall(r"uses: \S+@(\S+)", path.read_text(encoding="utf-8")): - assert re.fullmatch(r"[0-9a-f]{40}", ref), f"{path.name}: pin {ref} to a commit SHA" diff --git a/tests/test_workflows.py b/tests/test_workflows.py new file mode 100644 index 0000000..611c2d5 --- /dev/null +++ b/tests/test_workflows.py @@ -0,0 +1,22 @@ +"""Guards for the GitHub Actions workflows.""" + +import re +from pathlib import Path + +WORKFLOWS = Path(__file__).resolve().parent.parent / ".github" / "workflows" +BOTS = ["first-commit.yml", "exercise-2-merge.yml", "graduate.yml"] + + +def test_bots_only_check_and_comment(): + """The bots never merge: a maintainer reviews and merges every learner PR.""" + for name in BOTS: + text = (WORKFLOWS / name).read_text(encoding="utf-8") + assert "gh pr merge" not in text, f"{name} must not merge" + assert "contents: read" in text and "contents: write" not in text, f"{name} needs no write access to code" + assert "gh pr comment" in text + + +def test_every_action_is_pinned_to_a_commit(): + for path in WORKFLOWS.glob("*.yml"): + for ref in re.findall(r"uses: \S+@(\S+)", path.read_text(encoding="utf-8")): + assert re.fullmatch(r"[0-9a-f]{40}", ref), f"{path.name}: pin {ref} to a commit SHA" diff --git a/tools/check_exercise_2.py b/tools/check_exercise_2.py index 88d8389..87b9822 100644 --- a/tools/check_exercise_2.py +++ b/tools/check_exercise_2.py @@ -14,7 +14,7 @@ python tools/check_exercise_2.py --login LOGIN --base BASE --head HEAD --tests success --run-url URL -Prints a Markdown comment and exits 0 only if the PR can be merged. Exits 3, +Prints a Markdown comment and exits 0 only if the PR is ready for a maintainer to merge. Exits 3, printing nothing, when the PR isn't a learner's Exercise 2 PR at all (for example a maintainer changing the course), so the bot stays quiet. """ @@ -212,9 +212,10 @@ def format_comment(result: Result, login: str, tests: str, run_url: str) -> str: }.get(tests, f"⚠️ The test run finished with `{tests}`. [Open it]({run_url}) to see why.") if result.ok and tests == "success": return ( - f"🎉 Nice work, @{login}! {tests_line} Merging this now.\n\n" + f"🎉 Nice work, @{login}! {tests_line} A maintainer will review your pull " + "request and merge it soon.\n\n" "You just did what real Python contributors do every day: write code, test it, " - "pass CI, get merged. Next up: Lesson 06, the house rules every project has." + "pass CI and ask for review. Next up: Lesson 06, the house rules every project has." ) parts = [f"Thanks, @{login}! Not quite there yet:\n", tests_line] if result.errors: diff --git a/tools/check_first_commit.py b/tools/check_first_commit.py index 729b3a5..8f9aa05 100644 --- a/tools/check_first_commit.py +++ b/tools/check_first_commit.py @@ -162,10 +162,11 @@ def check_source(source: str, login: str) -> Result: def format_comment(result: Result, login: str) -> str: if result.ok: return ( - f"🎉 Looks great, @{login}! Your file passed every check, so this pull " - "request will be merged automatically in a moment.\n\n" - "That purple **Merged** badge means your commit is now part of a public " - "project. Next up: Lesson 03, setting up git on your own machine." + f"🎉 Looks great, @{login}! Your file passed every check. A maintainer " + "will review your pull request and merge it soon.\n\n" + "When it's merged, you'll see the purple **Merged** badge: your commit is " + "then part of a public project. Next up: Lesson 03, setting up git on your " + "own machine." ) lines = "\n".join(f"- {e}" for e in result.errors) return ( diff --git a/tools/check_graduate.py b/tools/check_graduate.py index 51092d6..e4c23c7 100644 --- a/tools/check_graduate.py +++ b/tools/check_graduate.py @@ -180,7 +180,8 @@ def format_comment(result: Result, login: str) -> str: if result.ok: return ( f"🎓 Congratulations, @{login}! Your merged contribution checks out, so you're graduating. " - "This pull request will be merged and you'll appear on the graduates wall.\n\n" + "A maintainer will review this pull request, and once it's merged you'll appear " + "on the graduates wall.\n\n" "You can contribute to any open source project now. Keep going, and pass it on: " "the best thing a graduate can do is help the next beginner." )