Skip to content

Commit 51c70e8

Browse files
authored
Jira webhook comment duplicate patch (#12333)
* Jira Webhooks: Prevent duplicate comments from dojo * Remove excessive logging * Fix ruff
1 parent c15e604 commit 51c70e8

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

dojo/jira_link/views.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import datetime
33
import json
44
import logging
5+
import re
56

67
# Third party imports
78
from django.contrib import messages
89
from django.contrib.admin.utils import NestedObjects
910
from django.core.exceptions import PermissionDenied
1011
from django.db import DEFAULT_DB_ALIAS
12+
from django.db.models import Q
1113
from django.http import Http404, HttpResponse, HttpResponseRedirect
1214
from django.shortcuts import get_object_or_404, render
1315
from django.urls import reverse
@@ -212,8 +214,8 @@ def check_for_and_create_comment(parsed_json):
212214
comment = parsed_json.get("comment", None)
213215
if comment is None:
214216
return None
215-
216217
comment_text = comment.get("body")
218+
comment_text_without_defectdojo_user = re.sub(r"^\(.*?\):\s*", "", comment_text)
217219
commenter = ""
218220
if "name" in comment.get("updateAuthor"):
219221
commenter = comment.get("updateAuthor", {}).get("name")
@@ -255,10 +257,9 @@ def check_for_and_create_comment(parsed_json):
255257
entry = f"({commenter_display_name} ({commenter})): {comment_text}"
256258
# Iterate (potentially) over each of the findings the note should be added to
257259
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
259261
existing_notes = finding.notes.filter(
260-
entry=entry,
261-
author=author,
262+
Q(entry__icontains=comment_text_without_defectdojo_user) | Q(entry__icontains=entry),
262263
date__gte=(timezone.now() - datetime.timedelta(seconds=30)),
263264
)
264265
# Check the query for any hits

0 commit comments

Comments
 (0)