Lesson 3 of 4 Branching Strategies

Designing Pull Request Workflows

This lesson explains how branch policies, protection rules and code owners shape review.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify the available Azure Repos branch policies.
  • Explain why build validation is needed in Azure Repos.
  • Write a CODEOWNERS file.
  • Map equivalent settings between platforms.

What a pull request workflow should achieve

A pull request asks to merge one branch into another, but its real purpose is to provide a controlled checkpoint. A well-designed workflow makes sure that someone else has read the change, that automated checks have passed, and that the change is linked to a reason. It should do this quickly, because a slow review is one of the largest delays in most teams.

The settings that enforce a workflow live on the target branch. Azure Repos calls them branch policies, whereas GitHub has branch protection rules and rulesets.

Branch policies in Azure Repos

Branch policies are set on a branch, or on a pattern such as release/*. Each of the following can be required.

  • Require a minimum number of reviewers. Options control whether authors may approve their own changes, and whether new pushes reset votes.
  • Check for linked work items, which supports traceability.
  • Check for comment resolution, so that all comments are resolved before completion.
  • Limit merge types, which controls the shape of history.
  • Build validation, which queues a pipeline for the pull request and requires it to pass. A build can expire after a time, or when main changes.
  • Status checks, which require a pass from an external service through the Pull Request Status API.
  • Automatically included reviewers, which add reviewers according to the changed paths, as either required or optional.

Build validation deserves particular attention. Azure Repos ignores the pr keyword in a YAML pipeline, so a pipeline runs for pull requests only when a build validation policy references it. This is a frequent exam point. Path filters on a build policy let a monorepo run only the relevant pipeline.

Troubleshooting

Pull request policies that misbehave

Exam skills 2.1.2

Find the fix for each Azure Repos pull request problem.

Log in to try this activity Interactive activities are free with an account.

Branch protection and code owners in GitHub

A branch protection rule can require a pull request before merging, a number of approvals, dismissal of stale approvals after new commits, approval of the most recent push by someone else, status checks to pass, conversation resolution and signed commits.

A CODEOWNERS file, stored in the root, docs/ or .github/, maps paths to owners. When review from code owners is required, an owner of each changed path must approve. The last matching line wins, so general rules come first.

# Default owners for everything
*                     @contoso/platform

# Infrastructure changes need the cloud team
/infra/               @contoso/cloud-team

# Pipelines need DevOps review
/.github/workflows/   @contoso/devops

A required status check names a check from a workflow, or from an external service such as Azure Pipelines. If a workflow does not run for a pull request, for example because of a path filter, the required check can stay pending and block the merge. This is a classic trap to consider when combining path filters with required checks.

The following diagram shows which of two branch policies on main apply to two kinds of pull request.

Two branch policies on main. Build validation runs for every pull request; an automatically included reviewers policy with the path filter /pipelines/* adds the security group as required reviewers only when pipeline YAML changes, so security never reviews application code alone.
The scenario is illustrative.
Scenario questions

CODEOWNERS and required checks

Exam skills 2.1.2

Apply CODEOWNERS and branch protection rules to GitHub scenarios.

Log in to try this activity Interactive activities are free with an account.

Designing for speed and safety

Too few controls allow defects through, and too many slow everyone down. A sensible default is one or two required reviewers, automated checks that finish in minutes, and path-based owners for sensitive areas, rather than a general rule requiring senior approval for all changes. Draft pull requests let authors share work early, without requesting formal review. Azure Repos supports auto-complete, and GitHub supports auto-merge, so a change completes by itself when all conditions pass.

The following table recaps the equivalent settings.

RequirementAzure ReposGitHub
Mandatory reviewersMinimum number of reviewersRequired approvals
Reviewers by pathAutomatically included reviewersCODEOWNERS
Pipeline must passBuild validationRequired status check
Comments addressedCheck for comment resolutionRequire conversation resolution
Work item requiredCheck for linked work itemsNo direct equivalent; a check can enforce it
Complete when readyAuto-completeAuto-merge
Match the pairs

Equivalent settings on each platform

Exam skills 2.1.2

Match each Azure Repos branch policy with its GitHub equivalent.

Log in to try this activity Interactive activities are free with an account.
Worked example

Protecting sensitive paths

An Azure Repos repository holds application code and pipeline YAML in a /pipelines folder. The security team must approve all pipeline changes, but must not be asked to review application code. Each pull request must also pass a build. What should you configure on main?

You should add an automatically included reviewers policy with the path filter /pipelines/* and the security group set as required, together with a build validation policy. The path filter means that the security team is added only when those files change. Raising the minimum number of reviewers would not ensure that the security team reviews the right files. A separate repository would add work and is not needed to meet the requirement.

Check yourself

In a CODEOWNERS file, two patterns match a changed file. Which applies?

Show answer

The last matching line. General rules should therefore come first, and specific ones later.

Exam Tips

Remember for the exam

  • Azure Repos ignores the pr YAML keyword; use build validation.
  • Automatically included reviewers and CODEOWNERS both assign reviewers by path.
  • In CODEOWNERS, the last matching line wins.
  • A required check skipped by a path filter can block a merge.
  • Dismiss stale approvals, or reset votes, so that new pushes are reviewed.