forked from stackrox/stackrox
-
Notifications
You must be signed in to change notification settings - Fork 0
46 lines (41 loc) · 1.47 KB
/
check-pr-title.yaml
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
37
38
39
40
41
42
43
44
45
46
name: "Check PR title"
on:
pull_request_target:
types: [opened, edited, synchronize]
jobs:
check-title:
runs-on: ubuntu-latest
env:
PR_TITLE: ${{ github.event.pull_request.title }}
steps:
- name: Check if the PR title is well dressed
env:
CONV: '(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([\w\-\.]+\))?!?'
JIRA: '([A-Z]+-[0-9]+, ?)*[A-Z]+-[0-9]+'
TEXT: ': .+'
run: |
# Either conventional or JIRA-nnn prefix followed by ': ' and random text:
REGEX="(($CONV)|($JIRA))($TEXT)"
test_regex() { echo -nE "$1" | grep --perl-regexp --line-regexp "$REGEX" ; }
echo "Examples:"
test_regex 'ROX-123: text'
test_regex 'ROX-123, RS-45: text'
test_regex 'refactor: text'
test_regex 'fix(ui): text'
test_regex 'feat(api)!: text'
if ! test_regex "$PR_TITLE"
then
echo "::error::Please update the PR title so that it follows the convention."
exit 1
fi
- name: Check PR title length
if: github.event.pull_request.user.login != 'dependabot[bot]'
env:
LENGTH: '70'
run: |
TITLE_LENGTH="$(echo -nE "$PR_TITLE" | wc --chars)"
if [ "$TITLE_LENGTH" -gt "$LENGTH" ]
then
echo "::error::Please shorten the PR title from $TITLE_LENGTH to at most $LENGTH characters."
exit 1
fi