Skip to content
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

Update helper.py to fix #8785 #8786

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions dojo/jira_link/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
# findings or groups already having an existing jira issue can always be pushed
return True, None, None

if type(obj) == Finding:

Check notice on line 102 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L102

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
if form:
active = form['active'].value()
verified = form['verified'].value()
Expand All @@ -122,7 +122,7 @@
if jira_minimum_threshold and jira_minimum_threshold > Finding.get_number_severity(severity):
logger.debug('Finding below the minimum JIRA severity threshold (%s).' % System_Settings.objects.get().jira_minimum_severity)
return False, 'Finding below the minimum JIRA severity threshold (%s).' % System_Settings.objects.get().jira_minimum_severity, 'below_minimum_threshold'
elif type(obj) == Finding_Group:

Check notice on line 125 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L125

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
if not obj.findings.all():
return False, '%s cannot be pushed to jira as it is empty.' % to_str_typed(obj), 'error_empty'
if 'Active' not in obj.status():
Expand Down Expand Up @@ -521,10 +521,10 @@
labels.append(prod_name_label)

if system_settings.add_vulnerability_id_to_jira_label or jira_project and jira_project.add_vulnerability_id_to_jira_label:
if type(obj) == Finding and obj.vulnerability_ids:

Check notice on line 524 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L524

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
for id in obj.vulnerability_ids:
labels.append(id)
elif type(obj) == Finding_Group:

Check notice on line 527 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L527

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
for finding in obj.findings.all():
for id in finding.vulnerability_ids:
labels.append(id)
Expand All @@ -540,7 +540,7 @@
if obj_tags:
for tag in obj_tags:
tags.append(str(tag.name.replace(' ', '-')))
if type(obj) == Finding_Group:

Check notice on line 543 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L543

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
for finding in obj.findings.all():
obj_tags = finding.tags.all()
if obj_tags:
Expand All @@ -554,10 +554,10 @@
def jira_summary(obj):
summary = ''

if type(obj) == Finding:

Check notice on line 557 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L557

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
summary = obj.title

if type(obj) == Finding_Group:

Check notice on line 560 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L560

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
summary = obj.name

return summary.replace('\r', '').replace('\n', '')[:255]
Expand All @@ -584,9 +584,9 @@


def jira_environment(obj):
if type(obj) == Finding:

Check notice on line 587 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L587

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
return "\n".join([str(endpoint) for endpoint in obj.endpoints.all()])
elif type(obj) == Finding_Group:

Check notice on line 589 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L589

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
return "\n".join([jira_environment(finding) for finding in obj.findings.all()])
else:
return ''
Expand Down Expand Up @@ -660,6 +660,7 @@
environment=None,
priority_name=None,
epic_name_field=None,
default_assignee=None,
duedate=None,
issuetype_fields=[]):

Expand Down Expand Up @@ -691,6 +692,9 @@
if duedate and 'duedate' in issuetype_fields:
fields['duedate'] = duedate.strftime('%Y-%m-%d')

if default_assignee:
fields['assignee'] = {'name': default_assignee}

return fields


Expand All @@ -711,7 +715,7 @@

obj_can_be_pushed_to_jira, error_message, error_code = can_be_pushed_to_jira(obj)
if not obj_can_be_pushed_to_jira:
if type(obj) == Finding and obj.duplicate and not obj.active:

Check notice on line 718 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L718

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
logger.warning("%s will not be pushed to JIRA as it's a duplicate finding", to_str_typed(obj))
else:
log_jira_alert(error_message, obj)
Expand Down Expand Up @@ -745,16 +749,15 @@
priority_name=jira_priority(obj),
epic_name_field=get_epic_name_field_name(jira_instance),
duedate=duedate,
issuetype_fields=issuetype_fields)
issuetype_fields=issuetype_fields,
default_assignee=jira_project.default_assignee)

logger.debug('sending fields to JIRA: %s', fields)
new_issue = jira.create_issue(fields)
if jira_project.default_assignee:
jira.assign_issue(new_issue.key, jira_project.default_assignee)

Maffooch marked this conversation as resolved.
Show resolved Hide resolved

Check notice on line 757 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L757

blank line contains whitespace (W293)
# Upload dojo finding screenshots to Jira
findings = [obj]
if type(obj) == Finding_Group:

Check notice on line 760 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L760

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
findings = obj.findings.all()

for find in findings:
Expand Down Expand Up @@ -876,7 +879,7 @@

# Upload dojo finding screenshots to Jira
findings = [obj]
if type(obj) == Finding_Group:

Check notice on line 882 in dojo/jira_link/helper.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/jira_link/helper.py#L882

do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (E721)
findings = obj.findings.all()

for find in findings:
Expand Down