Test labelling enforcement #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR and Issue Validation | |
on: | |
pull_request: | |
types: [opened, edited, labeled, unlabeled, synchronize] | |
issues: | |
types: [opened, edited, labeled, unlabeled] | |
jobs: | |
validate-pr: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v2 | |
- name: Validate PR has labels | |
id: check_labels | |
run: | | |
PR_LABELS=$(jq -r '.pull_request.labels | length' $GITHUB_EVENT_PATH) | |
if [ "$PR_LABELS" -eq "0" ]; then | |
echo "No labels found on the pull request." | |
exit 1 | |
fi | |
- name: Validate PR is linked to an issue | |
id: check_linked_issues | |
run: | | |
PR_NUMBER=$(jq -r '.pull_request.number' $GITHUB_EVENT_PATH) | |
REPO_OWNER=$(jq -r '.repository.owner.login' $GITHUB_EVENT_PATH) | |
REPO_NAME=$(jq -r '.repository.name' $GITHUB_EVENT_PATH) | |
TIMELINE_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues/$PR_NUMBER/timeline") | |
echo "Timeline JSON: $TIMELINE_JSON" | |
LINKED_ISSUES=$(echo "$TIMELINE_JSON" | jq ' | |
reduce .[] as $event ( | |
{}; | |
if $event.event == "cross-referenced" or $event.event == "connected" then | |
.[$event.source.issue.number] = true | |
elif $event.event == "unlinked" then | |
del(.[$event.source.issue.number]) | |
else | |
. | |
end | |
) | keys | length') | |
if [ "$LINKED_ISSUES" -eq "0" ]; then | |
echo "No linked issues found in the pull request." | |
exit 1 | |
fi | |
validate-issue: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v2 | |
- name: Validate issue has labels | |
id: check_labels | |
run: | | |
ISSUE_LABELS=$(jq -r '.issue.labels | length' $GITHUB_EVENT_PATH) | |
if [ "$ISSUE_LABELS" -eq "0" ]; then | |
echo "No labels found on the issue." | |
exit 1 | |
fi |