add support for any limit of commits
This commit is contained in:
21
PICable.py
21
PICable.py
@@ -5,7 +5,7 @@ from datetime import datetime, timedelta
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
LIMIT_COMMITS_30_DAYS = 50 # Has to be <= 100
|
LIMIT_COMMITS_30_DAYS = 50
|
||||||
LIMIT_STARS = 200
|
LIMIT_STARS = 200
|
||||||
LIMIT_NLOC = 100000
|
LIMIT_NLOC = 100000
|
||||||
MARGIN = 0.1
|
MARGIN = 0.1
|
||||||
@@ -26,15 +26,24 @@ def get_stars_info(owner, repo, token):
|
|||||||
def get_commits_last_30_days(owner, repo, token):
|
def get_commits_last_30_days(owner, repo, token):
|
||||||
headers = {"Authorization": f"token {token}"}
|
headers = {"Authorization": f"token {token}"}
|
||||||
since = (datetime.now() - timedelta(days=30)).isoformat()
|
since = (datetime.now() - timedelta(days=30)).isoformat()
|
||||||
print(since)
|
commits_url = f"https://api.github.com/repos/{owner}/{repo}/commits?since={since}"
|
||||||
commits_url = f"https://api.github.com/repos/{owner}/{repo}/commits?since={since}&per_page={LIMIT_COMMITS_30_DAYS}"
|
|
||||||
commits_response = requests.get(commits_url, headers=headers)
|
commits_response = requests.get(commits_url, headers=headers)
|
||||||
|
|
||||||
if commits_response.status_code != 200:
|
if commits_response.status_code != 200:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
commits_30_days = len(commits_response.json())
|
if "link" in commits_response.headers:
|
||||||
return commits_30_days
|
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):
|
def get_lines_of_code(owner, repo):
|
||||||
@@ -54,7 +63,7 @@ def get_lines_of_code(owner, repo):
|
|||||||
else:
|
else:
|
||||||
loc = 0
|
loc = 0
|
||||||
subprocess.run(["rm", "-rf", clone_dir], check=True)
|
subprocess.run(["rm", "-rf", clone_dir], check=True)
|
||||||
|
print()
|
||||||
return loc
|
return loc
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user