Skip to content

Commit 41860d9

Browse files
authored
Enhance recategorization script with error handling
Added error handling for recategorization and ensured jq is installed before filtering SARIF results. Signed-off-by: Saumya Rai <saumya.rai@qorix.ai>
1 parent 3661581 commit 41860d9

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

scripts/workflow/recategorize_guidelines.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,27 @@ python3 "$RECATEGORIZE_SCRIPT" \
2424
"$CODING_STANDARDS_CONFIG" \
2525
"$SARIF_FILE" \
2626
"sarif-results-recategorized/$(basename "$SARIF_FILE")"
27-
rm "$SARIF_FILE"
28-
mv "sarif-results-recategorized/$(basename "$SARIF_FILE")" "$SARIF_FILE"
27+
PY_EXIT=$?
28+
if [ $PY_EXIT -ne 0 ]; then
29+
echo "Recategorization failed (exit code $PY_EXIT). SARIF file not updated." >&2
30+
exit $PY_EXIT
31+
fi
32+
rm "$SARIF_FILE"
33+
mv "sarif-results-recategorized/$(basename "$SARIF_FILE")" "$SARIF_FILE"
2934

35+
# Ensure jq is available
36+
if ! command -v jq >/dev/null 2>&1; then
37+
echo "Error: jq is required but not installed. Please install jq and rerun this script." >&2
38+
exit 1
39+
fi
3040

31-
#adding filters later
41+
# Filter SARIF to only include results from repos/* (relative or absolute)
42+
echo "Filtering SARIF results to only include entries with paths matching (^|/)repos/ ..."
43+
jq '(.runs) |= map(.results |= map(select((.locations // [] | length > 0) and ((.locations[0].physicalLocation.artifactLocation.uri // "") | test("(^|/)repos/")))) )' "$SARIF_FILE" > "${SARIF_FILE}.filtered"
44+
if [ $? -eq 0 ]; then
45+
mv "${SARIF_FILE}.filtered" "$SARIF_FILE"
46+
else
47+
echo "jq filtering failed. SARIF file was not modified." >&2
48+
rm -f "${SARIF_FILE}.filtered"
49+
exit 1
50+
fi

0 commit comments

Comments
 (0)