Skip to content

Commit

Permalink
add nadia metric
Browse files Browse the repository at this point in the history
Signed-off-by: Isaac Milarsky <[email protected]>
  • Loading branch information
IsaacMilarky committed Mar 28, 2024
1 parent 5f9b23c commit 69586c0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
5 changes: 4 additions & 1 deletion scripts/fetch_public_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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}")
Expand Down
38 changes: 38 additions & 0 deletions scripts/metricsLib/metrics_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion scripts/metricsLib/metrics_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

0 comments on commit 69586c0

Please sign in to comment.