Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions .github/scripts/handle_warning_violations.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
set -eou pipefail

echo "Handle Warning Violations: WARNING_COUNT=${WARNING_COUNT}"
if [ "${WARNING_COUNT}" -eq 0 ]; then
echo "No warning violations found, skipping ticket creation"
exit 0
Expand All @@ -17,7 +18,8 @@ if [ -f "tools/spectral/ipa/metrics/outputs/warning-violations.json" ]; then
fi

# Check if warning ticket already exists
EXISTING_TICKET=$(curl -s -H "Authorization: Bearer ${JIRA_API_TOKEN}" \
echo "Check if a jira ticket already exists."
EXISTING_TICKET=$(curl -H "Authorization: Bearer ${JIRA_API_TOKEN}" \
"https://jira.mongodb.org/rest/api/2/search?jql=project=CLOUDP AND summary~'Warning-level IPA violations' AND status!=Done" \
| jq -r '.issues[0].key // empty')

Expand All @@ -26,6 +28,7 @@ if [ -n "${EXISTING_TICKET}" ]; then
exit 0
fi


# Create detailed description
DESCRIPTION="Warning-level violations were found during IPA validation. Please review and add exceptions if valid, or address false positives.
These warning-level checks are part of the rule rollout process. See the IPA Validation Technical Documentation for details:
Expand All @@ -36,8 +39,9 @@ ${VIOLATION_DETAILS}

Total violations: ${WARNING_COUNT}"

echo "Jira ticket does not exists. Creating..."
# Create new Jira ticket
TICKET_RESPONSE=$(curl -s -X POST -H "Authorization: Bearer ${JIRA_API_TOKEN}" \
TICKET_RESPONSE=$(curl -X POST -H "Authorization: Bearer ${JIRA_API_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"fields\": {
Expand All @@ -51,19 +55,19 @@ TICKET_RESPONSE=$(curl -s -X POST -H "Authorization: Bearer ${JIRA_API_TOKEN}" \
"https://jira.mongodb.org/rest/api/2/issue/")

TICKET_KEY=$(echo "${TICKET_RESPONSE}" | jq -r '.key')

if [ "${TICKET_KEY}" != "null" ]; then
echo "Created Jira ticket: ${TICKET_KEY}"

echo "Created Jira ticket: ${TICKET_KEY}."
# Create summary for Slack
echo "Creating Slack Summary with VIOLATION_DETAILS: ${VIOLATION_DETAILS}..."
SLACK_SUMMARY=""
if [ -n "${VIOLATION_DETAILS}" ]; then
SLACK_SUMMARY=$(echo "${VIOLATION_DETAILS}" | head -3)
if [ "$(echo "${VIOLATION_DETAILS}" | wc -l)" -gt 3 ]; then
SLACK_SUMMARY="${SLACK_SUMMARY}\n... and more"
fi
fi


echo "Send Slack notification..."
# Send Slack notification with violation summary
SLACK_MESSAGE="Warning-level IPA violations found (${WARNING_COUNT} violations) (${SLACK_ONCALL_USER}).

Expand All @@ -76,4 +80,4 @@ Jira ticket: https://jira.mongodb.org/browse/${TICKET_KEY}"
else
echo "Failed to create Jira ticket"
exit 1
fi
fi