You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: resolve undefined display in PR comment and improve message handling
This commit addresses the issue where 'undefined' could appear in PR comments posted by the scope check CI.
Fixes include:
- Robust handling of empty PR titles, with specific error messages.
- Sanitization of PR titles to remove potential newline characters from jq output.
- Improved logic for constructing suggestion messages in comments, ensuring variables are correctly handled even if empty.
- Safe multi-line string assignment to GITHUB_ENV for the comment body using heredocs, preventing issues with special characters and newlines.
These changes ensure more reliable and informative feedback in PR comments when scope validation fails.
if [ ${#pr_scopes[@]} -eq 0 ] && [[ "$pr_scopes_str" != "*" ]]; then
46
61
error_message="PR title does not contain a valid scope. Please use the format 'type(scope): message' or 'type(*): message'."
47
62
echo "::error::$error_message"
48
-
comment_body="**Scope Check Failed!** 🚨\n\n${error_message}\n\nExample: \`feat(my-scope): add new feature\` or \`fix(*): resolve an issue\`."
49
-
echo "comment_body=$comment_body" >> $GITHUB_ENV
63
+
comment_body="**Scope Check Failed!** 🚨\n\n${error_message}\n\nTitle received: \`$pr_title\`\n\nExample: \`feat(my-scope): add new feature\` or \`fix(*): resolve an issue\`."
64
+
cat <<EOF_COMMENT > comment_file.txt
65
+
$comment_body
66
+
EOF_COMMENT
67
+
echo "comment_body<<EOF_CMT" >> $GITHUB_ENV
68
+
cat comment_file.txt >> $GITHUB_ENV
69
+
echo "EOF_CMT" >> $GITHUB_ENV
50
70
exit 1
51
71
fi
52
72
echo "PR Scopes: ${pr_scopes[@]}"
@@ -115,16 +135,44 @@ jobs:
115
135
echo "::error::PR title scopes do not cover all changed files. Missing scopes for: ${missing_scopes[@]}"
116
136
# Prepare message for PR comment
117
137
comment_body="**Scope Check Failed!** 🚨\n\nPR title scopes do not cover all changed files.\n\n"
118
-
comment_body+="Missing required scopes in PR title: \`${missing_scopes[@]}\`\n\n"
119
-
comment_body+="Please update your PR title to include these scopes. For example: \`type(${pr_scopes_str:+${pr_scopes_str},}${missing_scopes[@]}): your message\` or \`type(*): your message\` if a wildcard is appropriate.\n\n"
138
+
if [ ${#missing_scopes[@]} -gt 0 ]; then
139
+
comment_body+="Missing required scopes in PR title: \`${missing_scopes[*]}\`\n\n" # Use [*] for space separated, or loop for comma separated
140
+
141
+
suggestion_scopes=""
142
+
if [ -n "$pr_scopes_str" ] && [[ "$pr_scopes_str" != "*" ]]; then
143
+
suggestion_scopes="${pr_scopes_str}"
144
+
fi
145
+
146
+
# Build comma-separated list for suggestion_scopes
147
+
for missing_scope in "${missing_scopes[@]}"; do
148
+
if [ -n "$suggestion_scopes" ]; then
149
+
suggestion_scopes+=","
150
+
fi
151
+
suggestion_scopes+="$missing_scope"
152
+
done
153
+
154
+
comment_body+="Please update your PR title to include these scopes. For example: \`type($suggestion_scopes): your message\` or \`type(*): your message\` if a wildcard is appropriate.\n\n"
0 commit comments