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 has an approval.

  • The approver is pr-reviewer, a GitHub App written for this site's courses: 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-reviewer never 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.

Install pr-reviewer on the repository

A GitHub App works only where it is installed: on an account, in the repositories picked for it. Install pr-reviewer on your account, for devops-project alone.

  1. Open the app's install page: GitHub names it yuval-pr-trainer.
  2. Choose Only select repositories, and pick devops-project.
  3. The page lists the two permissions the app asks for:
    • Pull requests: Read & write: it submits the review;
    • Contents: Read & write: without it, branch protection does not count its approval.
  4. Install.
  • In a pair, the repository's owner does this: the app is installed on the owner's account.
Already installed, from the Git Collaboration course
  • On the install page, choose Configure beside your account: it opens the existing installation.
  • Under Repository access, keep Only select repositories, add devops-project, and save.

Add the reviewer's configuration

The app reads its instructions from .github/reviewer.yml, and only from main.

  1. Copy the file from team-rep into your repository:

    1$ mkdir -p .github
    2$ curl -fsSL -o .github/reviewer.yml https://raw.githubusercontent.com/YuvalShaul/team-rep/main/.github/reviewer.yml
    

    Its settings, under comments explaining each:

    1rounds: 1
    2merge: never
    
    • rounds: 1: it requests changes once, and approves on the next push.
    • merge: never: the merge button stays yours.
  2. 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 reaches main only 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, GitHub's classic kind. The newer rulesets do the same job on another screen; this project uses the classic rule.

  1. Settings → Branches → Add branch protection rule, branch name pattern main.
  2. 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.
  3. Save changes.
  • The checks are not required yet: pr.yml runs on every pull request, but the merge waits only for the approval. Its jobs still print placeholders, so requiring them would prove nothing; Task 8 makes them required.
  • Force pushes to main are 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 push to main is refused. TODO: the error text.

Open a pull request, and wait for the approver

  • pr.yml runs, its checks appear on the pull request, and the merge button stays blocked: it waits for the approval.

  • pr-reviewer requests 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 push
    
  • pr-reviewer approves, and the merge button works.

  • Merge: the merge workflow runs.

The empty pipeline is now complete: every event runs its jobs, and the approval gates the merge.

Translations: