Skip to content

ci: add job to check if PR has issue in description #1

ci: add job to check if PR has issue in description

ci: add job to check if PR has issue in description #1

name: Check PR Description
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
check-description:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Check PR description for 'Issue:' link
id: check_pr_description
run: |
PR_BODY=$(curl -s https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .body)
# Check if the PR description contains a line starting with 'Issue:'
if [[ ! "$PR_BODY" =~ ^Issue:\s*#?[0-9]+$ && ! "$PR_BODY" =~ ^Issue:\s*https://github.com/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+/issues/[0-9]+ ]]; then
echo "Error: PR description must include an issue link in the format 'Issue: #123' or 'Issue: https://github.com/owner/repo/issues/123'." >&2
exit 1
else
echo "PR description contains a valid issue link."
fi
- name: Fail PR if no issue link found
if: failure()
run: |
echo "Please add an issue link in the format 'Issue: #123' or 'Issue: https://github.com/owner/repo/issues/123' in the PR description."