In Mergify, you can leverage certain features like YAML anchors and aliases,
shared key, and the
extends key to reduce redundancy, maintain
consistency, and increase code reusability.
YAML Anchors and AliasesSection titled YAML Anchors and Aliases
YAML anchors (
&) and aliases
*) are supported in the
configuration file. These allow you to reuse
configuration sections. For example, you can create a list of continuous
integration checks and use it in multiple sections:
Sharing Configuration SectionsSection titled Sharing Configuration Sections
You can store anything in the
shared key. Its main purpose is to provide a
place to put redundant YAML anchors:
Extending Configuration FilesSection titled Extending Configuration Files
Mergify lets you extend your configuration file by including the configuration from another repository. This feature is useful when you want to share and reuse configuration rules across multiple repositories, helping maintain consistency and reduce duplication.
To extend a configuration file, use the
extends keyword at the top level of
your configuration file file and specify the repository name from which you
want to include the configuration.
The configuration from the specified repository will be loaded and applied before the one in the current repository. Here’s an example:
Extending YAML anchorsSection titled Extending YAML anchors
Mergify, by using the
extends feature, also lets you extend the YAML anchors.
With the same duplication reduction goal, you can centralize all your anchors
inside one unique configuration file, that will be extended to others.
To extend the anchors, you simply have to define them in the configuration file that will be extended to the current configuration file. Then you can simply use the corresponding aliases inside the current configuration file and Mergify will automatically replace them with the anchors defined in the extended file.
The mechanism works as follows:
- Main configuration file using
extendskeyword with an undefined YAML alias:
- Extended file containing the YAML anchor definition:
- Final main configuration file: