-
Notifications
You must be signed in to change notification settings - Fork 1
45 lines (40 loc) · 1.41 KB
/
pr_body_validation.yml
File metadata and controls
45 lines (40 loc) · 1.41 KB
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
name: Pull Request Body Validation
on:
pull_request:
branches:
- main
types: [opened, synchronize, reopened, edited]
permissions:
checks: write
pull-requests: write
jobs:
check-pr-body:
runs-on: ubuntu-latest
outputs:
body_check_failed: ${{ steps.regex.outputs.match }}
steps:
- name: Check if the PR body contains 'Closes #'
id: regex
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ github.event.pull_request.body }}
regex: 'Closes #[0-9]+'
- name: Comment on PR, if body check fails
if: steps.regex.outputs.match == ''
uses: actions/github-script@v5
with:
script: |
const issueComment = `Hello @${{ github.actor }} 👋, \
\n\nIt looks like your PR description is missing 'Closes #'. \
\nPlease include the phrase 'Closes #issue_ID' to indicate which issue this PR closes.`;
github.rest.issues.createComment({
issue_number: ${{ github.event.pull_request.number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: issueComment
});
- name: Fail workflow if PR description is missing Closes #
if: steps.regex.outputs.match == ''
run: |
echo "Failing the workflow because PR description is missing Closes #."
exit 1