Repository: mozilla/bugbug

Issue:
Add Nom metric
https://github.com/mozilla/rust-code-analysis/commit/c320eacd91f6f58ec99b6996446a94d31d6bf871


Discussion:

Resolving patch:
diff --git a/bugbug/commit_features.py b/bugbug/commit_features.py
--- a/bugbug/commit_features.py
+++ b/bugbug/commit_features.py
@@ -165,6 +165,8 @@ def __call__(self, commit, **kwargs):
             "Average file estimated number of delivered bugs": commit["metrics"][
                 "halstead_bugs_avg"
             ],
+            "Average file number of functions": commit["metrics"]["functions_avg"],
+            "Average file number of closures": commit["metrics"]["closures_avg"],
             "Average file number of source loc": commit["metrics"]["sloc_avg"],
             "Average file number of instruction loc": commit["metrics"]["ploc_avg"],
             "Average file number of logical loc": commit["metrics"]["lloc_avg"],
@@ -205,6 +207,8 @@ def __call__(self, commit, **kwargs):
             "Maximum file estimated number of delivered bugs": commit["metrics"][
                 "halstead_bugs_max"
             ],
+            "Maximum file number of functions": commit["metrics"]["functions_max"],
+            "Maximum file number of closures": commit["metrics"]["closures_max"],
             "Maximum file number of source loc": commit["metrics"]["sloc_max"],
             "Maximum file number of instruction loc": commit["metrics"]["ploc_max"],
             "Maximum file number of logical loc": commit["metrics"]["lloc_max"],
@@ -245,6 +249,8 @@ def __call__(self, commit, **kwargs):
             "Minimum file estimated number of delivered bugs": commit["metrics"][
                 "halstead_bugs_min"
             ],
+            "Minimum file number of functions": commit["metrics"]["functions_min"],
+            "Minimum file number of closures": commit["metrics"]["closures_min"],
             "Minimum file number of source loc": commit["metrics"]["sloc_min"],
             "Minimum file number of instruction loc": commit["metrics"]["ploc_min"],
             "Minimum file number of logical loc": commit["metrics"]["lloc_min"],
@@ -285,6 +291,8 @@ def __call__(self, commit, **kwargs):
             "Total file estimated number of delivered bugs": commit["metrics"][
                 "halstead_bugs_total"
             ],
+            "Total file number of functions": commit["metrics"]["functions_total"],
+            "Total file number of closures": commit["metrics"]["closures_total"],
             "Total file number of source loc": commit["metrics"]["sloc_total"],
             "Total file number of instruction loc": commit["metrics"]["ploc_total"],
             "Total file number of logical loc": commit["metrics"]["lloc_total"],
@@ -366,6 +374,8 @@ def __call__(self, commit, **kwargs):
             "Average function estimated number of delivered bugs": merged_metrics[
                 "halstead_bugs_avg"
             ],
+            "Average function number of functions": merged_metrics["functions_avg"],
+            "Average function number of closures": merged_metrics["closures_avg"],
             "Average function number of source loc": merged_metrics["sloc_avg"],
             "Average function number of instruction loc": merged_metrics["ploc_avg"],
             "Average function number of logical loc": merged_metrics["lloc_avg"],
@@ -410,6 +420,8 @@ def __call__(self, commit, **kwargs):
             "Maximum function estimated number of delivered bugs": merged_metrics[
                 "halstead_bugs_max"
             ],
+            "Maximum function number of functions": merged_metrics["functions_max"],
+            "Maximum function number of closures": merged_metrics["closures_max"],
             "Maximum function number of source loc": merged_metrics["sloc_max"],
             "Maximum function number of instruction loc": merged_metrics["ploc_max"],
             "Maximum function number of logical loc": merged_metrics["lloc_max"],
@@ -454,6 +466,8 @@ def __call__(self, commit, **kwargs):
             "Minimum function estimated number of delivered bugs": merged_metrics[
                 "halstead_bugs_min"
             ],
+            "Minimum function number of functions": merged_metrics["functions_min"],
+            "Minimum function number of closures": merged_metrics["closures_min"],
             "Minimum function number of source loc": merged_metrics["sloc_min"],
             "Minimum function number of instruction loc": merged_metrics["ploc_min"],
             "Minimum function number of logical loc": merged_metrics["lloc_min"],
@@ -498,6 +512,8 @@ def __call__(self, commit, **kwargs):
             "Total function estimated number of delivered bugs": merged_metrics[
                 "halstead_bugs_total"
             ],
+            "Total function number of functions": merged_metrics["functions_total"],
+            "Total function number of closures": merged_metrics["closures_total"],
             "Total function number of source loc": merged_metrics["sloc_total"],
             "Total function number of instruction loc": merged_metrics["ploc_total"],
             "Total function number of logical loc": merged_metrics["lloc_total"],
@@ -550,6 +566,8 @@ def __call__(self, commit, **kwargs):
             "Diff in estimated number of delivered bugs": commit["metrics_diff"][
                 "halstead_bugs_total"
             ],
+            "Diff in number of functions": commit["metrics_diff"]["functions_total"],
+            "Diff in number of closures": commit["metrics_diff"]["closures_total"],
             "Diff in number of source loc": commit["metrics_diff"]["sloc_total"],
             "Diff in number of instruction loc": commit["metrics_diff"]["ploc_total"],
             "Diff in number of logical loc": commit["metrics_diff"]["lloc_total"],
diff --git a/bugbug/repository.py b/bugbug/repository.py
--- a/bugbug/repository.py
+++ b/bugbug/repository.py
@@ -132,6 +132,8 @@ def get_type(path: str) -> str:
     "halstead_effort",
     "halstead_time",
     "halstead_bugs",
+    "functions",
+    "closures",
     "sloc",
     "ploc",
     "lloc",
@@ -490,6 +492,8 @@ def get_summary_metrics(obj, metrics_space):
         obj["halstead_bugs_max"] = max(
             obj["halstead_bugs_max"], metrics["halstead"]["bugs"]
         )
+        obj["functions_max"] = max(obj["functions_max"], metrics["nom"]["functions"])
+        obj["closures_max"] = max(obj["closures_max"], metrics["nom"]["closures"])
         obj["sloc_max"] = max(obj["sloc_max"], metrics["loc"]["sloc"])
         obj["ploc_max"] = max(obj["ploc_max"], metrics["loc"]["ploc"])
         obj["lloc_max"] = max(obj["lloc_max"], metrics["loc"]["lloc"])
@@ -547,6 +551,8 @@ def get_summary_metrics(obj, metrics_space):
         obj["halstead_bugs_min"] = min(
             obj["halstead_bugs_min"], metrics["halstead"]["bugs"]
         )
+        obj["functions_min"] = min(obj["functions_min"], metrics["nom"]["functions"])
+        obj["closures_min"] = min(obj["closures_min"], metrics["nom"]["closures"])
         obj["sloc_min"] = min(obj["sloc_min"], metrics["loc"]["sloc"])
         obj["ploc_min"] = min(obj["ploc_min"], metrics["loc"]["ploc"])
         obj["lloc_min"] = min(obj["lloc_min"], metrics["loc"]["lloc"])
@@ -597,6 +603,8 @@ def get_space_metrics(
     obj["halstead_effort_total"] += metrics["halstead"]["effort"]
     obj["halstead_time_total"] += metrics["halstead"]["time"]
     obj["halstead_bugs_total"] += metrics["halstead"]["bugs"]
+    obj["functions_total"] += metrics["nom"]["functions"]
+    obj["closures_total"] += metrics["nom"]["closures"]
     obj["sloc_total"] += metrics["loc"]["sloc"]
     obj["ploc_total"] += metrics["loc"]["ploc"]
     obj["lloc_total"] += metrics["loc"]["lloc"]


Test patch:
diff --git a/tests/test_repository.py b/tests/test_repository.py
--- a/tests/test_repository.py
+++ b/tests/test_repository.py
@@ -2490,6 +2490,14 @@ def test_set_commit_metrics():
         "halstead_bugs_max": 0.006149947511600477,
         "halstead_bugs_min": 0.006149947511600477,
         "halstead_bugs_total": 0.006149947511600477,
+        "functions_avg": 0.0,
+        "functions_max": 1.0,
+        "functions_min": 1.0,
+        "functions_total": 1.0,
+        "closures_avg": 0.0,
+        "closures_max": 0,
+        "closures_min": 0.0,
+        "closures_total": 0.0,
         "lloc_avg": 0.0,
         "lloc_max": 1.0,
         "lloc_min": 1.0,
@@ -2545,6 +2553,8 @@ def test_set_commit_metrics():
         "halstead_effort_total": 0.0,
         "halstead_time_total": 0.0,
         "halstead_bugs_total": 0.0,
+        "functions_total": 0.0,
+        "closures_total": 0.0,
         "lloc_total": 0.0,
         "nargs_total": 0.0,
         "nexits_total": 0.0,
@@ -2577,6 +2587,8 @@ def test_set_commit_metrics():
                     "halstead_effort_total": 79.2481250360578,
                     "halstead_time_total": 4.402673613114322,
                     "halstead_bugs_total": 0.006149947511600477,
+                    "functions_total": 1.0,
+                    "closures_total": 0.0,
                     "lloc_total": 1.0,
                     "nargs_total": 0.0,
                     "nexits_total": 0.0,
@@ -2729,6 +2741,14 @@ def test_set_commit_metrics_meaningful_diff():
         "halstead_bugs_max": 0.010862528153285396,
         "halstead_bugs_min": 0.010862528153285396,
         "halstead_bugs_total": 0.010862528153285396,
+        "functions_avg": 0.0,
+        "functions_max": 1.0,
+        "functions_min": 1.0,
+        "functions_total": 1.0,
+        "closures_avg": 0.0,
+        "closures_max": 0,
+        "closures_min": 0.0,
+        "closures_total": 0.0,
         "lloc_avg": 0.0,
         "lloc_max": 2.0,
         "lloc_min": 2.0,
@@ -2784,6 +2804,8 @@ def test_set_commit_metrics_meaningful_diff():
         "halstead_effort_total": 106.77984827763449,
         "halstead_time_total": 5.932213793201916,
         "halstead_bugs_total": 0.00471258064168492,
+        "functions_total": 0.0,
+        "closures_total": 0.0,
         "lloc_total": 1.0,
         "nargs_total": 0.0,
         "nexits_total": 0.0,
@@ -2816,6 +2838,8 @@ def test_set_commit_metrics_meaningful_diff():
                     "halstead_effort_total": 186.02797331369229,
                     "halstead_time_total": 10.334887406316238,
                     "halstead_bugs_total": 0.010862528153285396,
+                    "functions_total": 1.0,
+                    "closures_total": 0.0,
                     "lloc_total": 2.0,
                     "nargs_total": 0.0,
                     "nexits_total": 0.0,