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
13 changes: 0 additions & 13 deletions .github/congrats/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions .github/congrats/exercise-2.md

This file was deleted.

5 changes: 0 additions & 5 deletions .github/congrats/first-commit.md

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
31 changes: 3 additions & 28 deletions .github/workflows/exercise-2-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -11,7 +12,7 @@ on:
types: [completed]

permissions:
contents: write
contents: read
pull-requests: write

jobs:
Expand Down Expand Up @@ -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
31 changes: 3 additions & 28 deletions .github/workflows/first-commit.yml
Original file line number Diff line number Diff line change
@@ -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/<name>.py (status 3) get no comment.
Expand All @@ -13,7 +14,7 @@ on:
paths: ["first-commits/**"]

permissions:
contents: write
contents: read
pull-requests: write

concurrency:
Expand Down Expand Up @@ -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
13 changes: 3 additions & 10 deletions .github/workflows/graduate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/<login>.py with git show +
# ast.parse, and looks up the linked PR with the GitHub API (read-only).
# PRs that don't touch graduates/<name>.py (status 3) get no comment.
# PRs that don't touch graduates/<name>.py (status 3) get no comment. The bot
# only checks and comments; a maintainer reviews and merges.

on:
pull_request_target:
Expand All @@ -12,7 +13,7 @@ on:
paths: ["graduates/**"]

permissions:
contents: write
contents: read
pull-requests: write

concurrency:
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions .github/workflows/graduates-wall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion CURRICULUM.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion first-commits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 3 additions & 2 deletions lessons/02-first-pr-in-browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lessons/02-first-pr-in-browser/exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
15 changes: 9 additions & 6 deletions lessons/02-first-pr-in-browser/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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.
4 changes: 2 additions & 2 deletions lessons/05-second-pr-from-terminal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
6 changes: 3 additions & 3 deletions lessons/05-second-pr-from-terminal/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lessons/13-capstone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down
2 changes: 1 addition & 1 deletion practice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
2 changes: 1 addition & 1 deletion publishing/udemy-landing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions tests/test_check_exercise_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
27 changes: 0 additions & 27 deletions tests/test_congrats.py

This file was deleted.

22 changes: 22 additions & 0 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
@@ -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"
Loading
Loading