Task 3: Pull Requests and the Approver
In this task main stops taking changes directly: a change reaches it only through a pull request that passes its
checks and has an approval.
- The approver is
pr-reviewer, the GitHub App from the Git Collaboration course: a stand-in for a senior team member.- On a real team, a person reads every pull request, and approves only a change they judge right.
pr-reviewernever reads the code: it requests changes once, waits for a push, then approves, so you practise the round of a review.
- In a pair, the other student approves as well: either approval is enough to merge, and the author's own never counts.
Give pr-reviewer access to the repository
A GitHub App is installed on your account, and works only in the repositories you give it: give it devops-project,
and nothing else.
Already installed, from the Git Collaboration course
- Your avatar → Settings → Applications → Installed GitHub Apps → Configure beside
yuval-pr-trainer, the app's name on GitHub. - Under Repository access, keep Only select repositories, add
devops-project, and save. - The permissions are the ones you granted in the course: nothing to change.
Not installed yet
- Open the app's
install page: GitHub names it
yuval-pr-trainer. - Choose Only select repositories, and pick
devops-project. - Grant both permissions:
- Pull requests: Read & write: it submits the review;
- Contents: Read & write: without it, branch protection does not count its approval.
- In a pair, the repository's owner does this: the app is installed on the owner's account.
Add the reviewer's configuration
The app reads its instructions from .github/reviewer.yml, and only from main.
Copy the file from
team-repinto your repository:1$ mkdir -p .github 2$ curl -fsSL -o .github/reviewer.yml https://raw.githubusercontent.com/YuvalShaul/team-rep/main/.github/reviewer.ymlIts settings, under comments explaining each:
1rounds: 1 2merge: neverrounds: 1: it requests changes once, and approves on the next push.merge: never: the merge button stays yours.
Commit it, and push it to
main:1$ git add .github/reviewer.yml 2$ git commit -m "Configure pr-reviewer" 3$ git push
- Do it before you protect
main: afterwards the file reachesmainonly through a pull request, reviewed by an app with no configuration. - A pull request that edits the file changes nothing until it merges: the rules it is judged by come from
main.
Protect main
A branch protection rule on main, the classic kind the
Git Collaboration
course sets up in its Branch protection chapter. GitHub's newer rulesets do the same job on another screen;
use the classic rule, since you know its page.
- Settings → Branches → Add branch protection rule, branch name pattern
main. - The course's three settings:
- Require a pull request before merging;
- Require approvals: 1, under it;
- Do not allow bypassing the above settings: without it you, the owner, are an admin, and admins are exempt.
- Two settings the course did not need, because it had no pipeline:
- Require status checks to pass before merging, and pick the jobs of
pr.ymlby name:lint,unit-tests,integration-tests,security,image-build. - Require branches to be up to date before merging: the pull request's checks then ran on the code that
lands on
main, so the merge workflow need not test it again.
- Require status checks to pass before merging, and pick the jobs of
- Save changes.
- A check is in the list only after it has run once: the pull request you opened in Task 2 is what put them there.
- A check's name is its job's name. A matrix job adds its value,
unit-tests (3.13), and each of those is a check of its own to require. - A required check that never runs blocks the merge forever. If a later task gives
pr.ymlapaths:filter, a pull request changing only the README waits for checks that never start. - Force pushes to
mainare blocked by the rule as it is: it allows them only when you tick the box that does.
Push to main, and read the refusal
- A direct
git pushtomainis refused. TODO: the error text.
Open a pull request, and wait for the approver
The checks run, the merge button stays blocked.
pr-reviewerrequests changes. Answer with a commit, an empty one if nothing needs changing, and push it:1$ git commit --allow-empty -m "Answer the review" 2$ git pushpr-reviewerapproves, and the merge button works.Merge: the merge workflow runs.
The empty pipeline is now complete: every event runs its jobs, and the gate holds.