Skip to content

Commit 74ea72f

Browse files
Merge pull request #691 from rhmdnd/add-github-action-for-checking-pr-titles
CMP-3152: Implement an action to check PR titles
2 parents b8ec8ed + 5888741 commit 74ea72f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

.github/workflows/check-pr-title.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "Check PR title"
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, edited, synchronize]
6+
7+
jobs:
8+
check-title:
9+
runs-on: ubuntu-latest
10+
env:
11+
PR_TITLE: ${{ github.event.pull_request.title }}
12+
steps:
13+
- name: Check if the PR title is well dressed
14+
if: github.event.pull_request.user.login != 'renovate[bot]' || github.event.pull_request.user.login != 'red-hat-konflux[bot]'
15+
env:
16+
JIRA: '([A-Z]+-[0-9]+, ?)*[A-Z]+-[0-9]+'
17+
TEXT: ': .+'
18+
run: |
19+
# Either conventional or JIRA-nnn prefix followed by ': ' and random text:
20+
REGEX="($JIRA)($TEXT)"
21+
test_regex() { echo -nE "$1" | grep --perl-regexp --line-regexp "$REGEX" ; }
22+
23+
echo "Examples:"
24+
test_regex 'CMP-123: text'
25+
test_regex 'CMP-123, OCPBUGS-12345: text'
26+
27+
if ! test_regex "$PR_TITLE"
28+
then
29+
echo "::error::Please update the PR title so that it follows the convention."
30+
exit 1
31+
fi

0 commit comments

Comments
 (0)