Scopes
Declare the areas of your codebase once, so the merge queue batches by them and Job Selection skips the CI jobs a pull request does not need.
Scopes name the areas of your codebase that a pull request touches. You declare them once, in the
scopes section of .mergify.yml, and every Mergify feature that needs to know what a change
affects reads that declaration:
-
The merge queue batches pull requests that touch the same scopes, and merges one right away when the base branch only moved in scopes it does not touch.
-
Job Selection skips the CI jobs whose scopes a pull request does not touch.
Here’s a quick walkthrough of how we use scopes on Mergify’s own monorepo:
How the merge queue batches by scope
Section titled How the merge queue batches by scopeHow scopes shape a batch depends on the queue mode.
Batching in serial and isolated modes
Section titled Batching in serial and isolated modesMergify prefers the closest match: pull requests that overlap in scope are tested together first, while an unrelated change waits for a later batch unless Mergify needs it to fill the requested batch size.
How Pull Requests Are Grouped Into a Batch covers the full order of precedence, including how priority and stacks come before scopes.
Batching in parallel mode
Section titled Batching in parallel modeIn parallel mode, each scope is one lane, shared by every queue rule:
-
A batch takes the pull requests its scopes cover. Mergify batches together pull requests of one queue rule that carry the same scopes, in queue order, up to
batch_size. A batch with room left also takes waiting pull requests whose scopes are all among its own. Pull requests carrying no scope are batched only with each other. Pull requests of a stack are batched by the scopes of its bottom pull request. -
A batch waits on every scope it carries. It is tested on top of the last batch ahead of it in each of its scopes, from any queue rule, and merges only after them. Outside barriers, a batch that shares no scope with the batches ahead of it is tested and merged on its own.
Pull requests spread over many combinations of scopes form small batches, whatever batch_size
allows.
How parallel mode works covers the rest of the
cycle: how many batches are tested at once, under one max_parallel_checks that every queue rule
shares, and what a failing batch holds back.
Scope assignment lifecycle
Section titled Scope assignment lifecycleA pull request gets its scopes in one of these ways:
-
File pattern detection: Define scopes directly in your configuration and Mergify evaluates them itself, matching each pull request’s changed files against your patterns. No CI job or GitHub Action is required for the queue to batch by scope. See file-pattern scopes for a step-by-step setup.
-
Manual upload: Use the
gha-mergify-ciGitHub Action, themergifyio/mergify-ciBuildkite plugin, the REST API, or themergify ci scopes-sendCLI to push scopes computed by your own tooling. There is a build tool guide for Nx, Bazel, Pants, and Turborepo, plus one for any other build tool. -
Both: declare
manualbesidefiles, and your CI adds scopes to those the patterns match. See Files and manual example.
Limits on an upload
Section titled Limits on an uploadAn upload sent through the REST API or the Mergify CLI has to stay within these limits:
- A scope name is at most 1024 characters.
- A scope name cannot contain a NUL byte or an unpaired UTF-16 surrogate.
- An upload carries at most 10,000 scopes.
An upload that breaks any of them is refused in full with a 422 and nothing is stored, so the
pull request keeps the stale scopes of an earlier run. Cap a generated name’s length in your own
tooling, so an over-long one fails the job that produced it.
Configuration schema
Section titled Configuration schemaDeclare scopes at the top level of your .mergify.yml file:
scopes: source: files: frontend: include: - apps/web/**/* api: include: - services/api/**/*.py docs: include: - docs/**/* merge_queue_scope: merge-queue
queue_rules: - name: default batch_size: 3Top-level keys
Section titled Top-level keys-
scopes.source: selects how scopes are provided.-
files: map scope names to the file patterns that define them. Each entry acceptsincludeand optionalexcludelists of glob patterns. -
manual: instructs Mergify to expect scopes that your CI uploads with thegha-mergify-ciGitHub Action, themergifyio/mergify-ciBuildkite plugin, the Mergify CLI, or the REST API. These are the only scopes a pull request gets, and the queue waits for them. -
filesandmanualtogether: a pull request gets the scopes its files match plus the scopes andall_scopesflag uploaded for its head commit, and the queue waits for that upload. -
null: disables scopes entirely.
-
-
scopes.merge_queue_scope: optional name of the scope reported on a merge queue batch build, so that CI jobs can tell one from an ordinary pull request build (defaults tomerge-queue). It is reported whether or not the queue opened a draft pull request for the batch, and a pull request cannot carry it: the queue drops that name from the scopes a pull request reports for itself. See The merge queue scope. -
scopes.capacities: optional map of scope name to the number of speculative checks that scope may run at the same time, used to limit per-scope concurrency in any mode. See Limiting concurrency per scope. A key holding*,?,[, or{is a glob over scope names, with the syntax of the glob patterns afilessource uses; any other key names one scope exactly. An exact key may be any name the scopes API accepts, whatever the source: a Bazel package label like//lib/core, a scoped package name like@acme/web, or a name your file patterns declare. The source decides which scopes a pull request carries, and any of them can be capped. -
scopes.default_capacity: optional capacity applied to every scope that nocapacitieskey matches, so scope sets that change from one pull request to the next stay bounded without you listing each one. Likecapacities, it applies in any mode. See Capping scopes you did not list. -
scopes.barrier_files: optional file filters marking files that impact every scope. Only valid with afilessource, alone or besidemanual. A pull request that changes a matching file becomes a merge queue barrier. See Declaring a pull request impacts every scope.
Manual source example
Section titled Manual source examplescopes: source: manual:
queue_rules: - name: default batch_size: 5Your CI uploads every scope, usually the projects a build tool such as Bazel, Nx, Pants, or
Turborepo finds affected. It sends them with the scopes-upload action of gha-mergify-ci on
GitHub Actions, or of the mergifyio/mergify-ci plugin on Buildkite. With no file patterns to
match, scope detection (the scopes action) fails the step on a pull request or a push.
Files and manual example
Section titled Files and manual examplescopes: source: files: frontend: include: - apps/web/**/* manual:A pull request gets the scopes its changed files match plus those your CI uploads for its head
commit, such as the projects a build tool finds through dependencies no pattern sees. With
manual declared, the queue waits for the head commit’s upload, so send one for every pull
request, even with nothing to add. On GitHub Actions, give the extra scopes, comma-separated, to
the scopes action, which sends them with the scopes it detects:
- uses: Mergifyio/gha-mergify-ci@v33 with: action: scopes scopes: ${{ steps.affected.outputs.scopes }}The Buildkite plugin takes the same scopes option,
and the Mergify CLI sends them with mergify ci scopes-send;
Marking a barrier on upload says when it needs --head-sha.
Declaring a pull request impacts every scope
Section titled Declaring a pull request impacts every scopeSome pull requests invalidate everything: a build-system configuration change or a shared toolchain bump. Enumerating every scope by hand is brittle, and the list goes stale as soon as your set of scopes changes.
Instead, mark the change as a barrier, a pull request that impacts every scope. Mergify sets an
all_scopes flag on it and serializes the queue around it. With
file-pattern scopes, declare the files that raise it under scopes.barrier_files; with a manual
source, alone or beside files, an upload can set the flag instead.
Barrier files (file-pattern scopes)
Section titled Barrier files (file-pattern scopes)When your scopes come from file patterns, declare the files
that impact every scope under scopes.barrier_files. Whenever a queued pull request changes a
matching file, Mergify flags it with all_scopes and treats it as a barrier, with no CI job or
manual upload required.
scopes: source: files: frontend: include: - apps/web/**/* api: include: - services/api/**/*.py barrier_files: include: - .github/workflows/** - Makefile
queue_rules: - name: default batch_size: 3With this configuration, a pull request that changes .github/workflows/** or Makefile (files
that affect the whole repository) becomes a barrier, whichever scopes it also belongs to.
barrier_files accepts the same include and optional exclude patterns as a scope, and needs at
least one include: an exclude-only filter would match every pull request and silently serialize
the entire queue, so Mergify rejects it.
A renamed file is matched at both of its paths, so moving a file out of a barrier pattern makes the pull request a barrier too: the barrier file is gone from the location you declared.
You can also manage these patterns from the dashboard: the Barrier files editor on the
Scopes page edits the same barrier_files filters.
Marking a barrier on upload
Section titled Marking a barrier on uploadWhen you upload scopes yourself, set the all_scopes flag on the pull request. With the
gha-mergify-ci GitHub Action or the
mergifyio/mergify-ci
Buildkite plugin, set all_scopes: true on the scopes-upload action, or on the scopes action
when your source declares manual beside files. With the Mergify CLI, pass
--all to scopes-send:
mergify ci scopes-send -s build-system --allOn a GitHub Actions pull_request or pull_request_target job, Buildkite, and a Jenkins pull
request build, the CLI reads the pull request
and its head commit from the build. On CircleCI it reads the head commit only: add --pull-request.
Anywhere else, add --pull-request and --head-sha with the pull request’s head commit, as the
Any CI recipe explains.
When you upload a scopes JSON file with --scopes-json, the CLI also honors an
"all_scopes": true field in the file itself, so your detection tooling can set the flag without
touching the command line.
You can send the flag through the REST API as well. This endpoint needs an application key granted CI Reporting, which a key granted Every resource does not hold:
curl -X PUT \ -H "Accept: application/json" \ -H "Authorization: Bearer <your-application-key>" \ -H "Content-Type: application/json" \ -d '{"scopes": ["build-system"], "all_scopes": true}' \ https://api.mergify.com/v1/repos/<owner>/<repository>/commits/<head-sha>/scopesSend the pull request’s head SHA, which is not always the revision your job checked out: on a
pull_request event the default checkout is a merge commit, and an upload keyed on that commit
matches no pull request head. The pull-request-number variant of this endpoint is deprecated: send
the head SHA to the commit endpoint above instead.
The flag complements the scopes list rather than replacing it: keep reporting the concrete
scopes your tooling detected, and set all_scopes: true on top when the change affects every
target.
Barrier behavior in the queue
Section titled Barrier behavior in the queueA pull request flagged with all_scopes conflicts with every scope, so the merge queue serializes
at it: it shares a batch only with other barrier pull requests and is tested on top of every pull
request queued ahead of it, and the pull requests queued behind it merge only after it. Because a
barrier defeats parallelism, reserve all_scopes for changes that do need testing against
everything. In isolated mode a barrier is tested on its
own and the pull requests behind it do not wait for it.
The flag is visible in the merge queue status API and on the draft pull request description created by the queue.
Was this page helpful?
Thanks for your feedback!