Skip to content

Commit

Permalink
build: do not close tracking issues
Browse files Browse the repository at this point in the history
PR-URL: stdlib-js#3106

Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Snehil Shah <[email protected]>
  • Loading branch information
gunjjoshi and Planeshifter authored Nov 28, 2024
1 parent 92b2038 commit 890af82
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/generate_pr_commit_message.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,21 @@ jobs:
id: commit_message
run: |
COMMIT_MESSAGE=$($GITHUB_WORKSPACE/.github/workflows/scripts/generate_pr_commit_message $PR_NUMBER)
EXIT_CODE=$?
echo "commit_message<<EOF" >> $GITHUB_OUTPUT
echo "$COMMIT_MESSAGE" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
if [ $EXIT_CODE -eq 200 ]; then
echo "has_tracking_issue=true" >> $GITHUB_OUTPUT
else
echo "has_tracking_issue=false" >> $GITHUB_OUTPUT
fi
# Ensure the script itself doesn't fail the workflow:
exit 0
# Post commit message as PR comment:
- name: 'Post commit message as PR comment'
uses: peter-evans/create-or-update-comment@v4
Expand All @@ -88,3 +99,5 @@ jobs:
```
*Please review the above commit message and make any necessary adjustments.*
${{ 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.' || '' }}
23 changes: 20 additions & 3 deletions .github/workflows/scripts/generate_pr_commit_message
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ GITHUB_API_URL="https://api.github.com"
REPO_OWNER="stdlib-js"
REPO_NAME="stdlib"

# Exit codes
SUCCESS=0
ERROR=1
TRACKING_ISSUE_FOUND=200


# FUNCTIONS #

Expand Down Expand Up @@ -126,12 +131,12 @@ github_api() {
else
# Handle cases where POST data is required but not provided:
echo "POST request requires data."
on_error 1
on_error $ERROR
fi
;;
*)
echo "Invalid HTTP method: $method"
on_error 1
on_error $ERROR
;;
esac
}
Expand Down Expand Up @@ -226,8 +231,17 @@ main() {
# Create a regex pattern from the keywords:
keywords_pattern=$(IFS='|'; echo "${closing_keywords[*]}")

EXIT_CODE=$SUCCESS
for issue in $issue_numbers; do
if echo "$pr_body" | grep -Eiq "(${keywords_pattern})([[:space:]]+|:)[[:space:]]*#${issue}\b"; then
# Fetch issue labels:
issue_details=$(github_api "GET" "/repos/$REPO_OWNER/$REPO_NAME/issues/$issue")
issue_labels=$(echo "$issue_details" | jq -r '.labels[].name')

# Check if the issue is a tracking issue:
if echo "$issue_labels" | grep -q "Tracking Issue"; then
EXIT_CODE=$TRACKING_ISSUE_FOUND
ref_issues+="Ref: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
elif echo "$pr_body" | grep -Eiq "(${keywords_pattern})([[:space:]]+|:)[[:space:]]*#${issue}\b"; then
closes_issues+="Closes: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
else
ref_issues+="Ref: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
Expand Down Expand Up @@ -265,6 +279,9 @@ main() {

# Output the commit message:
echo -e "$commit_message"

# Return successful exit code (200 if a tracking issue was found, 0 otherwise):
return $EXIT_CODE
}

# Call main with all command-line arguments:
Expand Down

0 comments on commit 890af82

Please sign in to comment.