diff --git a/.github/workflows/generate_pr_commit_message.yml b/.github/workflows/generate_pr_commit_message.yml index 51a6b53c9708..c639ddc15699 100644 --- a/.github/workflows/generate_pr_commit_message.yml +++ b/.github/workflows/generate_pr_commit_message.yml @@ -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<> $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 @@ -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.' || '' }} diff --git a/.github/workflows/scripts/generate_pr_commit_message b/.github/workflows/scripts/generate_pr_commit_message index d8b06680adaf..3c60608d1275 100755 --- a/.github/workflows/scripts/generate_pr_commit_message +++ b/.github/workflows/scripts/generate_pr_commit_message @@ -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 # @@ -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 } @@ -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" @@ -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: