Monorepo
Optimize merge queue batching for monorepos with scopes.
In monorepo environments, not every pull request affects the entire codebase. Running all tests for every change wastes time and CI resources. Mergify’s scopes feature allows you to intelligently batch pull requests based on which parts of your codebase they modify, dramatically improving merge queue efficiency.
Understanding Scopes
Section titled Understanding ScopesScopes define discrete areas of your monorepo (like packages, services, or components). When a pull request is created, Mergify automatically determines which scopes are affected and uses this information to optimize batching.
Scopes can be determined in several ways depending on your project’s needs:
-
File patterns: Match file paths to identify affected scopes
-
Build system integration: Support for tools like Bazel, Nx, Turborepo, and others that can provide scope information based on dependency graphs and build targets
This flexibility allows you to use the approach that best fits your monorepo’s architecture and existing tooling.
The Batching Challenge in Monorepos
Section titled The Batching Challenge in MonoreposWithout scopes, Mergify batches pull requests together regardless of what they change. This means:
- A Python service change and a JavaScript frontend change might be batched together
- Both sets of tests run even though they’re completely independent
- If one fails, both PRs are affected by the batch split process
With scopes, Mergify can:
- Batch together PRs that affect the same scopes (e.g., multiple Python changes)
- Keep independent changes in separate batches
- Reduce unnecessary CI runs for unrelated parts of your codebase
Configuration Approaches
Section titled Configuration ApproachesChoose the approach that best fits your monorepo setup:
File Patterns
Section titled File PatternsUse simple glob patterns to map file paths to scopes. This approach is straightforward to set up and works well when your monorepo follows clear directory boundaries.
Best for:
- Projects with well-defined directory structure
- Monorepos without complex dependency graphs
Learn more about file patterns →
Monorepo Build Tools
Section titled Monorepo Build ToolsLeverage your existing build tool (Nx, Bazel, Turborepo, etc.) to detect affected projects based on your dependency graph. This approach provides more accurate scope detection by understanding your project’s dependencies.
Best for:
- Projects already using monorepo build tools
- Complex dependency relationships
- Teams wanting transitive dependency detection
Learn more about build tool integrations: