-
Notifications
You must be signed in to change notification settings - Fork 4
36 lines (35 loc) · 1.44 KB
/
pr-naming-rules.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Adopted from an action that is no longer maintained
# https://github.com/deepakputhraya/action-pr-title
name: Pull Request Validation
on:
pull_request:
types: [opened, synchronize, edited, reopened]
jobs:
title-rules:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const REGEX = new RegExp('^(\\[(feature|bugfix|doc|security|trivial)\\])+ [A-Z].+'); // Title must match this regex
const MIN_LENGTH = 32; // Min length of the title
const MAX_LENGTH = 256; // Max length of the title (-1 is no max)
const { title } = context.payload.pull_request;
if (!REGEX.test(title)) {
core.setFailed(
`Pull Request title "${title}" failed to match regex - ${REGEX}`
);
return;
}
if (title.length < MIN_LENGTH) {
core.setFailed(
`Pull Request title "${title}" is smaller than the minimum length - ${MIN_LENGTH}`
);
return;
}
if (MAX_LENGTH > 0 && title.length > MAX_LENGTH) {
core.setFailed(
`Pull Request title "${title}" is greater than the maximum length - ${MAX_LENGTH}`
);
return;
}