label๐Ÿ”—

The label action can add or remove labels from a pull request.

Options๐Ÿ”—

Key Name

Value Type

Default

Value Description

add

list of Template

[]

The list of labels to add.

remove

list of Template

[]

The list of labels to remove.

remove_all

Boolean

false

Remove all labels from the pull request.

toggle

list of Template

[]

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.

Examples๐Ÿ”—

๐Ÿ’ฅ Warn on Conflicts๐Ÿ”—

When browsing the list of pull request, GitHub does not give any indication on which pull requests might be in conflict. Mergify allows to do this easily 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:
        add:
          - conflict
  - name: remove conflict label if not needed
    conditions:
      - -conflict
    actions:
      label:
        remove:
          - conflict

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

../../_images/conflict-pr-list.png

Toggle a label based on CI status๐Ÿ”—

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 name of the branch๐Ÿ”—

pull_request_rules:
  - name: add a label with the name of the branch
    conditions: []
    actions:
      label:
        add:
          - "branch:{{base}}"