πŸ”– Configuration FileπŸ”—

File UsedπŸ”—

Mergify uses the configuration file that is:

  • The file named .mergify.yml, or, as a fallback, .mergify/config.yml or .github/mergify.yml from the root directory.

  • In the default repository branch configured on GitHub β€” usually main.

FormatπŸ”—

Here’s what you need to know about the file format:

  • The file format is YAML.

  • The file main type is a dictionary whose keys are named pull_request_rules and defaults.

Pull Request RulesπŸ”—

  • The value type of the pull_request_rules is list.

  • Each entry in pull_request_rules must be a dictionary.

Each dictionary must have the following keys:

Key Name

Value Type

Value Description

name

string

The name of the rule. This is not used by the engine directly, but is used when reporting information about a rule.

disabled

dictionary with reason key

This optional key allows to disabled a rule and cancel any ongoing actions. A reason must be set using the reason key.

conditions

list of 🎯 Conditions

A list of 🎯 Conditions string that must match against the pull request for the rule to be applied.

actions

dictionary of πŸš€ Actions

A dictionary made of πŸš€ Actions that will be executed on the matching pull requests.

The rules are evaluated in the order they are defined in pull_request_rules and, therefore, the actions are executed in that same order.

See πŸ§ͺ Example Rules for configuration file examples.

Queue RulesπŸ”—

  • The value type of the queue_rules is list.

  • Each entry in queue_rules must be a dictionary.

See Queue Rules for the complete list and description of options.

DefaultsπŸ”—

  • The value type of defaults is a dictionary.

This dictionary must have the following key:

Key Name

Value Type

Value Description

actions

dictionary of πŸš€ Actions

A dictionary made of πŸš€ Actions whose configuration will be used by default.

The defaults section is used to define default configuration valued for actions run by pull request rules and by βš™οΈ Commands. If the options are defined in pull_request_rules they are used, otherwise, the values set in defaults are used.

For example:

defaults:
  actions:
    comment:
      bot_account: Autobot

pull_request_rules:
  - name: comment with default
    conditions:
      - label=comment
    actions:
      comment:
        message: I πŸ’™ Mergify

The configuration above is the same as below:

pull_request_rules:
  - name: comment with default
    conditions:
      - label=comment
    actions:
      comment:
        message: I πŸ’™ Mergify
        bot_account: Autobot

Data TypesπŸ”—

Regular ExpressionsπŸ”—

You can use regular expression with matching operators in your conditions .

Mergify leverages Python regular expressions to match rules.

Tip

You can use regex101, PyRegex or Pythex to test your regular expressions.

ExamplesπŸ”—

pull_request_rules:
  - name: add python label if a Python file is modified
    conditions:
      - files~=\.py$
    actions:
      label:
        add:
          - python

  - name: automatic merge for main when the title does not contain β€œWIP” (ignoring case)
    conditions:
      - base=main
      - -title~=(?i)wip
    actions:
      merge:
        method: merge

TimeπŸ”—

This format represents the time of the day in the 24-hours format. It can be used with any of the greater and lesser operators (>=, >, <=, <).

current-time>=18:00[Europe/Paris
schedule: Mon-Fri 09:00-19:00[America/Vancouver]
schedule: Mon-Fri 09:00[Europe/Paris]-19:00[America/Vancouver]

ExamplesπŸ”—

- name: comment after 18:00
  conditions:
    - current-time>=18:00
  actions:
    close:
      message: It's too late for this!
- name: merge on working hour
  conditions:
    - schedule: Mon-Fri 09:00-19:00[America/Vancouver]
  actions:
    merge:

TimestampπŸ”—

The timestamp format must follow the ISO 8601 standard. If the timezone is missing, the timestamp is assumed to be in UTC.

2021-04-05
2012-09-17T22:02:51
2008-09-22T14:01:54Z
2013-12-05T07:19:04-08:00
2013-12-05T07:19:04[Europe/Paris]

ExamplesπŸ”—

- name: end of life version 10.0
  conditions:
    - base=stable/10.0
    - -closed
    - current-timestamp>=2021-04-05
  actions:
    close:
      message: |
        The pull request base branch has reached end-of-life.

Relative TimestampπŸ”—

Timestamps can be expressed relative to the current date and time. The format is [DD days] [HH:MM] ago:

  • DD, the number of days

  • HH, the number of hours

  • MM, the number of minutes

If the current date is 18th June 2020, updated-at>=14 days ago will be translated updated-at>=2020-06-04T00:00:00.

ExamplesπŸ”—

- name: close stale pull request
  conditions:
    - base=main
    - -closed
    - updated-at<14 days ago
  actions:
    close:
      message: |
        This pull request looks stale. Feel free to reopen it if you think it's a mistake.

Disabling RulesπŸ”—

You can disable a rule while keeping it in the configuration. This allows gracefully handling the cancellation of any ongoing actions (e.g., like stopping the merge queue).

ExamplesπŸ”—

- name: automatic merge for main when the title does not contain β€œWIP” (ignoring case)
  disabled:
    reason: code freeze
  conditions:
    - base=main
    - -title~=(?i)wip
  actions:
    merge:
      method: merge

TemplateπŸ”—

The template data type is a regular string that is rendered using the Jinja2 template language.

If you don’t need any of the power coming with this templating language, you can just use this as a regular string.

However, those templates allow to use any of the pull request attribute in the final string.

For example the template string:

Thank you @{{author}} for your contribution!

will render to:

Thank you @jd for your contribution!

when used in your configuration file β€” considering the pull request author login is jd.

Note

You need to replace the - character by _ from the pull request attribute names when using templates. The - is not a valid character for variable names in Jinja2 template.

ValidationπŸ”—

Changes to the configuration file should be done via a pull request in order for Mergify to validate it via a GitHub check.

However, if you want to validate your configuration file before sending a pull request, you can use the following command line:

$ curl -F 'data=@.mergify.yml' https://gh.mergify.io/validate

Or by uploading the configuration file with this form: