Skip to content

Commit f4748d2

Browse files
committed
Add files for static analysis
Fixed the workflow expression injection in actions issue and added the CLI to interact with the BugSpots tool. related: adoptium/aqa-tests#6272 Signed-off-by: Anirudh Sengar <anirudhsengar3@gmail.com>
1 parent bf7900f commit f4748d2

1 file changed

Lines changed: 37 additions & 23 deletions

File tree

.github/workflows/gw_comment_trigger.yml

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,26 @@ jobs:
1919
steps:
2020
- name: Parse comment
2121
id: parse
22+
env:
23+
COMMENT_BODY: ${{ github.event.comment.body }}
2224
run: |
23-
comment_body="${{ github.event.comment.body }}"
24-
echo "Comment body: $comment_body"
25+
echo "Comment body: $COMMENT_BODY"
2526
26-
# Extract repository URL
27-
repo_url=$(echo "$comment_body" | grep -oP 'gw --repo \K[^\s]+' || echo "")
27+
# Extract repository URL using environment variable
28+
repo_url=$(echo "$COMMENT_BODY" | grep -oP 'gw --repo \K[^\s]+' || echo "")
2829
if [ -z "$repo_url" ]; then
2930
echo "Error: No repository URL found in comment"
3031
exit 1
3132
fi
3233
34+
# Validate repository URL format
35+
if ! echo "$repo_url" | grep -qE '^https://github\.com/[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+/?$'; then
36+
echo "Error: Invalid repository URL format. Must be a GitHub repository URL."
37+
exit 1
38+
fi
39+
3340
# Extract limit with improved regex and validation
34-
limit_raw=$(echo "$comment_body" | grep -oP -- '--limit\s+\K\d+' || echo "")
41+
limit_raw=$(echo "$COMMENT_BODY" | grep -oP -- '--limit\s+\K\d+' || echo "")
3542
3643
# Validate and set limit (default to 10 if not specified or invalid)
3744
if [ -n "$limit_raw" ] && [ "$limit_raw" -gt 0 ] && [ "$limit_raw" -le 100 ]; then
@@ -69,15 +76,20 @@ jobs:
6976
- name: Run Bugspots Comment Analyzer
7077
id: bugspots
7178
continue-on-error: true
79+
env:
80+
REPO_URL: ${{ needs.parse-comment.outputs.repo_url }}
81+
LIMIT: ${{ needs.parse-comment.outputs.limit }}
7282
run: |
73-
chmod +x BugPredict/gw.sh
74-
# Run the script and capture the exit code
75-
./BugPredict/gw.sh "${{ needs.parse-comment.outputs.repo_url }}" "${{ needs.parse-comment.outputs.limit }}"
83+
chmod +x gw.sh
84+
# Run the script with environment variables to prevent injection
85+
./gw.sh "$REPO_URL" "$LIMIT"
7686
7787
- name: Check for repository errors
7888
id: check-errors
89+
env:
90+
REPO_URL: ${{ needs.parse-comment.outputs.repo_url }}
7991
run: |
80-
repo_name=$(basename "${{ needs.parse-comment.outputs.repo_url }}" .git)
92+
repo_name=$(basename "$REPO_URL" .git)
8193
8294
# Check if the bugspots step failed
8395
if [ "${{ steps.bugspots.outcome }}" = "failure" ]; then
@@ -104,17 +116,17 @@ jobs:
104116
105117
- name: Prepare error comment
106118
if: steps.check-errors.outputs.analysis_failed == 'true'
119+
env:
120+
REPO_URL: ${{ needs.parse-comment.outputs.repo_url }}
121+
ERROR_TYPE: ${{ steps.check-errors.outputs.error_type }}
107122
run: |
108-
repo_url="${{ needs.parse-comment.outputs.repo_url }}"
109-
error_type="${{ steps.check-errors.outputs.error_type }}"
110-
111123
echo "## ❌ Repository Analysis Failed" > comment.md
112124
echo "" >> comment.md
113-
echo "**Repository:** \`$repo_url\`" >> comment.md
125+
echo "**Repository:** \`$REPO_URL\`" >> comment.md
114126
echo "**Analysis Date:** $(date '+%Y-%m-%d %H:%M:%S UTC')" >> comment.md
115127
echo "" >> comment.md
116128
117-
case "$error_type" in
129+
case "$ERROR_TYPE" in
118130
"clone_failed")
119131
echo "### 🚫 Invalid Repository" >> comment.md
120132
echo "" >> comment.md
@@ -143,7 +155,7 @@ jobs:
143155
echo "" >> comment.md
144156
echo "**Error:** An unexpected error occurred during analysis." >> comment.md
145157
echo "" >> comment.md
146-
repo_name=$(basename "$repo_url" .git)
158+
repo_name=$(basename "$REPO_URL" .git)
147159
if [ -f "bugspots-results/bugspots-${repo_name}.err" ]; then
148160
echo "**Error details:**" >> comment.md
149161
echo '```' >> comment.md
@@ -162,16 +174,18 @@ jobs:
162174
163175
- name: Prepare success comment
164176
if: steps.check-errors.outputs.analysis_failed == 'false'
177+
env:
178+
REPO_URL: ${{ needs.parse-comment.outputs.repo_url }}
179+
LIMIT: ${{ needs.parse-comment.outputs.limit }}
165180
run: |
166-
repo_name=$(basename "${{ needs.parse-comment.outputs.repo_url }}" .git)
167-
limit="${{ needs.parse-comment.outputs.limit }}"
181+
repo_name=$(basename "$REPO_URL" .git)
168182
169183
if [ -f "bugspots-results/bugspots-${repo_name}.log" ] && [ -s "bugspots-results/bugspots-${repo_name}.log" ]; then
170184
# Parse the bugspots output to extract hotspots
171185
if grep -q "Hotspots:" "bugspots-results/bugspots-${repo_name}.log"; then
172186
echo "## 🎯 Bugspots Analysis Results" > comment.md
173187
echo "" >> comment.md
174-
echo "**Repository:** \`${{ needs.parse-comment.outputs.repo_url }}\`" >> comment.md
188+
echo "**Repository:** \`$REPO_URL\`" >> comment.md
175189
echo "**Analysis Date:** $(date '+%Y-%m-%d %H:%M:%S UTC')" >> comment.md
176190
echo "" >> comment.md
177191
@@ -182,11 +196,11 @@ jobs:
182196
echo "**Analysis Summary:**" >> comment.md
183197
echo "- Found **${bugfix_commits}** bugfix commits" >> comment.md
184198
echo "- Identified **${total_hotspots}** total hotspots" >> comment.md
185-
echo "- Showing top **${limit}** files most likely to contain bugs" >> comment.md
199+
echo "- Showing top **${LIMIT}** files most likely to contain bugs" >> comment.md
186200
echo "" >> comment.md
187201
188202
# Extract hotspots section and get top N entries
189-
echo "### 🔥 Top ${limit} Hotspots" >> comment.md
203+
echo "### 🔥 Top ${LIMIT} Hotspots" >> comment.md
190204
echo "" >> comment.md
191205
echo '```' >> comment.md
192206
echo "Score File" >> comment.md
@@ -199,7 +213,7 @@ jobs:
199213
# Fallback to manual extraction
200214
sed -n '/Hotspots:/,/^$/p' "bugspots-results/bugspots-${repo_name}.log" | \
201215
grep -E '^\s*[0-9]+\.[0-9]+.*' | \
202-
head -n "$limit" | \
216+
head -n "$LIMIT" | \
203217
sed 's/^\s*//' >> comment.md
204218
fi
205219
@@ -212,7 +226,7 @@ jobs:
212226
# No hotspots section found
213227
echo "## ⚠️ Bugspots Analysis Results" > comment.md
214228
echo "" >> comment.md
215-
echo "**Repository:** \`${{ needs.parse-comment.outputs.repo_url }}\`" >> comment.md
229+
echo "**Repository:** \`$REPO_URL\`" >> comment.md
216230
echo "**Analysis Date:** $(date '+%Y-%m-%d %H:%M:%S UTC')" >> comment.md
217231
echo "" >> comment.md
218232
echo "### 📭 No Hotspots Found" >> comment.md
@@ -232,7 +246,7 @@ jobs:
232246
else
233247
echo "## ⚠️ Bugspots Analysis Results" > comment.md
234248
echo "" >> comment.md
235-
echo "**Repository:** \`${{ needs.parse-comment.outputs.repo_url }}\`" >> comment.md
249+
echo "**Repository:** \`$REPO_URL\`" >> comment.md
236250
echo "**Analysis Date:** $(date '+%Y-%m-%d %H:%M:%S UTC')" >> comment.md
237251
echo "" >> comment.md
238252
echo "### 📭 No Results Found" >> comment.md

0 commit comments

Comments
 (0)