Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,32 @@
| \.mergify/config\.yml
| \.github/mergify\.yml
)$

- id: validate-mergify-config-location
name: Validate Mergify configuration location
description: Ensure exactly one Mergify configuration file exists in an allowed location
entry: sh -eu -c
language: system
pass_filenames: false
always_run: true
args:
- |
found=""
for f in \
.mergify.yml \
.mergify/config.yml \
.github/mergify.yml
do
[ -f "$f" ] || continue
if [ -z "$found" ]; then
found="$f"
else
printf "Multiple Mergify configuration files found. Ensure only one location is used:\n - %s\n - %s\n" "$found" "$f" >&2
exit 1
fi
done

if [ -z "$found" ]; then
echo "Mergify configuration missing. Expected one of: .mergify.yml, .mergify/config.yml, .github/mergify.yml" >&2
exit 1
fi
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,36 @@ Add the following to your `.pre-commit-config.yaml`:
```yaml
repos:
- repo: https://github.com/Mergifyio/mergify-pre-commit
rev: 1.0.0
rev: 1.1.0
hooks:
- id: validate-mergify-config-location
- id: validate-mergify-config
```

It uses `check-jsonschema` under the hood with Mergify's official schema:
### validate-mergify-config

```
https://docs.mergify.com/mergify-configuration-schema.json
```
Validate Mergify configuration files against the official schema.

### Customization
- Uses `check-jsonschema` with Mergify's schema: `https://docs.mergify.com/mergify-configuration-schema.json`
- Targets files matching the hook's `files` pattern.

To pass extra arguments to `check-jsonschema`, use `args` in your config. For example, to enable verbose mode:
Customization example (pass extra args to `check-jsonschema`):

```yaml
repos:
- repo: https://github.com/Mergifyio/mergify-pre-commit
rev: 1.0.0
rev: 1.1.0
hooks:
- id: validate-mergify-config
args: ["--verbose"]
```

### validate-mergify-config-location

Ensure exactly one Mergify configuration file exists in an allowed location.

- Allowed locations (yml only):
- `.mergify.yml`
- `.mergify/config.yml`
- `.github/mergify.yml`
- Runs as a system shell script, checks repo state (not just staged files).