Read Anthropic’s case study about Graphite Reviewer

Using GitHub for enterprise-level code reviews

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite

GitHub is a powerful tool for managing code reviews at an enterprise scale, offering a variety of features to help teams handle large and complex projects with many contributors. With tools like branch protection rules, CODEOWNERS, and integrations such as Graphite's PR inbox, GitHub simplifies and optimizes code review workflows, making it easier to enforce best practices, maintain code quality, and scale reviews across multiple teams and repositories.

The CODEOWNERS file in GitHub automatically assigns reviewers based on the paths of files or directories within your project. This is especially useful for large teams with diverse expertise, as it allows you to define who is responsible for reviewing specific parts of the codebase.

  • Why use CODEOWNERS?
    • Streamlines the review process: When a PR modifies a file, the designated code owners are automatically requested for a review, ensuring that the right people are reviewing the right code.
    • Increases accountability: By assigning ownership, team members know exactly which parts of the codebase they are responsible for reviewing.

Save this file in your repository under .github/CODEOWNERS, and it will automatically enforce the review assignments based on the file paths.

GitHub Enterprise offers several advanced tools to help manage enterprise-level code reviews effectively. By leveraging these tools, you can ensure your team follows best practices while improving code quality across multiple projects.

GitHub's branch protection rules can be customized to require a certain number of approvals before merging a PR. This ensures that changes are thoroughly reviewed by multiple people before they are added to important branches.

Branch protection rules in GitHub are an important part of maintaining high-quality code in an enterprise environment. These rules ensure that critical branches, like main or develop, are protected from direct pushes and require thorough reviews before merging. They also enforce additional checks, such as running tests or linting, before allowing changes to be merged.

By configuring these rules, you ensure that:

  • Code reviews are mandatory before merging any changes.
  • Automated checks (e.g., build passes, tests) must be completed successfully before merging.
  • Approval thresholds can be set to require a certain number of reviewers.
  1. Navigate to repository settings: Go to your repository's "Settings" tab.
  2. Select "Branches": In the left-hand sidebar, click on "Branches."
  3. Add a branch protection rule: Click "Add rule" under the "Branch protection rules" section.

screenshot of adding a branch protection rule

  1. Specify the branch name pattern: For example, you might apply the rule to main or develop to ensure those important branches are protected.
  2. Enable required reviews: Check the box for "Require pull request reviews before merging."
  3. Enable status checks: Select "Require status checks to pass before merging" and choose the relevant checks, such as tests or linting.

This ensures that all code changes undergo a rigorous review process, reducing the risk of bugs or issues being introduced into your critical branches.

GitHub Enterprise insights provide valuable metrics to monitor and improve the review process. These insights can help you track key metrics such as:

  • Review times: Measure how long it takes for a PR to be reviewed and merged.
  • Approval rates: Track how quickly PRs get approved across teams.
  • Contributor activity: Understand which contributors are actively reviewing and how many PRs they handle.

You can also view similar metrics in Graphite Insights, such as:

  • Total PRs merged
  • Average number of PRs merged per person
  • Average number of PRs reviewed per person
  • Median publish to merge time
  • Median review response time
  • Median wait time to first review
  • Average number of review cycles until merge

These kinds metrics help identify bottlenecks, whether due to delays in approvals or lack of active reviewers, allowing teams to optimize their code review cycles.

Large-scale codebases often require careful management to ensure that PRs are efficiently reviewed without overwhelming individual team members.

  • Break large repositories into modules: Use GitHub submodules or a monorepo approach to split code into logical units, making it easier to review changes in smaller, isolated sections.
  • Use labels to categorize PRs: Labels like backend, frontend, or high-priority can be used to notify specific teams about the relevant PRs, ensuring the right people are reviewing the right changes.

For enterprise teams handling a large number of pull requests (PRs), the Graphite PR inbox also provides a powerful way to stay organized and prioritize reviews. It works similarly to an email inbox but for PRs, helping teams track which PRs need attention, which are approved, and which are pending changes.

Graphite divides PRs into several default sections, allowing you to organize them based on status:

  • Needs your review: Displays PRs that require your review and action.
  • Approved: Shows PRs you have reviewed and approved, ready for merging.
  • Returned to you: Lists PRs that have been sent back to you for further modifications after your review.
  • Merging and recently merged: Tracks PRs in the process of merging or recently merged.

In addition to these default sections, you can create custom sections using filters to group PRs by other criteria, such as:

  • PRs authored by a specific team member
  • High-priority reviews
  • PRs from certain repositories
  1. Click on "Add new section" in the PR inbox.
  2. Choose filters, such as repository names, labels, or PR statuses, to define which PRs should appear in that section.
  3. After creating a section, you can reorder them by dragging and dropping, making it easy to keep the most important sections at the top.

screenshot of adding a section in the PR inbox

You can share the configuration of your PR inbox with other team members to ensure everyone is on the same page regarding which PRs they need to review. This is especially useful for maintaining consistent workflows across large teams or departments.

  • How to share configurations:
    • After creating a section, click the gear icon and select "Share filters."
    • This generates a link that can be shared with your team. They can click it to automatically apply the same filter settings to their inbox.

For large enterprises managing multiple repositories, Graphite allows you to select up to 30 repositories as "default repositories" for your PR inbox. This provides a centralized location to view and manage PRs from across your entire organization, regardless of which repository they belong to. This feature is particularly helpful when dealing with a large number of repositories and helps avoid the fragmentation that can occur when managing PRs across multiple separate projects.

One of the most powerful features for large-scale code reviews is Graphite's stacked PR capabilities. This approach involves breaking a large feature into smaller, manageable PRs that depend on each other, rather than one large PR.

  • Benefits of stacked PRs:
    • Easier to review: Smaller changes are more digestible and can be reviewed faster.
    • Reduced complexity: Dependencies are clearly defined, and the review process is more focused.
    • Faster delivery: Teams can ship smaller, well-reviewed changes more quickly.

For example, instead of submitting a huge PR that encompasses an entire feature, break it down into multiple smaller, related PRs. Each PR in the stack builds on the previous one, making it easier to spot problems early in the process.

By combining GitHub's enterprise features with the organizational capabilities of Graphite's PR inbox, enterprise teams can streamline their code review process, ensure consistency across teams, and maintain high standards of code quality.

Built for the world's fastest engineering teams, now available for everyone