Skip to content

Commit e575eee

Browse files
authored
feat(hooks): Validate Mergify configuration location (#4)
Ensure exactly one Mergify configuration file exists in an allowed location.
1 parent 58dfec2 commit e575eee

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

.pre-commit-hooks.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,32 @@
1212
| \.mergify/config\.yml
1313
| \.github/mergify\.yml
1414
)$
15+
16+
- id: validate-mergify-config-location
17+
name: Validate Mergify configuration location
18+
description: Ensure exactly one Mergify configuration file exists in an allowed location
19+
entry: sh -eu -c
20+
language: system
21+
pass_filenames: false
22+
always_run: true
23+
args:
24+
- |
25+
found=""
26+
for f in \
27+
.mergify.yml \
28+
.mergify/config.yml \
29+
.github/mergify.yml
30+
do
31+
[ -f "$f" ] || continue
32+
if [ -z "$found" ]; then
33+
found="$f"
34+
else
35+
printf "Multiple Mergify configuration files found. Ensure only one location is used:\n - %s\n - %s\n" "$found" "$f" >&2
36+
exit 1
37+
fi
38+
done
39+
40+
if [ -z "$found" ]; then
41+
echo "Mergify configuration missing. Expected one of: .mergify.yml, .mergify/config.yml, .github/mergify.yml" >&2
42+
exit 1
43+
fi

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,36 @@ Add the following to your `.pre-commit-config.yaml`:
99
```yaml
1010
repos:
1111
- repo: https://github.com/Mergifyio/mergify-pre-commit
12-
rev: 1.0.0
12+
rev: 1.1.0
1313
hooks:
14+
- id: validate-mergify-config-location
1415
- id: validate-mergify-config
1516
```
1617
17-
It uses `check-jsonschema` under the hood with Mergify's official schema:
18+
### validate-mergify-config
1819
19-
```
20-
https://docs.mergify.com/mergify-configuration-schema.json
21-
```
20+
Validate Mergify configuration files against the official schema.
2221
23-
### Customization
22+
- Uses `check-jsonschema` with Mergify's schema: `https://docs.mergify.com/mergify-configuration-schema.json`
23+
- Targets files matching the hook's `files` pattern.
2424

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

2727
```yaml
2828
repos:
2929
- repo: https://github.com/Mergifyio/mergify-pre-commit
30-
rev: 1.0.0
30+
rev: 1.1.0
3131
hooks:
3232
- id: validate-mergify-config
3333
args: ["--verbose"]
3434
```
35+
36+
### validate-mergify-config-location
37+
38+
Ensure exactly one Mergify configuration file exists in an allowed location.
39+
40+
- Allowed locations (yml only):
41+
- `.mergify.yml`
42+
- `.mergify/config.yml`
43+
- `.github/mergify.yml`
44+
- Runs as a system shell script, checks repo state (not just staged files).

0 commit comments

Comments
 (0)