Building it · lesson 10 of 10
Ideas in this lesson
ABranchfrom lesson 5.4
Btake_number()the feature itself
CPull request and reviewfrom lesson 5.5
DDocstring and READMEfrom lesson 5.8

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.

Step 2 code queue_rules.py
Edit the code, then run it again

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):

Terminal
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.

ruff format changed the layout of your file. Do you need to re-check that take_number still works?

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.

Git sandbox
  1. Make a branch take-number
  2. Add take_number to queue_rules.py and commit it
  3. Push the branch and open a pull request with a clear title
  4. Answer Marco’s review in a second commit (add the docstring), and push it
  5. When Marco approves, merge the pull request
  6. 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

  1. 9e5dd29 HEAD →mainorigin/main Add the queue rules constants
  2. 389ecdd Start 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.

Comment 1: “take_number needs a docstring: callers must know it returns None when closed or full.” How do you answer?
Comment 2: “Why < CLOSES and not <=?” Your code is right: the centre closes at 17:00, so 17:00 is closed. How do you answer?
Comment 3: “Nit: README could mention numbers restart each day.” You agree, but the README is about to be rewritten in another pull request. How do you answer?

Spot the trap: merging first

Spot the trapMarco

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

A reviewer asks for a change on your open pull request. How do you add it?
Which order matches the team’s flow?

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.

All sources for Simple Software Development