-
Notifications
You must be signed in to change notification settings - Fork 5
52 lines (41 loc) · 1.75 KB
/
validate-pr-template.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: Validate PR Template
on:
pull_request:
types: [opened, edited, reopened]
jobs:
validate-pr:
runs-on: ubuntu-latest
<<<<<<< HEAD
=======
if: ${{ github.actor != 'dependabot[bot]' && github.actor != 'beyondtrust-release-app[bot]' }}
>>>>>>> main
steps:
- name: Check PR Description
id: validate
run: |
PR_BODY=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH")
if [[ -z "$PR_BODY" || "$PR_BODY" == "null" ]]; then
echo "PR description is empty or null."
exit 1
fi
# Check sections
PURPOSE=$(echo "$PR_BODY" | sed -n '/### Purpose of the PR/,/### According to ticket/p' | sed '1d;$d' | grep -v "<!--")
TICKET=$(echo "$PR_BODY" | sed -n '/### According to ticket/,/### Summary of changes:/p' | sed '1d;$d' | grep -v "<!--")
SUMMARY=$(echo "$PR_BODY" | sed -n '/### Summary of changes:/,$p' | sed '1d' | grep -v "<!--")
# Validate each section
if [[ -z "$PURPOSE" || "$PURPOSE" =~ ^[[:space:]]*$ ]]; then
echo "The 'Purpose of the PR' section must contain meaningful text below the placeholder."
exit 1
fi
if [[ -z "$TICKET" || "$TICKET" =~ ^[[:space:]]*$ ]]; then
echo "The 'According to ticket' section must contain meaningful text (e.g., Jira URL or ticket number)."
exit 1
fi
if [[ -z "$SUMMARY" || "$SUMMARY" =~ ^[[:space:]]*$ ]]; then
echo "The 'Summary of changes' section must contain meaningful text below the placeholder."
exit 1
fi
echo "PR description is valid."
- name: Set output for success
if: success()
run: echo "PR template validation passed!"