1111 - ' main'
1212 - ' release-**'
1313 - ' develop'
14- - ' hotfix-v0**'
15-
14+ - ' hotfix-**'
15+ # paths-ignore:
16+ # - 'docs/**'
17+ # - '.github/'
18+ # - 'CHANGELOG/'
19+ # - 'charts/'
20+ # - 'manifests/'
21+ # - 'sample-docker-templates/'
1622jobs :
1723 validate-PR-issue :
1824 runs-on : ubuntu-latest
19- permissions :
20- issues : write
21- contents : read
22- pull-requests : write
25+
2326 steps :
2427 - name : Checkout repository
2528 uses : actions/checkout@v2
2629
27- - name : Validate Issue Reference
30+ - name : Set up jq (for parsing JSON)
31+ run : sudo apt-get install -y jq
32+
33+ - name : PR Validation Script
2834 env :
29- GH_TOKEN : ${{ github.token }}
3035 PR_BODY : ${{ github.event.pull_request.body }}
3136 PRNUM : ${{ github.event.pull_request.number }}
3237 TITLE : ${{ github.event.pull_request.title }}
38+ GH_TOKEN : ${{ github.token }}
39+ GH_PR_VALIDATOR_TOKEN : ${{ secrets.GH_PR_VALIDATOR_TOKEN }}
40+ BASE_REPO : ${{ github.event.pull_request.base.repo.full_name }}
41+ HEAD_REPO : ${{ github.event.pull_request.head.repo.full_name }}
3342 run : |
34- set -x
35- # Skip validation for documentation or chore PRs
36- if [[ "$TITLE" =~ ^(doc:|docs:|chore:|misc:|sync:) ]]; then
37- echo "Skipping validation for docs/chore PR."
38- echo "PR NUMBER-: $PRNUM "
39- gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed"
40- gh pr edit $PRNUM --add-label "PR:Ready-to-Review"
41- exit 0
42- fi
43-
44- # Define all issue matching patterns
45- patterns=(
46- " ((Fixes|Resolves) #[0-9]+)"
47- " ((Fixes|Resolves) https://github.com/devtron-labs/devtron/issues/[0-9]+)"
48- " ((Fixes|Resolves) devtron-labs/devtron#[0-9]+)"
49- " (Fixes|Resolves):?\\ s+\\ [#([0-9]+)\\ ]"
50- " ((Fixes|Resolves):? #devtron-labs/devops-sprint/issues/[0-9]+)"
51- " ((Fixes|Resolves):? #devtron-labs/sprint-tasks/issues/[0-9]+)"
52- " ((Fixes|Resolves) https://github.com/devtron-labs/devops-sprint/issues/[0-9]+)"
53- " ((Fixes|Resolves) https://github.com/devtron-labs/sprint-tasks/issues/[0-9]+)"
54- " ((Fixes|Resolves):? #devtron-labs/sprint-tasks#[0-9]+)"
55- )
56-
57- # Extract issue number and repo from PR body
58- extract_issue_number() {
59- local pattern="$1" # Get the pattern as the first argument to the function
60-
61- # Check if PR_BODY matches the provided pattern using Bash's =~ regex operator
62- if [[ "$PR_BODY" =~ $pattern ]]; then
63- echo "matched for this pattern $pattern"
64-
65- issue_num=$(echo "$PR_BODY" | grep -oE "$pattern" | grep -oE "[0-9]+")
66-
67- # Extract the repository name (e.g., devtron-labs/devtron) from PR_BODY using grep
68- repo=$(echo "$PR_BODY" | grep -oE "devtron-labs/[a-zA-Z0-9_-]+")
69- echo "Extracted issue number : $issue_num from repo: $repo"
70-
71- return 0 # Return success
72- else
73- echo "No match for the pattern $pattern"
74- fi
75- return 1 # Return failure if no match
76- }
77-
78- issue_num=""
79- repo="devtron-labs/devtron" # Default repo
80- for pattern in "${patterns[@]}"; do
81- echo "Now checking for $pattern"
82- extract_issue_number "$pattern" && break
83- done
84-
85- if [[ -z "$issue_num" ]]; then
86- echo "No valid issue number found."
87- gh pr edit $PRNUM --add-label "PR:Issue-verification-failed"
88- gh pr edit $PRNUM --remove-label "PR:Ready-to-Review"
89- exit 1
90- fi
91-
92- # Form the issue API URL dynamically
93- issue_api_url="https://api.github.com/repos/$repo/issues/$issue_num"
94- echo "API URL : $issue_api_url"
95-
96- # Check if the issue exists in the private repo
97- response_code=$(curl -s -o /dev/null -w "%{http_code}" \
98- --header "authorization : Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}" \
99- " $issue_api_url" )
100-
101- if [[ "$response_code" -eq 200 ]]; then
102- echo "Issue # $issue_num is valid and exists in $repo."
103-
104- # Fetch the current state of the issue (open/closed) from the private repository.
105- issue_status=$(curl -s \
106- --header "authorization : Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}" \
107- " $issue_api_url" | jq '.state'|tr -d \")
108- # Check if the issue is still open.
109- # if [[ "$issue_status" == open ]]; then
110- # echo "Issue #$issue_num is opened."
111- if [[ $forked == true ]]; then
112- echo "PR:Ready-to-Review, exiting gracefully"
113- exit 0
114- fi
115- # Remove the 'Issue-verification-failed' label (if present) and add 'Ready-to-Review'.
116- gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed"
117- gh pr edit $PRNUM --add-label "PR:Ready-to-Review"
118- echo "PR:Ready-to-Review, exiting gracefully"
119- exit 0
120- # else
121- # echo "Issue #$issue_num is closed. Please link an open issue to proceed."
122- # if [[ $forked == true ]]; then
123- # echo "PR:Ready-to-Review, exiting gracefully"
124- # exit 0
125- # fi
126- # Add a comment to the PR indicating the issue is not linked correctly.
127- # gh pr comment $PRNUM --body "PR is linked to a closed issue. Please link an open issue to proceed."
128-
129- # Add the 'Issue-verification-failed' label and remove 'Ready-to-Review'.
130- # gh pr edit $PRNUM --add-label "PR:Issue-verification-failed"
131- # gh pr edit $PRNUM --remove-label "PR:Ready-to-Review"
132- # exit 1
133- # fi
134- else
135- echo "Issue not found. Invalid URL or issue number."
136- # Add a comment to the PR indicating the issue is not linked correctly.
137- gh pr comment $PRNUM --body "PR is not linked to a valid issue. Please update the issue link."
138-
139- # Apply 'Issue-verification-failed' label and remove 'Ready-to-Review' label.
140- gh pr edit $PRNUM --add-label "PR:Issue-verification-failed"
141- gh pr edit $PRNUM --remove-label "PR:Ready-to-Review"
142- exit 1
143- fi
43+ wget https://raw.githubusercontent.com/devtron-labs/utilities/feat/central-pr-validator/.github/workflows/validateIssue.sh
44+ chmod +x validateIssue.sh
45+ ./validateIssue.sh
0 commit comments