diff --git a/grimoirelab_metrics/cli.py b/grimoirelab_metrics/cli.py index 7cbe4a3..22ef574 100755 --- a/grimoirelab_metrics/cli.py +++ b/grimoirelab_metrics/cli.py @@ -26,7 +26,6 @@ import sys import time import typing -from urllib import response import click import requests @@ -154,7 +153,7 @@ def grimoirelab_metrics( logging.info("Could not find any git repositories to analyze") sys.exit(0) - #schedule_repositories(git_urls, grimoirelab_client) + # Old code schedule_repositories(git_urls, grimoirelab_client) metrics = generate_metrics_when_ready( grimoirelab_client=grimoirelab_client, @@ -212,7 +211,6 @@ def get_repository(download_location: str) -> str | None: if is_valid(download_location): git_regex = re.search(GIT_REPO_REGEX, download_location) if git_regex: - #uri = f"https://{git_regex.group(5)}" uri = f"https://{git_regex.group(5)}.git" return uri return None @@ -350,29 +348,28 @@ def repository_ready(grimoirelab_client: GrimoireLabClient, repository: str, aft :param repository: Repository URI :param after_date: Date to check if the task has finished """ - ecosystem ="npm-training-set" + ecosystem = "npm-training-set" project = "npm-popular-components" endpoint = f"api/v1/ecosystems/{ecosystem}/projects/{project}/repos/" try: r = grimoirelab_client.get(endpoint, params={"uri": repository}) - #r = grimoirelab_client.get(endpoint) except requests.HTTPError as e: logging.warning(f"Error checking repository status: {e}") return False repo_data = r.json() print(repo_data) - + if not repo_data.get("results"): logging.warning(f"Repository '{repository}' not found in project") - return False + return False # The response contains categories (datasets) categories = repo_data["results"][0].get("categories", []) if not categories: return False - + # Check the first category's task task = categories[0].get("task") """ @@ -413,23 +410,22 @@ def schedule_repository(grimoirelab_client: GrimoireLabClient, uri: str, datasou "datasource_category": category, } - ecosystem ="npm-training-set" + ecosystem = "npm-training-set" project = "npm-popular-components" endpoint = f"api/v1/ecosystems/{ecosystem}/projects/{project}/repos/" - + try: res = grimoirelab_client.post(endpoint, json=data) - res.raise_for_status() + res.raise_for_status() except requests.HTTPError as e: if e.response is not None and e.response.status_code == 422: # Optional: You can inspect e.response.text to ensure it's a duplicate error print(f"INFO - Repository {data.get('uri')} is already registered. Skipping.") - res = e.response # Assign the response so subsequent code doesn't break + res = e.response # Assign the response so subsequent code doesn't break else: # If it's a different HTTP error (500, 404, 403), re-raise it - raise e - + raise e if __name__ == "__main__": diff --git a/grimoirelab_metrics/grimoirelab_client.py b/grimoirelab_metrics/grimoirelab_client.py index 9692001..f4c9e8b 100644 --- a/grimoirelab_metrics/grimoirelab_client.py +++ b/grimoirelab_metrics/grimoirelab_client.py @@ -101,7 +101,7 @@ def _make_request(self, method: str, uri: str, *args, **kwargs) -> requests.Resp raise ValueError("Session not connected. Call connect() first.") url = f"{self.url}/{uri}" - #print(f"Making {method.upper()} request to {url} with args: {args} and kwargs: {kwargs}") + # print(f"Making {method.upper()} request to {url} with args: {args} and kwargs: {kwargs}") last_exception = None for attempt in range(MAX_RETRIES): diff --git a/grimoirelab_metrics/metrics.py b/grimoirelab_metrics/metrics.py index 00c49ba..07705e8 100644 --- a/grimoirelab_metrics/metrics.py +++ b/grimoirelab_metrics/metrics.py @@ -126,7 +126,7 @@ def _initialize_months(self): """ from_month = self.from_date.replace(day=1) to_month = self.to_date.replace(day=1) - + while from_month <= to_month: month_key = from_month.strftime("%Y-%m") self.commits_per_month[month_key] = 0 @@ -248,9 +248,9 @@ def get_commit_frequency_metrics(self, days_interval: int): def get_commit_coefficient_of_variation(self): """ - Get the coefficient of variation (mean) of the number of commits + Get the coefficient of variation (mean) of the number of commits per month. - + NEXT: The only interval so far coded is monthly. Is that correct? """ @@ -419,13 +419,13 @@ def _update_commit_count(self, event_data): if days_interval <= 90: self.recent_commits += 1 - + # Update commits per month - #try: ##FIXME + # try: ##FIXME month_key = commit_date.strftime("%Y-%m") self.commits_per_month[month_key] += 1 - ##except (ValueError, TypeError, InvalidDateError): - ##pass + # #except (ValueError, TypeError, InvalidDateError): + # #pass def _update_contributors(self, event_data): author = event_data[AUTHOR_FIELD]