Skip to content

Commit 2ecc785

Browse files
chore: Update pr-issue-validator.yaml (#3854)
* Update pr-issue-validator.yaml added support for following regex : - Fixes #3482 - Fixes #3482 - Resolves #3482 - Resolves #3482 * Update pr-issue-validator.yaml Trimmed whitespace chartacter '\r' using tr utility
1 parent ef45955 commit 2ecc785

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

.github/workflows/pr-issue-validator.yaml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,36 @@ jobs:
4545
gh pr edit $PRNUM --add-label "PR:Ready-to-Review"
4646
exit 0
4747
fi
48-
pattern="((Fixes|Resolves) #[0-9]+)"
48+
49+
### For ex: Fixes #2123
50+
pattern1="((Fixes|Resolves) #[0-9]+)"
51+
52+
### For ex: Resolves https://github.com/devtron-labs/devtron/issues/2123
53+
pattern2="((Fixes|Resolves) https://github.com/devtron-labs/devtron/issues/[0-9]+)"
54+
55+
### For ex: Fixes devtron-labs/devtron#2123
56+
pattern3="((Fixes|Resolves) devtron-labs/devtron#[0-9]+)"
57+
4958
# Get the pull request body
5059
PR_BODY=$(jq -r '.pull_request.body' $GITHUB_EVENT_PATH)
5160
echo "PR_BODY = $PR_BODY"
5261
53-
### Checks if PR_BODY has Fixes #<issue_number> or not
62+
### Checks if PR_BODY matches pattern1 or pattern2 or pattern3 or none
5463
### grep -i (case insensitive) -E (enables extended regular expression in grep) -q (this option suppresses normal output)
55-
if echo "$PR_BODY" | grep -iEq "$pattern"; then
56-
# if [[ "$PR_BODY" =~ "$pattern" ]]; then
64+
if echo "$PR_BODY" | grep -iEq "$pattern1"; then
5765
### Here we are taking only the numerical value ie. issue number
5866
### head -n1 only prints the 1st line.
5967
### grep -o -E "[0-9]+ basically outputs only the number between [0-9]+
60-
issue_num=$(echo "$PR_BODY" | grep -iE "$pattern" | head -n1 | grep -o -E "[0-9]+")
68+
echo "$PR_BODY" | grep -iE "$pattern1" | head -n1 | grep -o -E "[0-9]+" | tr -d '\r\n' > issue_num
69+
issue_num=$(cat issue_num)
70+
echo "issue_num is : $issue_num"
71+
elif echo "$PR_BODY" | grep -iEq "$pattern2"; then
72+
echo "$PR_BODY" | grep -iE "$pattern2" | head -n1 | awk -F '/' '{print $NF}' | tr -d '\r\n' > issue_num
73+
issue_num=$(cat issue_num)
74+
echo "issue_num is : $issue_num"
75+
elif echo "$PR_BODY" | grep -iEq "$pattern3"; then
76+
echo "$PR_BODY" | grep -iE "$pattern3" | head -n1 | awk -F '#' '{print $NF}' | tr -d '\r\n' > issue_num
77+
issue_num=$(cat issue_num)
6178
echo "issue_num is : $issue_num"
6279
else
6380
echo "No Issue number detected hence failing the PR Validation check."

0 commit comments

Comments
 (0)