32
32
run : |
33
33
set -x
34
34
# Skip validation for documentation or chore PRs
35
- if [[ "$TITLE" =~ ^(doc:|docs:|chore:) ]]; then
35
+ if [[ "$TITLE" =~ ^(doc:|docs:|chore:|misc: ) ]]; then
36
36
echo "Skipping validation for docs/chore PR."
37
37
echo "PR NUMBER-: $PRNUM "
38
38
gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed"
@@ -54,17 +54,26 @@ jobs:
54
54
55
55
# Extract issue number and repo from PR body
56
56
extract_issue_number() {
57
- local pattern="$1"
57
+ local pattern="$1" # Get the pattern as the first argument to the function
58
+
59
+ # Check if PR_BODY matches the provided pattern using Bash's =~ regex operator
58
60
if [[ "$PR_BODY" =~ $pattern ]]; then
59
61
echo "matched for this pattern $pattern"
60
- issue_num=$(echo "${BASH_REMATCH[0]}" | grep -oE "[0-9]+" | tr -d '\r\n')
62
+
63
+ # # If there is a match, Bash populates the BASH_REMATCH array with the results. stores the entire matched portion of the string
64
+ # issue_num=$(echo "${BASH_REMATCH[0]}" | grep -oE "[0-9]+" | tr -d '\r\n')
65
+
66
+ issue_num=$(echo "$PR_BODY" | grep -oE "$pattern" | grep -oE "[0-9]+")
67
+
68
+ # Extract the repository name (e.g., devtron-labs/devtron) from PR_BODY using grep
61
69
repo=$(echo "$PR_BODY" | grep -oE "devtron-labs/[a-zA-Z0-9_-]+")
62
70
echo "Extracted issue number : $issue_num from repo: $repo"
63
- return 0
71
+
72
+ return 0 # Return success
64
73
else
65
74
echo "No match for the pattern $pattern"
66
75
fi
67
- return 1
76
+ return 1 # Return failure if no match
68
77
}
69
78
70
79
issue_num=""
@@ -92,11 +101,33 @@ jobs:
92
101
93
102
if [[ "$response_code" -eq 200 ]]; then
94
103
echo "Issue # $issue_num is valid and exists in $repo."
95
- gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed"
96
- gh pr edit $PRNUM --add-label "PR:Ready-to-Review"
104
+
105
+ # Fetch the current state of the issue (open/closed) from the private repository.
106
+ issue_status=$(curl -s \
107
+ --header "authorization : Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}" \
108
+ " $issue_api_url" | jq '.state')
109
+ # Check if the issue is still open.
110
+ if [[ "$issue_status" -eq "open" ]]; then
111
+ echo "Issue # $issue_num is opened."
112
+ # Remove the 'Issue-verification-failed' label (if present) and add 'Ready-to-Review'.
113
+ gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed"
114
+ gh pr edit $PRNUM --add-label "PR:Ready-to-Review"
115
+ else
116
+ echo "Issue # $issue_num is closed. Please link an open issue to proceed."
117
+ # Add a comment to the PR indicating the issue is not linked correctly.
118
+ gh pr comment $PRNUM --body "PR is linked to a closed issue. Please link an open issue to proceed."
119
+
120
+ # Add the 'Issue-verification-failed' label and remove 'Ready-to-Review'.
121
+ gh pr edit $PRNUM --add-label "PR:Issue-verification-failed"
122
+ gh pr edit $PRNUM --remove-label "PR:Ready-to-Review"
123
+ exit 1
124
+ fi
97
125
else
98
126
echo "Issue not found. Invalid URL or issue number."
99
- gh pr comment $PRNUM --body "PR is not linked to a valid issue. Please update."
127
+ # Add a comment to the PR indicating the issue is not linked correctly.
128
+ gh pr comment $PRNUM --body "PR is not linked to a valid issue. Please update the issue link."
129
+
130
+ # Apply 'Issue-verification-failed' label and remove 'Ready-to-Review' label.
100
131
gh pr edit $PRNUM --add-label "PR:Issue-verification-failed"
101
132
gh pr edit $PRNUM --remove-label "PR:Ready-to-Review"
102
133
exit 1
0 commit comments