Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -50,6 +51,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -75,6 +77,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -100,6 +103,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -125,6 +129,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -151,6 +156,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -176,6 +182,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -203,6 +210,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -230,6 +238,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -257,6 +266,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -282,6 +292,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -307,6 +318,7 @@
"name": null,
"scale": "version_number",
"unit": null,
"unit_singular": null,
"evaluate_targets": false,
"accept_debt": false,
"debt_target": null,
Expand Down
22 changes: 22 additions & 0 deletions components/api_server/src/example-reports/example-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -56,6 +57,7 @@
"name": "Percentage test code",
"scale": "percentage",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": ">",
Expand Down Expand Up @@ -118,6 +120,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -180,6 +183,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -238,6 +242,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -283,6 +288,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -328,6 +334,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -373,6 +380,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -440,6 +448,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -574,6 +583,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -640,6 +650,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -662,6 +673,7 @@
"name": "Time since last security test",
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -689,6 +701,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -753,6 +766,7 @@
"name": "Number of performance tests",
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -817,6 +831,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -842,6 +857,7 @@
"name": null,
"scale": "percentage",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -867,6 +883,7 @@
"name": null,
"scale": "percentage",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -904,6 +921,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -929,6 +947,7 @@
"name": "Time since last performance test",
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down Expand Up @@ -982,6 +1001,7 @@
"name": null,
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -1008,6 +1028,7 @@
"name": "Time since last Axe-core report",
"scale": "count",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand All @@ -1033,6 +1054,7 @@
"name": null,
"scale": "version_number",
"unit": null,
"unit_singular": null,
"accept_debt": false,
"debt_target": null,
"direction": null,
Expand Down
1 change: 1 addition & 0 deletions components/api_server/src/model/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def default_metric_attributes(metric_type: str):
"name": None,
"scale": metric.default_scale,
"unit": None,
"unit_singular": None,
"evaluate_targets": metric.evaluate_targets,
"accept_debt": False,
"debt_target": None,
Expand Down
5 changes: 3 additions & 2 deletions components/api_server/src/routes/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,12 @@ def create_issue_text(metric: Metric, measured_value: Value) -> tuple[str, str]:
# for the text formatting notation used by Jira API version 2.
source_urls = [f"[{url}|{url}]" for url in [get_source_url(source) for source in metric.sources] if url]
percentage = "%" if metric.scale() == "percentage" else ""
issue_summary = f"Fix {measured_value}{percentage} {metric.unit} from {source_names}"
unit = metric.unit_for_value(measured_value)
issue_summary = f"Fix {measured_value}{percentage} {unit} from {source_names}"
source_url_str = f"\nPlease go to {', '.join(source_urls)} for more details." if source_urls else ""
issue_description = (
f"The metric [{metric.name}|{metric_url}] in Quality-time reports "
f"{measured_value}{percentage} {metric.unit} from {source_names}.{source_url_str}\n"
f"{measured_value}{percentage} {unit} from {source_names}.{source_url_str}\n"
)
return issue_summary, issue_description

Expand Down
9 changes: 8 additions & 1 deletion components/api_server/tests/model/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ class MoveItemToIndexTest(unittest.TestCase):
def setUp(self):
"""Override to set up the subject under test."""
self.data_model = {
"metrics": {"security_warnings": {"name": "Security warnings", "unit": "warnings", "tags": []}},
"metrics": {
"security_warnings": {
"name": "Security warnings",
"unit": "warnings",
"unit_singular": "warning",
"tags": [],
}
},
"subjects": {"software": {"name": "Software"}},
}

Expand Down
1 change: 1 addition & 0 deletions components/api_server/tests/model/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_default_metric_attributes(self):
"sources": {},
"tags": ["ci"],
"unit": None,
"unit_singular": None,
},
default_metric_attributes("software_version"),
)
Expand Down
15 changes: 15 additions & 0 deletions components/api_server/tests/routes/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ def setUp(self):
"type": "violations",
"name": "name",
"unit": Unit.VIOLATIONS,
"unit_singular": Unit.VIOLATION,
"sources": self.sources,
},
},
Expand Down Expand Up @@ -632,6 +633,20 @@ def test_add_metric_issue(self, requests_post):
self.assert_issue_posted(requests_post)
self.assert_issue_inserted()

@patch("bottle.request", Mock(json={"metric_url": METRIC_URL}))
def test_add_metric_issue_when_measurement_is_one(self, requests_post):
"""Test that the singular unit is used if the measurement is one."""
self.measurement["count"]["value"] = "1"
self.expected_json["fields"]["summary"] = "Fix 1 violation from Source"
description = self.expected_json["fields"]["description"]
self.expected_json["fields"]["description"] = description.replace("42 violations", "1 violation")
response = Mock()
response.json.return_value = {"key": "FOO-42"}
requests_post.return_value = response
self.assertEqual({"ok": True, "issue_url": self.ISSUE_URL}, add_metric_issue(METRIC_ID, self.database))
self.assert_issue_posted(requests_post)
self.assert_issue_inserted()

@patch("bottle.request", Mock(json={"metric_url": METRIC_URL}))
def test_add_metric_issue_with_landing_url(self, requests_post):
"""Test that the metric landing URL is used if available."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __parse_entity(self, entity: Entity, metric, landing_url: URL) -> Entity:
status_start = self.__metric_status_start(metric.get("status_start", ""))
entity["status_start_date"] = status_start.isoformat() if status_start else ""
entity["unit"] = metric.get("unit") or DATA_MODEL.metrics[metric["type"]].unit.value
entity["unit_singular"] = metric.get("unit_singular") or DATA_MODEL.metrics[metric["type"]].unit_singular.value
entity["measurement"] = value
direction = str(metric.get("direction") or DATA_MODEL.metrics[metric["type"]].direction.value)
direction = {"<": "≦", ">": "≧"}.get(direction, direction)
Expand Down
1 change: 0 additions & 1 deletion components/collector/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def create_report(title: str = "Title", report_uuid: str = "report1", **kwargs)
"target": "0",
"accept_debt": False,
"scale": "count",
"unit": "foo",
"webhook": "www.webhook.com",
"scales": ["count", "percentage"],
"sources": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def setUp(self):
"measurement": "20",
"target": "≦ 2",
"unit": "violations",
"unit_singular": "violation",
"status": "target_not_met",
"status_start_date": "2020-05-23T07:53:17+00:00",
},
Expand Down
6 changes: 4 additions & 2 deletions components/frontend/src/AppUI.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ it("shows only tags of the current report in the settings menu", async () => {
name: "Metric 1",
scale: "count",
tags: ["tag1"],
unit: "unit",
unit: "units",
unit_singular: "unit",
},
},
},
Expand All @@ -129,7 +130,8 @@ it("shows only tags of the current report in the settings menu", async () => {
name: "Metric 2",
scale: "count",
tags: ["tag2"],
unit: "unit",
unit: "units",
unit_singular: "unit",
},
},
},
Expand Down
Loading