Skip to content

Commit

Permalink
Update pr-issue-validator.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhtayal72 authored Aug 29, 2023
1 parent 937bdd3 commit 73a2b90
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions .github/workflows/pr-issue-validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@ on:
- synchronize
- edited
- reopened
branches:
- 'main'
- 'release-**'
- 'master'
# paths-ignore:
# - 'docs/**'
# - '.github/'
# - 'CHANGELOG/'
# - 'charts/'
# - 'manifests/'
# - 'sample-docker-templates/'


jobs:
validate-PR-issue:
runs-on: ubuntu-latest
Expand All @@ -29,27 +18,22 @@ jobs:

- name: Validate Issue Reference
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
PR_BODY: ${{ github.event.pull_request.body }}
url: ${{ github.event.pull_request.url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PRNUM: ${{ github.event.pull_request.number }}
TITLE: ${{ github.event.pull_request.title }}
run: |
set -x
set -e
if [[ "$TITLE" == *"doc:"* || "$TITLE" == *"docs:"* || "$TITLE" == *"chore:"* ]]; then
echo "Skipping validation as this is a PR for documentation or chore."
gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed"
gh pr edit $PRNUM --add-label "PR:Ready-to-Review"
gh pr edit $PRNUM --remove-label "PR: Issue-verification-failed"
gh pr edit $PRNUM --remove-label "PR:Ready-to-Review"
exit 0
fi
pattern="((Fixes|Resolves) #[0-9]+)"
echo "pattern = \n$pattern"
# Get the pull request body
PR_BODY=$(jq -r '.pull_request.body' $GITHUB_EVENT_PATH)
echo "pr_body = \n$PR_BODY"
issue_num=$(echo "$PR_BODY" | grep -o -P "$pattern" | head -n1 | grep -o -E "[0-9]+")
if [[ -z "$issue_num" ]]; then
Expand All @@ -76,7 +60,7 @@ jobs:
if [[ $(echo "$text" | jq -r '.state') == "open" ]]; then
echo "Issue #$issue_num is open"
echo "Issue reference found in the pull request body."
gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed"
gh pr edit $PRNUM --remove-label "PR: Issue-verification-failed"
gh pr edit $PRNUM --add-label "PR:Ready-to-Review"
exit 0
else
Expand All @@ -87,7 +71,7 @@ jobs:
echo "Invalid Response Code obtained - error code: $response_code"
echo "No valid issue reference found in the pull request body."
gh pr comment $PRNUM --body "PR is not linked to any issue, please make the corresponding changes in the body."
gh pr edit $PRNUM --add-label "PR:Issue-verification-failed"
gh pr edit $PRNUM --add-label "PR: Issue-verification-failed"
gh pr edit $PRNUM --remove-label "PR:Ready-to-Review"
exit 1
fi

0 comments on commit 73a2b90

Please sign in to comment.