Configuration Data Types
The different data types you can find in Mergify configuration file
When using templates or conditions, data are made of different types. You will find below the different data types that are available and exposed in Mergify configuration file.
Commit
A commit is an object that embeds several information about a Git commit
Key name | Value type | |
---|---|---|
sha | string | |
Commit sha | ||
parents | list of string | |
List of parents sha | ||
commit_message | string | |
The commit message | ||
commit_verification_verified | boolean | |
Whether the commit was verified by GitHub | ||
author | string | |
The commit author | ||
date_author | Timestamp | |
The date the commit was authored | ||
email_author | string | |
The email address of the commit author | ||
committer | string | |
The committer | ||
date_committer | Timestamp | |
The date the commit was committed |
You can use a commit object in templates:
{% for commit in commits %}Co-Authored-By: {{ commit.author }} <{{ commit.email_author }}>{% endfor %}
You can also use those objects in conditions:
pull_request_rules:- name: check that commits are not too oldconditions:- commits[*].date_committer < 365 days agoactions:comment:message: One of the commit is too old!
Commit Author
Key name | Value type | |
---|---|---|
name | string | |
Author name | ||
email | string | |
Author email address |
Regular Expressions
You can use regular expressions with matching operators in your conditions.
Mergify leverages Python regular expressions to match rules.
pull_request_rules:- name: add python label if a Python file is modifiedconditions:- 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)wipactions:merge:method: merge
Schedule
This format represents a schedule. It can contains only days, only times or both and can have a timezone specified with the times (for the list of available time zones, see IANA format. If no timezone is specified, it defaults to UTC.
Schedule can be only used with the equality operators =
and !=
.
schedule = Mon-Frischedule = 09:00-19:00schedule = 09:00-19:00[America/Vancouver]schedule != Mon-Fri 09:00-19:00[America/Vancouver]schedule != SAT-SUN
Timestamp
The timestamp format must follow the ISO 8601 standard. If the timezone is missing, the timestamp is assumed to be in UTC. The supported timezones come from the IANA database.
Supported formats:
2021-04-052012-09-17T22:02:512008-09-22T14:01:54Z2013-12-05T07:19:04-08:002013-12-05T07:19:04[Europe/Paris]
- name: end of life version 10.0conditions:- base=stable/10.0- updated-at<=2021-04-05actions:comment:message: |The pull request needs to be rebased after end of life of version 10.0
Timestamp Interval
Mergify supports ISO8601 time intervals for some of the exposed attributes.
If the timezone is missing, the timestamp is assumed to be in UTC. The supported timezones come from the IANA database.
2023-07-13T14:00/2023-07-13T16:002023-07-13T14:00:00.123/2023-07-13T16:00:00.1232023-07-13T14:00Z/2023-07-13T16:00Z2023-07-13T14:00/2023-07-13T16:00[Europe/Paris]
- name: merge except on new year dayconditions:- current-datetime!=2023-01-01T00:00/2023-01-01T23:59[Europe/Paris]actions:merge:
Unspecified digits can also be used for some part of the timestamp:
# 14:00 to 19:00 the 14th of July of every yearXXXX-07-14T14:00/XXXX-07-14T19:00[Europe/Paris]# 14:00 to 19:00 every day of July of every yearXXXX-07-XXT14:00/XXXX-07-XXT19:00[Europe/Paris]# 14:00 to 19:00 every day of July of 20232023-07-XXT14:00/XXXX-07-XXT19:00[Europe/Paris]# 14:00 to 19:00 every 31st day of every month of 2023# If a month doesn't have a 31st day it will be skipped2023-XX-31T14:00/2023-XX-31T19:00[Europe/Paris]# 14:00 to 19:00 every 31st day of every month of every yearXXXX-XX-31T14:00/XXXX-XX-31T19:00[Europe/Paris]
Relative Timestamp
Timestamps can be expressed relative to the current date and time. The format
is [DD days] [HH:MM]
:
DD
, the number of daysHH
, the number of hoursMM
, the number of minutes
If the current date is 18th June 2020, updated-at>=14 days ago
is translated
to updated-at>=2020-06-04T00:00:00
.
- name: close stale pull requestconditions:- base=main- -closed- updated-at<14 days agoactions:close:message: |This pull request looks stale. Feel free to reopen it if you think it's a mistake.
Duration
Duration can be expressed as quantity unit [quantity unit...]
where quantity
is a number (possibly signed); unit is second, minute, hour, day, week, or
abbreviations or plurals of these units;
1 day 15 hours 6 minutes 42 seconds1 d 15 h 6 m 42 s
Priority
Priority values can be expressed by using an integer between 1 and 10000. You can also use those aliases:
low
(1000)medium
(2000)high
(3000)
priority_rules:- name: my hotfix priority ruleconditions:- base=main- label=hotfix- check-success=linterspriority: high- name: my low priority ruleconditions:- base=main- label=low- check-success=linterspriority: 550
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 attributes 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
.
Jinja2 filters are supported, you can build string from list for example with:
Approved by: @{{ approved_reviews_by | join(', @') }}
Jinja2 string manipulation are also supported, you can split string for example with:
{{ body.split('----------')[0] | trim }}
Mergify also provides custom Jinja2 filters:
markdownify
: to convert HTML to Markdown:
{{ body | markdownify }}
get_section(<section>, <default>)
: to extract one Markdown section
{{ body | get_section("## Description") }}
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.
By default, the HTML comments are stripped from body
. To get the full
body, you can use the body_raw
attribute.
Queue Dequeue Reason
This describes the reason why a pull request has been removed from the queue.
Reason | Description |
---|---|
pr-merged | Pull request has been merged. |
pr-dequeued | Pull request has been removed from the queue by an dequeue command or by an automation rule |
checks-timeout | The configured
|
checks-failed | The checks have failed. |
queue-rule-missing | The queue rule has been removed from the configuration. |
target-branch-missing | The pull request base branch is missing. |
target-branch-changed | The pull request base branch has changed. |
pr-unexpectedly-failed-to-merge | An unexpected error happened while merging the pull request. |
batch-max-failure-resolution-attempts | The maximum number of resolution attempts set in
batch_max_failure_resolution_attempts has been reached. |
conflict-with-base-branch | The pull request conflicts with its base branch. |
conflict-with-pull-ahead | The pull request conflicts with a pull request ahead of it. |
branch-update-failed | Updating the head branch of the pull request failed. |