Skip to content
Merged
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
24 changes: 10 additions & 14 deletions grimoirelab_metrics/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import sys
import time
import typing
from urllib import response

import click
import requests
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
"""
Expand Down Expand Up @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion grimoirelab_metrics/grimoirelab_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 7 additions & 7 deletions grimoirelab_metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
"""

Expand Down Expand Up @@ -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]
Expand Down
Loading