|
2 | 2 | import datetime |
3 | 3 | import json |
4 | 4 | import logging |
| 5 | +import re |
5 | 6 |
|
6 | 7 | # Third party imports |
7 | 8 | from django.contrib import messages |
8 | 9 | from django.contrib.admin.utils import NestedObjects |
9 | 10 | from django.core.exceptions import PermissionDenied |
10 | 11 | from django.db import DEFAULT_DB_ALIAS |
| 12 | +from django.db.models import Q |
11 | 13 | from django.http import Http404, HttpResponse, HttpResponseRedirect |
12 | 14 | from django.shortcuts import get_object_or_404, render |
13 | 15 | from django.urls import reverse |
@@ -212,8 +214,8 @@ def check_for_and_create_comment(parsed_json): |
212 | 214 | comment = parsed_json.get("comment", None) |
213 | 215 | if comment is None: |
214 | 216 | return None |
215 | | - |
216 | 217 | comment_text = comment.get("body") |
| 218 | + comment_text_without_defectdojo_user = re.sub(r"^\(.*?\):\s*", "", comment_text) |
217 | 219 | commenter = "" |
218 | 220 | if "name" in comment.get("updateAuthor"): |
219 | 221 | commenter = comment.get("updateAuthor", {}).get("name") |
@@ -255,10 +257,9 @@ def check_for_and_create_comment(parsed_json): |
255 | 257 | entry = f"({commenter_display_name} ({commenter})): {comment_text}" |
256 | 258 | # Iterate (potentially) over each of the findings the note should be added to |
257 | 259 | for finding in findings: |
258 | | - # Determine if this exact note was created within the last 30 seconds to avoid duplicate notes |
| 260 | + # Determine if the same note body was created by either DefectDojo or Jira |
259 | 261 | existing_notes = finding.notes.filter( |
260 | | - entry=entry, |
261 | | - author=author, |
| 262 | + Q(entry__icontains=comment_text_without_defectdojo_user) | Q(entry__icontains=entry), |
262 | 263 | date__gte=(timezone.now() - datetime.timedelta(seconds=30)), |
263 | 264 | ) |
264 | 265 | # Check the query for any hits |
|
0 commit comments