Pila: the first feature
Last updated
Everything in Stage 5 comes together in one real change. You'll build Pila's most important feature, giving a patient a number, the way the team works: on a branch, checked by running it, tidied by the tools, documented, proposed in a pull request, reviewed by Marco, and merged only when his review is answered.
By the end of this lesson you can
- Build a small feature to its acceptance criteria, and check it by running it
- Take a change from branch to merge through a pull request and a review
- Answer review comments with changes or reasons
What you’re making
The story, from lesson 3.P: As a patient, I want to get a number by text, so that I don't have to line up before dawn. Its acceptance criteria:
- Numbers are given out from 7:00 until the centre closes at 17:00; outside those hours, none.
- Each phone gets one number a day; texting again returns the same number.
- At most 60 numbers a day; after that, none.
Marco has pushed the constants and an empty Queue class. You'll write take_number, check it, and take it all the way to main.
Write take_number
The checks at the bottom run your method in the situations the criteria describe. Make take_number return the right number, or None, until the last line prints checks: True.
Hints, if you want them: compare times with OPENS <= at < CLOSES; look the phone up in self.by_phone; the next number is len(self.by_phone) + 1. Stage 6 turns these prints into real tests that run on every change.
Before you push
Before proposing a change, the team runs the tools from lesson 5.6, and checks the README still tells the truth (lesson 5.8):
ruff format . 1 file reformatted, 2 files left unchanged ruff check . All checks passed! git diff --staged
The last command is the most important: read your own change, line by line, as a reviewer would. Most authors find something.
Branch, push and propose
Now the team's flow, in the sandbox. Type edit queue_rules.py and add your take_number from step 2 (just the method, inside the class; leave out the checks). Then commit, push and open a pull request. When Marco reviews, read his comments on the hosting site; the next step helps you answer them. Answer them with a second commit, push again, and merge once he approves.
- Make a branch
take-number - Add
take_numberto queue_rules.py and commit it - Push the branch and open a pull request with a clear title
- Answer Marco’s review in a second commit (add the docstring), and push it
- When Marco approves, merge the pull request
- Switch to main and pull
Working folder
no changes
Staging area
nothing staged
Repository
2 commits on main
Remote
origin: example.com/pila-team/pila.git · in step, as of your last fetch
You are in ~/pila, your clone of https://example.com/pila-team/pila.git, on main. queue_rules.py has the constants and an empty Queue class.
Commit graph
9e5dd29HEAD →mainorigin/main Add the queue rules constants389ecddStart Pila with a README
On the hosting site: example.com/pila-team/pila
Branches: main
Answer Marco’s review
Marco left three comments. Each needs an answer, either a change or a reason.
Spot the trap: merging first
Your pull request has Marco’s three comments. The demo for Kap. Ernesto is in an hour, and the Merge button works: the team’s branch rules don’t require an approval yet.
What happens if…
Check what you learned
Sources
Every claim on this page comes from these sources: the standard, the founding text of a method, a study, or the official record of a project, from the body that publishes it. Industry reports are labelled as such.
- Google Engineering Practices: The CL author’s guide to getting through code review: writing descriptions, keeping changes small, handling reviewer comments
- Pro Git, 3.2: Basic Branching and Merging: the branch-and-merge flow
- GitHub Docs: About pull requests: proposing, reviewing and merging a change
- PEP 257: Docstring Conventions: the docstring Marco asks for