-
Notifications
You must be signed in to change notification settings - Fork 14
ci(ipa): automatic warning-level violation detection #905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2941b14
ci(ipa): automatic warning-level violation detection
yelizhenden-mdb 0755b8f
Merge branch 'main' into CLOUDP-310539-warning-detection
yelizhenden-mdb 3fc2a28
update slack channel and jira team
yelizhenden-mdb 5afdba8
fix
yelizhenden-mdb 0adaa42
fix
yelizhenden-mdb 85158b2
prettier fix
yelizhenden-mdb 31a11b5
shellcheck fixes
yelizhenden-mdb b5bc24e
tag the oncall person to the slack message
yelizhenden-mdb 3442793
tag the oncall person to the slack message
yelizhenden-mdb 953977c
remove unneeded fields
yelizhenden-mdb 3406dbe
address the comments
yelizhenden-mdb aaa2202
comment out git workflow step
yelizhenden-mdb 1697e77
enablement note
yelizhenden-mdb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
set -eou pipefail | ||
|
||
if [ "${WARNING_COUNT}" -eq 0 ]; then | ||
echo "No warning violations found, skipping ticket creation" | ||
exit 0 | ||
fi | ||
|
||
# Read violation details if available | ||
VIOLATION_DETAILS="" | ||
if [ -f "tools/spectral/ipa/metrics/outputs/warning-violations.json" ]; then | ||
VIOLATION_DETAILS=$(jq -r ' | ||
group_by(.code) | | ||
map("• " + .[0].code + " (" + (length | tostring) + " violations)") | | ||
join("\n") | ||
' tools/spectral/ipa/metrics/outputs/warning-violations.json) | ||
fi | ||
|
||
# Check if warning ticket already exists | ||
EXISTING_TICKET=$(curl -s -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') | ||
|
||
if [ -n "${EXISTING_TICKET}" ]; then | ||
echo "Warning ticket already exists: ${EXISTING_TICKET}" | ||
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: | ||
https://wiki.corp.mongodb.com/spaces/MMS/pages/315003555/IPA+Validation+Technical+Documentation+Runbook#IPAValidationTechnicalDocumentation%26Runbook-RolloutofNewRule | ||
|
||
Violation Summary: | ||
${VIOLATION_DETAILS} | ||
|
||
Total violations: ${WARNING_COUNT}" | ||
|
||
# Create new Jira ticket | ||
TICKET_RESPONSE=$(curl -s -X POST -H "Authorization: Bearer ${JIRA_API_TOKEN}" \ | ||
-H "Content-Type: application/json" \ | ||
-d "{ | ||
\"fields\": { | ||
\"project\": {\"key\": \"CLOUDP\"}, | ||
\"summary\": \"Warning-level IPA violations found\", | ||
\"description\": \"${DESCRIPTION}\", | ||
\"issuetype\": {\"name\": \"Task\"}, | ||
\"assignee\": {\"id\": \"${TEAM_ID}\"} | ||
} | ||
}" \ | ||
"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}" | ||
|
||
# Create summary for Slack | ||
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 | ||
|
||
# Send Slack notification with violation summary | ||
SLACK_MESSAGE="Warning-level IPA violations found (${WARNING_COUNT} violations) (${SLACK_ONCALL_USER}). | ||
|
||
Jira ticket: https://jira.mongodb.org/browse/${TICKET_KEY}" | ||
|
||
curl -X POST -H "Authorization: Bearer ${SLACK_BEARER_TOKEN}" \ | ||
-H "Content-type: application/json" \ | ||
--data "{\"channel\":\"${SLACK_CHANNEL_ID}\",\"text\":\"${SLACK_MESSAGE}\"}" \ | ||
https://slack.com/api/chat.postMessage | ||
else | ||
echo "Failed to create Jira ticket" | ||
exit 1 | ||
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
tools/spectral/ipa/__tests__/metrics/data/collector-results.log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,762 changes: 1,761 additions & 1 deletion
1,762
tools/spectral/ipa/__tests__/metrics/data/expected-metric-results.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can link to the IPA wiki with the rollout process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added! Let me know how it sounds