Announcing Time-based Conditions

Announcing Time-based Conditions

Mehdi Abaakouk

Today, we're happy to announce the general availability of one of our most awaited features.

Expressing conditions to act upon is the core of Mergify rules. While many dimensions are exposed through our configuration file and allow us to filter on many pull request attributes, one important was missing.

Time.

Being able to execute rules based on the date and time of the day is a crucial point. There are dozens of scenarios where one wants to execute or not an action depending on the time.

We met DevOps engineers who wanted only to merge pull requests during office hours, product managers who wanted to close pull requests passed a certain delay or software engineers who wanted to organize their workflow depending on the time of the day.

Let's see how this can be used.

Conditions based on the current time

We now offer the ability to write conditions based on the day of the week and time, making it easy to apply rules based on a schedule.

The following rule merges a pull request only during office hours:

pull_request_rules:
  - name: Merge pull requests during working hours
    conditions:
      - schedule=Mon-Fri 10:00-17:00
      - check-success=myci
      - "#approved-review-by>=1"
    actions:
      merge:

Using the schedule option is a friendly shortcut to write time-based conditions. You can also write finer-grained conditions using the current time, day, month or year using the current-time, current-day-of-week, current-month and current-year attributes.

Conditions based on pull request timestamp attributes

Mergify now exposes a couple of new pull request attributes: updated_at, created_at, closed_at, merged_at.

For example, this rule allows detecting stale pull requests:‌

pull_request_rules:
  - name: Comment on staled pull request.
    conditions:
      - updated-at<=14 days ago
    actions:
      comment:
        message: This pull request looks stale. Should we close it @{{author}}?

At Mergify, we believe this new tooling allows you to automate more of your tidy manual process to manage your pull requests.

Share below what you have automated with all of this! 🦾