|
4 | 4 | import os |
5 | 5 | from string import Template |
6 | 6 |
|
| 7 | +from .code_quality import Finding |
7 | 8 | from .exceptions import WarningsConfigError |
8 | 9 | from .warnings_checker import WarningsChecker |
9 | 10 |
|
@@ -215,44 +216,29 @@ def add_code_quality_finding(self, row): |
215 | 216 | Args: |
216 | 217 | row (dict): The row of the warning with the corresponding colomn names |
217 | 218 | ''' |
218 | | - finding = { |
219 | | - "severity": "major", |
220 | | - "location": { |
221 | | - "path": self.cq_default_path, |
222 | | - "positions": { |
223 | | - "begin": { |
224 | | - "line": 1, |
225 | | - "column": 1 |
226 | | - } |
227 | | - } |
228 | | - } |
229 | | - } |
230 | | - |
231 | 219 | try: |
232 | 220 | description = self.cq_description_template.substitute(os.environ, **row) |
233 | 221 | except KeyError as err: |
234 | 222 | raise WarningsConfigError(f"Failed to find environment variable from configuration value " |
235 | 223 | f"'cq_description_template': {err}") from err |
236 | 224 |
|
| 225 | + finding = Finding(description) |
237 | 226 | # Attention to bug finder: items have color red for impact: high, medium and low. |
238 | 227 | if row["information"].lower() in self.code_quality_severity.keys(): |
239 | | - finding["severity"] = self.code_quality_severity[row["information"].lower()] |
| 228 | + finding.severity = self.code_quality_severity[row["information"].lower()] |
240 | 229 | elif row["color"].lower() in self.code_quality_severity.keys(): |
241 | | - finding["severity"] = self.code_quality_severity[row["color"].lower()] |
| 230 | + finding.severity = self.code_quality_severity[row["color"].lower()] |
242 | 231 | else: |
243 | | - finding["severity"] = "info" |
| 232 | + finding.severity = "info" |
244 | 233 |
|
245 | 234 | if row["file"]: |
246 | | - finding["location"]["path"] = row["file"] |
| 235 | + finding.path = row["file"] |
247 | 236 | if "line" in row: |
248 | | - finding["location"]["positions"]["begin"]["line"] = int(row["line"]) |
| 237 | + finding.line = int(row["line"]) |
249 | 238 | if "col" in row: |
250 | | - finding["location"]["positions"]["begin"]["column"] = int(row["col"]) |
251 | | - finding["description"] = description |
252 | | - exclude = ("new", "status", "severity", "comment", "key") |
253 | | - row_without_key = [value for key, value in row.items() if key not in exclude] |
254 | | - finding["fingerprint"] = hashlib.md5(str(row_without_key).encode('utf-8')).hexdigest() |
255 | | - self.cq_findings.append(finding) |
| 239 | + finding.column = int(row["col"]) |
| 240 | + |
| 241 | + self.cq_findings.append(finding.to_dict()) |
256 | 242 |
|
257 | 243 | def check(self, content): |
258 | 244 | ''' |
|
0 commit comments