Posting Custom Checks on Pull Requests

Posting Custom Checks on Pull Requests

Julien Danjou

Today, we're happy to announce a new feature that just landed in Mergify. You can now use the post_check action to post your custom checks into your pull requests.

If you never heard of those, checks are statuses posted at the bottom of a pull request near the merge button, usually with a green checkmark or a red cross. I'm sure you saw them already!


Now, Mergify allows to post your own check using the post_check action. to post the checks' result, written in your Mergify configuration. Let's see a few examples.

Validate Workflow

It's pretty standard for teams to have a well-defined workflow. That means pull requests should follow a particular set of rules.

For example, if your team follows the Conventional Commit convention, you might want to make sure your pull requests align with that.

You can check your pull request title with such a rule:

- name: Conventional Commit
  conditions:
    - "title~=^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\\(.+\\))?:"
  actions:
    post_check:
      title: |
        {% if check_succeed %}
        Title follows Conventional Commit
        {% else %}
        Title does not follow Conventional Commit
        {% endif %}
      summary: |
        {% if not check_succeed %}
        Your pull request title must follow [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/).
        {% endif %}

Mergify automatically validates the pull request title and post the result as a check:

All checks valid!

In the case where the check would fail, it's easy to explain what the pull request author should do to make the check valid:

Validate Authorship

In the same scenario, you could limit the pull requests you accept from specific authors. Such a verification can be useful to restrict contributions to a repository to valid members only.

- name: Author Authorization
  conditions:
    - author!=@dev
  actions:
    post_check:
      title: |
        {% if check_succeed %}
        Pull request authorized
        {% else %}
        Pull request unauthorized
        {% endif %}
      summary: |
        {% if not check_succeed %}
        You are not authorized to create a pull request because you are not a
        member of the dev team.
        {% endif %}

With such a rule, if the pull request author is not a member of the GitHub team dev, the check will fail β€” otherwise, it'll succeed.

This kind of check can be handy to implement conformity rules on your GitHub repository.

We are eager to see what kind of ideas and workflow validation our users will invent! Check out the documentation and feel free to share your thoughts in the comment section.