-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make SonarQube Parser use creationDate for Date #13919
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| import re | ||
| from datetime import datetime | ||
|
|
||
| import dateutil.parser | ||
|
Maffooch marked this conversation as resolved.
|
||
| from django.utils import timezone | ||
|
|
||
| from dojo.models import Finding | ||
|
|
||
|
|
@@ -23,6 +27,10 @@ | |
| scope = issue.get("scope") | ||
| quickFixAvailable = str(issue.get("quickFixAvailable")) | ||
| codeVariants = str(issue.get("codeVariants")) | ||
| try: | ||
| date = str(dateutil.parser.parse(issue.get("creationDate")).date()) | ||
| except (ValueError, TypeError, dateutil.parser.ParserError): | ||
| date = timezone.now() | ||
|
Comment on lines
+29
to
+32
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a blocker, but could save some repeated code by making this a helper function for all parsers?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this idea! I've got some ideas for parser improvements to discuss with you at some point too. Let's hold on this helper for now |
||
| description = "" | ||
| description += "**key:** " + key + "\n" | ||
| description += "**rule:** " + rule + "\n" | ||
|
|
@@ -50,6 +58,7 @@ | |
| dynamic_finding=False, | ||
| tags=["bug"], | ||
| line=line, | ||
| date=date, | ||
| ) | ||
| elif issue.get("type") == "VULNERABILITY": | ||
| key = issue.get("key") | ||
|
|
@@ -61,6 +70,10 @@ | |
| message = issue.get("message") | ||
| line = issue.get("line") | ||
| cwe = None | ||
| try: | ||
| date = str(dateutil.parser.parse(issue.get("creationDate")).date()) | ||
| except (ValueError, TypeError, dateutil.parser.ParserError): | ||
| date = timezone.now() | ||
| if "Category: CWE-" in message: | ||
| cwe_pattern = r"Category: CWE-\d{1,5}" | ||
| cwes = re.findall(cwe_pattern, message) | ||
|
|
@@ -119,6 +132,7 @@ | |
| file_path=component, | ||
| tags=["vulnerability"], | ||
| line=line, | ||
| date=date, | ||
| ) | ||
| vulnids = [] | ||
| if "Reference: CVE" in message: | ||
|
|
@@ -154,6 +168,10 @@ | |
| scope = issue.get("scope") | ||
| quickFixAvailable = str(issue.get("quickFixAvailable")) | ||
| codeVariants = issue.get("codeVariants", []) | ||
| try: | ||
| date = str(dateutil.parser.parse(issue.get("creationDate")).date()) | ||
| except (ValueError, TypeError, dateutil.parser.ParserError): | ||
| date = timezone.now() | ||
| description = "" | ||
| description += "**rule:** " + rule + "\n" | ||
| description += "**component:** " + component + "\n" | ||
|
|
@@ -185,6 +203,7 @@ | |
| file_path=component, | ||
| tags=["code_smell"], | ||
| line=line, | ||
| date=date, | ||
| ) | ||
| items.append(item) | ||
| if json_content.get("hotspots"): | ||
|
|
@@ -200,6 +219,10 @@ | |
| flows = hotspot.get("flows", []) | ||
| ruleKey = hotspot.get("ruleKey") | ||
| messageFormattings = hotspot.get("messageFormattings", []) | ||
| try: | ||
| date = str(dateutil.parser.parse(hotspot.get("creationDate")).date()) | ||
| except (ValueError, TypeError, dateutil.parser.ParserError): | ||
| date = timezone.now() | ||
| description = "" | ||
| description += "**key:** " + key + "\n" | ||
| description += "**component:** " + component + "\n" | ||
|
|
@@ -229,6 +252,7 @@ | |
| file_path=component, | ||
| tags=["hotspot"], | ||
| line=line, | ||
| date=date, | ||
| ) | ||
| items.append(item) | ||
| return items | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.