1+ #! /bin/bash
2+ set  -eou pipefail
3+ 
4+ if  [ " ${WARNING_COUNT} "   -eq  0 ];  then 
5+   echo  " No warning violations found, skipping ticket creation" 
6+   exit  0
7+ fi 
8+ 
9+ #  Read violation details if available
10+ VIOLATION_DETAILS=" " 
11+ if  [ -f  " tools/spectral/ipa/metrics/outputs/warning-violations.json"   ];  then 
12+   VIOLATION_DETAILS=$( jq -r ' 
13+     group_by(.code) |  
14+     map("• " + .[0].code + " (" + (length | tostring) + " violations)") |  
15+     join("\n") 
16+   '   tools/spectral/ipa/metrics/outputs/warning-violations.json) 
17+ fi 
18+ 
19+ #  Check if warning ticket already exists
20+ EXISTING_TICKET=$( curl -s -H " Authorization: Bearer ${JIRA_API_TOKEN} "   \
21+   " https://jira.mongodb.org/rest/api/2/search?jql=project=CLOUDP AND summary~'Warning-level IPA violations' AND status!=Done"   \ 
22+   |  jq -r ' .issues[0].key // empty' )  
23+ 
24+ if  [ -n  " ${EXISTING_TICKET} "   ];  then 
25+   echo  " Warning ticket already exists: ${EXISTING_TICKET} " 
26+   exit  0
27+ fi 
28+ 
29+ #  Create detailed description
30+ DESCRIPTION=" Warning-level violations were found during IPA validation. Please review and add exceptions if valid, or address false positives.
31+ These warning-level checks are part of the rule rollout process. See the IPA Validation Technical Documentation for details: 
32+ https://wiki.corp.mongodb.com/spaces/MMS/pages/315003555/IPA+Validation+Technical+Documentation+Runbook#IPAValidationTechnicalDocumentation%26Runbook-RolloutofNewRule 
33+ 
34+ Violation Summary: 
35+ ${VIOLATION_DETAILS} 
36+ 
37+ Total violations: ${WARNING_COUNT} "  
38+ 
39+ #  Create new Jira ticket
40+ TICKET_RESPONSE=$( curl -s -X POST -H " Authorization: Bearer ${JIRA_API_TOKEN} "   \
41+   -H " Content-Type: application/json"   \ 
42+   -d " { 
43+     \" fields\" : { 
44+       \" project\" : {\" key\" : \" CLOUDP\" }, 
45+       \" summary\" : \" Warning-level IPA violations found\" , 
46+       \" description\" : \" ${DESCRIPTION} \" , 
47+       \" issuetype\" : {\" name\" : \" Task\" }, 
48+       \" assignee\" : {\" id\" : \" ${TEAM_ID} \" } 
49+     } 
50+   }"   \
51+   " https://jira.mongodb.org/rest/api/2/issue/" )  
52+ 
53+ TICKET_KEY=$( echo " ${TICKET_RESPONSE} "   |  jq -r ' .key' ) 
54+ 
55+ if  [ " ${TICKET_KEY} "   !=  " null"   ];  then 
56+   echo  " Created Jira ticket: ${TICKET_KEY} " 
57+   
58+   #  Create summary for Slack
59+   SLACK_SUMMARY=" " 
60+   if  [ -n  " ${VIOLATION_DETAILS} "   ];  then 
61+     SLACK_SUMMARY=$( echo " ${VIOLATION_DETAILS} "   |  head -3) 
62+     if  [ " $( echo " ${VIOLATION_DETAILS} "   |  wc -l) "   -gt  3 ];  then 
63+       SLACK_SUMMARY=" ${SLACK_SUMMARY} \n... and more" 
64+     fi 
65+   fi 
66+   
67+   #  Send Slack notification with violation summary
68+   SLACK_MESSAGE=" Warning-level IPA violations found (${WARNING_COUNT}  violations) (${SLACK_ONCALL_USER} ).
69+ 
70+ Jira ticket: https://jira.mongodb.org/browse/${TICKET_KEY} "  
71+   
72+   curl -X POST -H " Authorization: Bearer ${SLACK_BEARER_TOKEN} "   \
73+     -H " Content-type: application/json"   \
74+     --data " {\" channel\" :\" ${SLACK_CHANNEL_ID} \" ,\" text\" :\" ${SLACK_MESSAGE} \" }"   \
75+     https://slack.com/api/chat.postMessage
76+ else 
77+   echo  " Failed to create Jira ticket" 
78+   exit  1
79+ fi 
0 commit comments