View as Markdown

Label

Add, remove, or toggle labels on a pull request.


The label action allows Mergify to automatically add or remove labels from a pull request based on the conditions specified in your rules.

A label named in add or toggle that does not exist in the repository yet is created with a randomly picked color. Create it yourself first if you want to choose its color and description. Mergify only adds labels the pull request does not already carry, and only removes ones it does, so a rule whose conditions keep matching does not keep calling GitHub.

add#list of string

The list of labels to add.

remove#list of string

The list of labels to remove.

remove_all#boolean·defaultfalse

Remove all labels from the pull request.

toggle#list of string

Toggle labels in the list based on the conditions. If all the conditions are a success, all the labels in the list will be added, otherwise, they will all be removed.

pull_request_rules:
- name: add "WIP" label when the title contains "WIP"
conditions:
- title ~= WIP
actions:
label:
toggle:
- WIP

In this example, Mergify will automatically add the “WIP” label to any pull request whose title contains “WIP”. If the pull request does not match the rule anymore, the label will be removed.

When browsing the list of pull requests, GitHub does not give any indication on which pull requests might be in conflict. Mergify lets you do this by adding a label.

pull_request_rules:
- name: warn on conflicts
conditions:
- conflict
actions:
comment:
message: "@{{author}} this pull request is now in conflict 😩"
label:
toggle:
- conflict

Then, your pull request list will look like this on conflict:

Pull request in conflict in pull request list

Toggle A Label Based on CI Status

Section titled Toggle A Label Based on CI Status

This rule toggles a label based on the failure status of a CI system.

pull_request_rules:
- name: toggle labels based on CI state
conditions:
- check-failure = CI
actions:
label:
toggle:
- "CI:fail"

Add A Label Based on The Target Branch

Section titled Add A Label Based on The Target Branch

This rule adds a static label to pull requests targeting a given branch.

pull_request_rules:
- name: label pull requests targeting the release branch
conditions:
- base = release
actions:
label:
add:
- "release"

Was this page helpful?