diff --git a/PICable.py b/PICable.py index 53c843a..0e7ae43 100644 --- a/PICable.py +++ b/PICable.py @@ -5,7 +5,7 @@ from datetime import datetime, timedelta import requests -LIMIT_COMMITS_30_DAYS = 50 # Has to be <= 100 +LIMIT_COMMITS_30_DAYS = 50 LIMIT_STARS = 200 LIMIT_NLOC = 100000 MARGIN = 0.1 @@ -26,15 +26,24 @@ def get_stars_info(owner, repo, token): def get_commits_last_30_days(owner, repo, token): headers = {"Authorization": f"token {token}"} since = (datetime.now() - timedelta(days=30)).isoformat() - print(since) - commits_url = f"https://api.github.com/repos/{owner}/{repo}/commits?since={since}&per_page={LIMIT_COMMITS_30_DAYS}" + commits_url = f"https://api.github.com/repos/{owner}/{repo}/commits?since={since}" commits_response = requests.get(commits_url, headers=headers) if commits_response.status_code != 200: return -1 - commits_30_days = len(commits_response.json()) - return commits_30_days + if "link" in commits_response.headers: + page_count = int(commits_response.headers["link"].split(", ")[-1].split("; ")[0].split("page=")[1].split(">")[0]) + + last_commits_url = f"{commits_url}&page={page_count}" + last_commits_response = requests.get(last_commits_url, headers=headers) + + if last_commits_response.status_code != 200: + return -1 + + print((page_count - 1) * 30 + len(last_commits_response.json())) + return (page_count - 1) * 30 + len(last_commits_response.json()) + return len(commits_response.json()) def get_lines_of_code(owner, repo): @@ -54,7 +63,7 @@ def get_lines_of_code(owner, repo): else: loc = 0 subprocess.run(["rm", "-rf", clone_dir], check=True) - + print() return loc @@ -115,4 +124,4 @@ def PICable(owner, repository, token): else: res += f"The repository {repository_url} is almost PICable. There are certain requirements which are almost met by this repository. Consult with a professor before proceeding. :warning:\n" - return res + return res \ No newline at end of file