---
title: Workflow Automation
description: Automate the routine work on your pull requests with rules that react to a pull request's state to label, comment, assign, rebase, merge, and more.
hubAccent: true
---

Workflow Automation handles the routine work on your pull requests. You write
rules in your Mergify configuration file, and Mergify carries them out: labeling,
commenting, assigning, rebasing, merging, and more. Your team spends less time on
pull request housekeeping.

## Anatomy of a rule

Every rule lives under `pull_request_rules` and pairs a set of **conditions**
with the **actions** to run when a pull request matches them:

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

Here, any pull request whose title contains `WIP` gets the `WIP` label. Once the
title no longer matches, Mergify removes it.

## How rules are evaluated

Mergify evaluates the *state* of a pull request rather than individual events. It
checks the current status of a pull request and acts based on the conditions you
defined. This behavior is known as "edge triggering": once an action has run,
Mergify does not run it again while the rule keeps matching. It runs a second
time only after the pull request stops matching the rule and then matches again.

Not every action works that way. `assign`, `dismiss_reviews`, `edit`, `label`,
`rebase`, `request_reviews`, `review`, `squash`, and `update` run on every
evaluation instead, which is how they hold a pull request in the state
a rule describes. The rule above relies on that: if someone removes the `WIP`
label while the title still matches, Mergify puts it back.

A failure counts as having run: an edge-triggered action that failed does not
try again while its rule keeps matching. To run it again, comment
[`@mergifyio refresh`](/commands/refresh) or re-run one of Mergify's check runs
from the pull request's **Checks** tab. Either one asks for a full
re-evaluation, which resyncs the pull request's data from GitHub and re-runs
the actions that failed or were cancelled.

:::note
  Mergify never evaluates rules for pull request drafts it creates while
  processing the [merge queue](/merge-queue).
:::

## Building blocks

  - [Rule Syntax](/workflow/rule-syntax): The `pull_request_rules` format and how to structure a rule.
  - [Conditions](/configuration/conditions): Match pull requests on title, labels, CI status, files, authorship, and more.
  - [Actions](/workflow/actions): The full catalog of tasks Mergify can run when a rule matches.
  - [Configuration File](/configuration/file-format): Where rules live and how the overall config file is structured.

## Popular actions

  - [Merge](/workflow/actions/merge): Automate the merging of your pull requests.
  - [Queue](/workflow/actions/queue): Add the pull request to the merge queue.
  - [Label](/workflow/actions/label): Add, remove, or toggle labels on a pull request.
  - [Comment](/workflow/actions/comment): Post a comment on a pull request.
  - [Backport](/workflow/actions/backport): Copy a pull request to another branch once it is merged.
  - [Rebase](/workflow/actions/rebase): Rebase the pull request on top of its base branch.

