Merge pull request #469 from anmol098/fix/commit_pagination_retrieving_fix

Fixed commit pagination code
This commit is contained in:
Anmol Singh
2023-11-21 18:01:53 +05:30
committed by GitHub
4 changed files with 12 additions and 16 deletions

View File

@@ -88,7 +88,7 @@ async def make_commit_day_time_list(time_zone: str, repositories: Dict, commit_d
day_times = [0] * 4 # 0 - 6, 6 - 12, 12 - 18, 18 - 24 day_times = [0] * 4 # 0 - 6, 6 - 12, 12 - 18, 18 - 24
week_days = [0] * 7 # Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday week_days = [0] * 7 # Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
for repository in [d for d in repositories["data"]["user"]["repositories"]["nodes"]]: for repository in repositories:
if repository["name"] not in commit_dates.keys(): if repository["name"] not in commit_dates.keys():
continue continue
@@ -128,7 +128,7 @@ def make_language_per_repo_list(repositories: Dict) -> str:
:returns: string representation of statistics. :returns: string representation of statistics.
""" """
language_count = dict() language_count = dict()
repos_with_language = [repo for repo in repositories["data"]["user"]["repositories"]["nodes"] if repo["primaryLanguage"] is not None] repos_with_language = [repo for repo in repositories if repo["primaryLanguage"] is not None]
for repo in repos_with_language: for repo in repos_with_language:
language = repo["primaryLanguage"]["name"] language = repo["primaryLanguage"]["name"]
language_count[language] = language_count.get(language, {"count": 0}) language_count[language] = language_count.get(language, {"count": 0})

View File

@@ -129,15 +129,14 @@ async def collect_user_repositories() -> Dict:
""" """
DBM.i("Getting user repositories list...") DBM.i("Getting user repositories list...")
repositories = await DM.get_remote_graphql("user_repository_list", username=GHM.USER.login, id=GHM.USER.node_id) repositories = await DM.get_remote_graphql("user_repository_list", username=GHM.USER.login, id=GHM.USER.node_id)
repo_names = [repo["name"] for repo in repositories["data"]["user"]["repositories"]["nodes"]] repo_names = [repo["name"] for repo in repositories]
DBM.g("\tUser repository list collected!") DBM.g("\tUser repository list collected!")
contributed = await DM.get_remote_graphql("repos_contributed_to", username=GHM.USER.login) contributed = await DM.get_remote_graphql("repos_contributed_to", username=GHM.USER.login)
contributed_nodes = [r for r in contributed["data"]["user"]["repositoriesContributedTo"]["nodes"] if r["name"] not in repo_names and not r["isFork"]] contributed_nodes = [repo for repo in contributed if repo["name"] not in repo_names and not repo["isFork"]]
DBM.g("\tUser contributed to repository list collected!") DBM.g("\tUser contributed to repository list collected!")
repositories["data"]["user"]["repositories"]["nodes"] += contributed_nodes return repositories + contributed_nodes
return repositories
async def get_stats() -> str: async def get_stats() -> str:

View File

@@ -271,9 +271,7 @@ class DownloadManager:
query_response = await DownloadManager._fetch_graphql_query(query, **kwargs, pagination=pagination) query_response = await DownloadManager._fetch_graphql_query(query, **kwargs, pagination=pagination)
new_page_list, page_info = DownloadManager._find_pagination_and_data_list(query_response) new_page_list, page_info = DownloadManager._find_pagination_and_data_list(query_response)
page_list += new_page_list page_list += new_page_list
_, page_info = DownloadManager._find_pagination_and_data_list(initial_query_response) return page_list
page_info.clear()
return initial_query_response
@staticmethod @staticmethod
async def get_remote_graphql(query: str, **kwargs) -> Dict: async def get_remote_graphql(query: str, **kwargs) -> Dict:

View File

@@ -30,11 +30,10 @@ async def calculate_commit_data(repositories: Dict) -> Tuple[Dict, Dict]:
yearly_data = dict() yearly_data = dict()
date_data = dict() date_data = dict()
total = len(repositories["data"]["user"]["repositories"]["nodes"]) for ind, repo in enumerate(repositories):
for ind, repo in enumerate(repositories["data"]["user"]["repositories"]["nodes"]):
if repo["name"] not in EM.IGNORED_REPOS: if repo["name"] not in EM.IGNORED_REPOS:
repo_name = "[private]" if repo["isPrivate"] else f"{repo['owner']['login']}/{repo['name']}" repo_name = "[private]" if repo["isPrivate"] else f"{repo['owner']['login']}/{repo['name']}"
DBM.i(f"\t{ind + 1}/{total} Retrieving repo: {repo_name}") DBM.i(f"\t{ind + 1}/{len(repositories)} Retrieving repo: {repo_name}")
await update_data_with_commit_stats(repo, yearly_data, date_data) await update_data_with_commit_stats(repo, yearly_data, date_data)
DBM.g("Commit data calculated!") DBM.g("Commit data calculated!")
@@ -56,13 +55,13 @@ async def update_data_with_commit_stats(repo_details: Dict, yearly_data: Dict, d
""" """
owner = repo_details["owner"]["login"] owner = repo_details["owner"]["login"]
branch_data = await DM.get_remote_graphql("repo_branch_list", owner=owner, name=repo_details["name"]) branch_data = await DM.get_remote_graphql("repo_branch_list", owner=owner, name=repo_details["name"])
if branch_data["data"]["repository"] is None: if len(branch_data) == 0:
DBM.w(f"\t\tSkipping repo: {repo_details['name']}") DBM.w("\t\tSkipping repo.")
return return
for branch in branch_data["data"]["repository"]["refs"]["nodes"]: for branch in branch_data:
commit_data = await DM.get_remote_graphql("repo_commit_list", owner=owner, name=repo_details["name"], branch=branch["name"], id=GHM.USER.node_id) commit_data = await DM.get_remote_graphql("repo_commit_list", owner=owner, name=repo_details["name"], branch=branch["name"], id=GHM.USER.node_id)
for commit in commit_data["data"]["repository"]["ref"]["target"]["history"]["nodes"]: for commit in commit_data:
date = search(r"\d+-\d+-\d+", commit["committedDate"]).group() date = search(r"\d+-\d+-\d+", commit["committedDate"]).group()
curr_year = datetime.fromisoformat(date).year curr_year = datetime.fromisoformat(date).year
quarter = (datetime.fromisoformat(date).month - 1) // 3 + 1 quarter = (datetime.fromisoformat(date).month - 1) // 3 + 1