Skip to content

Commit 890af82

Browse files
build: do not close tracking issues
PR-URL: #3106 Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]> Reviewed-by: Snehil Shah <[email protected]>
1 parent 92b2038 commit 890af82

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

.github/workflows/generate_pr_commit_message.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,21 @@ jobs:
7070
id: commit_message
7171
run: |
7272
COMMIT_MESSAGE=$($GITHUB_WORKSPACE/.github/workflows/scripts/generate_pr_commit_message $PR_NUMBER)
73+
EXIT_CODE=$?
74+
7375
echo "commit_message<<EOF" >> $GITHUB_OUTPUT
7476
echo "$COMMIT_MESSAGE" >> $GITHUB_OUTPUT
7577
echo "EOF" >> $GITHUB_OUTPUT
7678
79+
if [ $EXIT_CODE -eq 200 ]; then
80+
echo "has_tracking_issue=true" >> $GITHUB_OUTPUT
81+
else
82+
echo "has_tracking_issue=false" >> $GITHUB_OUTPUT
83+
fi
84+
85+
# Ensure the script itself doesn't fail the workflow:
86+
exit 0
87+
7788
# Post commit message as PR comment:
7889
- name: 'Post commit message as PR comment'
7990
uses: peter-evans/create-or-update-comment@v4
@@ -88,3 +99,5 @@ jobs:
8899
```
89100
90101
*Please review the above commit message and make any necessary adjustments.*
102+
103+
${{ steps.commit_message.outputs.has_tracking_issue == 'true' && '⚠️ **Action Required**: This PR references tracking issues. Please update the PR description to replace any "Closes", "Fixes", or "Resolves" keywords with "Ref" when referencing these issues.' || '' }}

.github/workflows/scripts/generate_pr_commit_message

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ GITHUB_API_URL="https://api.github.com"
4545
REPO_OWNER="stdlib-js"
4646
REPO_NAME="stdlib"
4747

48+
# Exit codes
49+
SUCCESS=0
50+
ERROR=1
51+
TRACKING_ISSUE_FOUND=200
52+
4853

4954
# FUNCTIONS #
5055

@@ -126,12 +131,12 @@ github_api() {
126131
else
127132
# Handle cases where POST data is required but not provided:
128133
echo "POST request requires data."
129-
on_error 1
134+
on_error $ERROR
130135
fi
131136
;;
132137
*)
133138
echo "Invalid HTTP method: $method"
134-
on_error 1
139+
on_error $ERROR
135140
;;
136141
esac
137142
}
@@ -226,8 +231,17 @@ main() {
226231
# Create a regex pattern from the keywords:
227232
keywords_pattern=$(IFS='|'; echo "${closing_keywords[*]}")
228233

234+
EXIT_CODE=$SUCCESS
229235
for issue in $issue_numbers; do
230-
if echo "$pr_body" | grep -Eiq "(${keywords_pattern})([[:space:]]+|:)[[:space:]]*#${issue}\b"; then
236+
# Fetch issue labels:
237+
issue_details=$(github_api "GET" "/repos/$REPO_OWNER/$REPO_NAME/issues/$issue")
238+
issue_labels=$(echo "$issue_details" | jq -r '.labels[].name')
239+
240+
# Check if the issue is a tracking issue:
241+
if echo "$issue_labels" | grep -q "Tracking Issue"; then
242+
EXIT_CODE=$TRACKING_ISSUE_FOUND
243+
ref_issues+="Ref: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
244+
elif echo "$pr_body" | grep -Eiq "(${keywords_pattern})([[:space:]]+|:)[[:space:]]*#${issue}\b"; then
231245
closes_issues+="Closes: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
232246
else
233247
ref_issues+="Ref: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
@@ -265,6 +279,9 @@ main() {
265279

266280
# Output the commit message:
267281
echo -e "$commit_message"
282+
283+
# Return successful exit code (200 if a tracking issue was found, 0 otherwise):
284+
return $EXIT_CODE
268285
}
269286

270287
# Call main with all command-line arguments:

0 commit comments

Comments
 (0)