@@ -701,6 +701,11 @@ def jira_get_resolution_id(jira, issue, status):
701701def jira_change_resolution_id (jira , issue , id ):
702702 jira .transition_issue (issue , id )
703703
704+ # Logs the error to the alerts table, which appears in the notification toolbar
705+ def log_jira_generic_alert (title , description ):
706+ create_notification (event = 'jira_update' , title = title , description = description ,
707+ icon = 'bullseye' , source = 'Jira' )
708+
704709# Logs the error to the alerts table, which appears in the notification toolbar
705710def log_jira_alert (error , finding ):
706711 create_notification (event = 'jira_update' , title = 'Jira update issue' , description = 'Finding: ' + str (finding .id ) + ', ' + error ,
@@ -856,22 +861,30 @@ def close_epic(eng, push_to_jira):
856861 jpkey = JIRA_PKey .objects .get (product = prod )
857862 jira_conf = jpkey .conf
858863 if jpkey .enable_engagement_epic_mapping and push_to_jira :
859- j_issue = JIRA_Issue .objects .get (engagement = eng )
860- req_url = jira_conf .url + '/rest/api/latest/issue/' + j_issue .jira_id + '/transitions'
861- j_issue = JIRA_Issue .objects .get (engagement = eng )
862- json_data = {'transition' :{'id' :jira_conf .close_status_key }}
863- r = requests .post (url = req_url , auth = HTTPBasicAuth (jira_conf .username , jira_conf .password ), json = json_data )
864+ try :
865+ j_issue = JIRA_Issue .objects .get (engagement = eng )
866+ req_url = jira_conf .url + '/rest/api/latest/issue/' + j_issue .jira_id + '/transitions'
867+ j_issue = JIRA_Issue .objects .get (engagement = eng )
868+ json_data = {'transition' :{'id' :jira_conf .close_status_key }}
869+ r = requests .post (url = req_url , auth = HTTPBasicAuth (jira_conf .username , jira_conf .password ), json = json_data )
870+ except Exception as e :
871+ log_jira_generic_alert ('Jira Engagement/Epic Close Error' , e )
872+ pass
864873
865874def update_epic (eng , push_to_jira ):
866875 engagement = eng
867876 prod = Product .objects .get (engagement = engagement )
868877 jpkey = JIRA_PKey .objects .get (product = prod )
869878 jira_conf = jpkey .conf
870879 if jpkey .enable_engagement_epic_mapping and push_to_jira :
871- jira = JIRA (server = jira_conf .url , basic_auth = (jira_conf .username , jira_conf .password ))
872- j_issue = JIRA_Issue .objects .get (engagement = eng )
873- issue = jira .issue (j_issue .jira_id )
874- issue .update (summary = eng .name , description = eng .name )
880+ try :
881+ jira = JIRA (server = jira_conf .url , basic_auth = (jira_conf .username , jira_conf .password ))
882+ j_issue = JIRA_Issue .objects .get (engagement = eng )
883+ issue = jira .issue (j_issue .jira_id )
884+ issue .update (summary = eng .name , description = eng .name )
885+ except Exception as e :
886+ log_jira_generic_alert ('Jira Engagement/Epic Update Error' , e )
887+ pass
875888
876889def add_epic (eng , push_to_jira ):
877890 engagement = eng
@@ -886,19 +899,27 @@ def add_epic(eng, push_to_jira):
886899 'issuetype' : {'name' : 'Epic' },
887900 'customfield_' + str (jira_conf .epic_name_id ) : engagement .name ,
888901 }
889- jira = JIRA (server = jira_conf .url , basic_auth = (jira_conf .username , jira_conf .password ))
890- new_issue = jira .create_issue (fields = issue_dict )
891- j_issue = JIRA_Issue (jira_id = new_issue .id , jira_key = new_issue , engagement = engagement )
892- j_issue .save ()
902+ try :
903+ jira = JIRA (server = jira_conf .url , basic_auth = (jira_conf .username , jira_conf .password ))
904+ new_issue = jira .create_issue (fields = issue_dict )
905+ j_issue = JIRA_Issue (jira_id = new_issue .id , jira_key = new_issue , engagement = engagement )
906+ j_issue .save ()
907+ except Exception as e :
908+ log_jira_generic_alert ('Jira Engagement/Epic Creation Error' , e )
909+ pass
893910
894911def add_comment (find , note , force_push = False ):
895912 prod = Product .objects .get (engagement = Engagement .objects .get (test = find .test ))
896913 jpkey = JIRA_PKey .objects .get (product = prod )
897914 jira_conf = jpkey .conf
898915 if jpkey .push_notes or force_push == True :
899- jira = JIRA (server = jira_conf .url , basic_auth = (jira_conf .username , jira_conf .password ))
900- j_issue = JIRA_Issue .objects .get (finding = find )
901- jira .add_comment (j_issue .jira_id , '(%s): %s' % (note .author .get_full_name (), note .entry ))
916+ try :
917+ jira = JIRA (server = jira_conf .url , basic_auth = (jira_conf .username , jira_conf .password ))
918+ j_issue = JIRA_Issue .objects .get (finding = find )
919+ jira .add_comment (j_issue .jira_id , '(%s): %s' % (note .author .get_full_name (), note .entry ))
920+ except Exception as e :
921+ log_jira_generic_alert ('Jira Add Comment Error' , e )
922+ pass
902923
903924def send_review_email (request , user , finding , users , new_note ):
904925 recipients = [u .email for u in users ]
@@ -1062,15 +1083,15 @@ def create_notification_message(event, notification_type):
10621083 return notification
10631084
10641085 def send_slack_notification (channel ):
1065- # try:
1066- res = requests .request (method = 'POST' , url = 'https://slack.com/api/chat.postMessage' ,
1067- data = {'token' :get_system_setting ('slack_token' ),
1068- 'channel' :channel ,
1069- 'username' :get_system_setting ('slack_username' ),
1070- 'text' :create_notification_message (event , 'slack' )})
1071- # except Exception as e:
1072- # log_alert(e)
1073- # pass
1086+ try :
1087+ res = requests .request (method = 'POST' , url = 'https://slack.com/api/chat.postMessage' ,
1088+ data = {'token' :get_system_setting ('slack_token' ),
1089+ 'channel' :channel ,
1090+ 'username' :get_system_setting ('slack_username' ),
1091+ 'text' :create_notification_message (event , 'slack' )})
1092+ except Exception as e :
1093+ log_alert (e )
1094+ pass
10741095
10751096 def send_hipchat_notification (channel ):
10761097 try :
@@ -1079,7 +1100,6 @@ def send_hipchat_notification(channel):
10791100 url = 'https://%s/v2/room/%s/notification?auth_token=%s' % (get_system_setting ('hipchat_site' ), channel , get_system_setting ('hipchat_token' )),
10801101 data = {'message' :create_notification_message (event , 'slack' ),
10811102 'message_format' :'text' })
1082- print res
10831103 except Exception as e :
10841104 log_alert (e )
10851105 pass
@@ -1110,8 +1130,10 @@ def send_alert_notification(user=None):
11101130
11111131
11121132 def log_alert (e ):
1113- alert = Alerts (user_id = Dojo_User .objects .get (is_superuser = True ), title = 'Notification issue' , description = "%s" % e , icon = "exclamation-triangle" , source = "Notifications" )
1114- alert .save ()
1133+ users = Dojo_User .objects .filter (is_superuser = True )
1134+ for user in users :
1135+ alert = Alerts (user_id = user , url = kwargs .get ('url' , reverse ('alerts' )), title = 'Notification issue' , description = "%s" % e , icon = "exclamation-triangle" , source = "Notifications" )
1136+ alert .save ()
11151137
11161138 # Global notifications
11171139 try :
0 commit comments