From 69586c0b62f496d3b50bca521232108e74d01cbc Mon Sep 17 00:00:00 2001 From: Isaac Milarsky Date: Thu, 28 Mar 2024 10:36:09 -0400 Subject: [PATCH] add nadia metric Signed-off-by: Isaac Milarsky --- scripts/fetch_public_metrics.py | 5 ++- scripts/metricsLib/metrics_data_structures.py | 38 +++++++++++++++++++ scripts/metricsLib/metrics_definitions.py | 6 ++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/scripts/fetch_public_metrics.py b/scripts/fetch_public_metrics.py index d8c1aea78f..41ca716c9a 100755 --- a/scripts/fetch_public_metrics.py +++ b/scripts/fetch_public_metrics.py @@ -3,7 +3,7 @@ entity objects. """ import json -from metricsLib.metrics_definitions import SIMPLE_METRICS, ORG_METRICS +from metricsLib.metrics_definitions import SIMPLE_METRICS, ORG_METRICS, ADVANCED_METRICS from metricsLib.metrics_definitions import PERIODIC_METRICS, RESOURCE_METRICS @@ -87,6 +87,9 @@ def fetch_all_new_metric_data(all_orgs, all_repos): for metric in RESOURCE_METRICS: repo.apply_metric_and_store_data(metric, repo) + for metric in ADVANCED_METRICS: + repo.apply_metric_and_store_data(metric,repo) + # Capture all metric data for all Github orgs for org in all_orgs: print(f"Fetching metrics for org {org.name} id #{org.repo_group_id}") diff --git a/scripts/metricsLib/metrics_data_structures.py b/scripts/metricsLib/metrics_data_structures.py index 1893937fcb..bd469f38b3 100644 --- a/scripts/metricsLib/metrics_data_structures.py +++ b/scripts/metricsLib/metrics_data_structures.py @@ -428,6 +428,44 @@ def get_values(self, params=None): # Custom parse functions +def parse_nadia_label_into_badge(**kwargs): + """ + Parse the json returned by the augur nadia badging + endpoint and return a url to the appropriate badge + + Args: + kwargs: dict + Keyword arguments used by the parsing function. + + Returns: + Dictionary containing the url of the badge + """ + + metric_json = kwargs['metric_json'] + + try: + badge_name = metric_json[0]['nadia_badge_label'] + except KeyError: + return {} + + if badge_name == "club": + color = "ff69b4" + elif badge_name == "toy": + color = "blue" + elif badge_name == "stadium": + color = "orange" + elif badge_name == "federation": + color = "brightgreen" + else: + color = "red" + badge_name = "Midsize" + + url = f"https://img.shields.io/static/v1?label=project+type&message={badge_name}&color={color}" + + #return the url for the website to link to rather than waste time and space downloading + # the svg tag and saving it + return {"nadia_shields_badge_url": url} + def parse_commits_by_month(**kwargs): """ Parse the raw json returned by the commits endpoint into diff --git a/scripts/metricsLib/metrics_definitions.py b/scripts/metricsLib/metrics_definitions.py index 44eaf1933e..43f391e54b 100644 --- a/scripts/metricsLib/metrics_definitions.py +++ b/scripts/metricsLib/metrics_definitions.py @@ -3,7 +3,7 @@ """ from metricsLib.metrics_data_structures import CustomMetric, parse_commits_by_month, RangeMetric from metricsLib.metrics_data_structures import GraphQLMetric, LengthMetric, ResourceMetric -from metricsLib.metrics_data_structures import ListMetric +from metricsLib.metrics_data_structures import ListMetric, parse_nadia_label_into_badge from metricsLib.constants import TOKEN, AUGUR_HOST # The general procedure is to execute all metrics against all repos and orgs @@ -205,3 +205,7 @@ COMMITS_ENDPOINT = "https://api.github.com/repos/{owner}/{repo}/commits" SIMPLE_METRICS.append(CustomMetric("getCommitsByMonth", [ 'owner', 'repo'], COMMITS_ENDPOINT, parse_commits_by_month, token=TOKEN)) + + +NADIA_ENDPOINT = AUGUR_HOST + "/repos/{repo_id}/nadia-project-labeling-badge/" +ADVANCED_METRICS.append(CustomMetric("getNadiaBadgeURL",["repo_id"],NADIA_ENDPOINT, parse_nadia_label_into_badge))