From 10d35c340184f010c2d7b66b9032466996e1492c Mon Sep 17 00:00:00 2001 From: pseusys Date: Fri, 11 Aug 2023 05:08:04 +0200 Subject: [PATCH 1/5] Fixed commit pagination code --- sources/graphics_list_formatter.py | 4 ++-- sources/main.py | 7 +++---- sources/manager_download.py | 4 +--- sources/yearly_commit_calculator.py | 11 +++++------ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/sources/graphics_list_formatter.py b/sources/graphics_list_formatter.py index 929de8e..d7c0a28 100644 --- a/sources/graphics_list_formatter.py +++ b/sources/graphics_list_formatter.py @@ -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 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(): continue @@ -128,7 +128,7 @@ def make_language_per_repo_list(repositories: Dict) -> str: :returns: string representation of statistics. """ 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: language = repo["primaryLanguage"]["name"] language_count[language] = language_count.get(language, {"count": 0}) diff --git a/sources/main.py b/sources/main.py index d8d7955..dd9a181 100644 --- a/sources/main.py +++ b/sources/main.py @@ -129,15 +129,14 @@ async def collect_user_repositories() -> Dict: """ DBM.i("Getting user repositories list...") 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!") 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!") - repositories["data"]["user"]["repositories"]["nodes"] += contributed_nodes - return repositories + return repositories + contributed_nodes async def get_stats() -> str: diff --git a/sources/manager_download.py b/sources/manager_download.py index a90bf39..90bb978 100644 --- a/sources/manager_download.py +++ b/sources/manager_download.py @@ -271,9 +271,7 @@ class DownloadManager: query_response = await DownloadManager._fetch_graphql_query(query, **kwargs, pagination=pagination) new_page_list, page_info = DownloadManager._find_pagination_and_data_list(query_response) page_list += new_page_list - _, page_info = DownloadManager._find_pagination_and_data_list(initial_query_response) - page_info.clear() - return initial_query_response + return page_list @staticmethod async def get_remote_graphql(query: str, **kwargs) -> Dict: diff --git a/sources/yearly_commit_calculator.py b/sources/yearly_commit_calculator.py index 5ce0c94..e591414 100644 --- a/sources/yearly_commit_calculator.py +++ b/sources/yearly_commit_calculator.py @@ -30,11 +30,10 @@ async def calculate_commit_data(repositories: Dict) -> Tuple[Dict, Dict]: yearly_data = dict() date_data = dict() - total = len(repositories["data"]["user"]["repositories"]["nodes"]) - for ind, repo in enumerate(repositories["data"]["user"]["repositories"]["nodes"]): + for ind, repo in enumerate(repositories): if repo["name"] not in EM.IGNORED_REPOS: 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) 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"] 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']}") 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) - 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() curr_year = datetime.fromisoformat(date).year quarter = (datetime.fromisoformat(date).month - 1) // 3 + 1 From 3ff32d18d1cd80420ae7f400cdb364100c01b013 Mon Sep 17 00:00:00 2001 From: pseusys Date: Fri, 11 Aug 2023 05:20:13 +0200 Subject: [PATCH 2/5] Skipping commit data obfuscated --- sources/yearly_commit_calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/yearly_commit_calculator.py b/sources/yearly_commit_calculator.py index e591414..83ffd3f 100644 --- a/sources/yearly_commit_calculator.py +++ b/sources/yearly_commit_calculator.py @@ -56,7 +56,7 @@ async def update_data_with_commit_stats(repo_details: Dict, yearly_data: Dict, d owner = repo_details["owner"]["login"] branch_data = await DM.get_remote_graphql("repo_branch_list", owner=owner, name=repo_details["name"]) if len(branch_data) == 0: - DBM.w(f"\t\tSkipping repo: {repo_details['name']}") + DBM.w("\t\tSkipping repo.") return for branch in branch_data: From 18204a93b4cc200dd5ce72c49ed6b8f4d2ae2da3 Mon Sep 17 00:00:00 2001 From: An Duong Date: Mon, 25 Sep 2023 21:34:37 -0400 Subject: [PATCH 3/5] Fix NPE --- sources/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/main.py b/sources/main.py index d8d7955..9c44095 100644 --- a/sources/main.py +++ b/sources/main.py @@ -133,7 +133,7 @@ async def collect_user_repositories() -> Dict: DBM.g("\tUser repository list collected!") 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 = [r for r in contributed["data"]["user"]["repositoriesContributedTo"]["nodes"] if r != None and r["name"] not in repo_names and not r["isFork"]] DBM.g("\tUser contributed to repository list collected!") repositories["data"]["user"]["repositories"]["nodes"] += contributed_nodes From 83fac825964dd5eb742f7f3cf63492c3f8704271 Mon Sep 17 00:00:00 2001 From: Guy Alexis Date: Mon, 20 Nov 2023 11:58:10 +0000 Subject: [PATCH 4/5] fix bug : Calculating stats for this user. Check back later #482 --- sources/manager_download.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/manager_download.py b/sources/manager_download.py index a90bf39..e2160f7 100644 --- a/sources/manager_download.py +++ b/sources/manager_download.py @@ -184,7 +184,7 @@ class DownloadManager: else: res = DownloadManager._REMOTE_RESOURCES_CACHE[resource] DBM.g(f"\tQuery '{resource}' loaded from cache!") - if res.status_code == 200: + if res.status_code in [200, 202]: if convertor is None: return res.json() else: From ba2d9d15a54858fc1ccea50b2138f3a649b1e0d5 Mon Sep 17 00:00:00 2001 From: Guy Alexis Date: Mon, 20 Nov 2023 12:13:18 +0000 Subject: [PATCH 5/5] fix bug : Calculating stats for this user. Check back later #482 --- sources/manager_download.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/manager_download.py b/sources/manager_download.py index e2160f7..eb6128e 100644 --- a/sources/manager_download.py +++ b/sources/manager_download.py @@ -184,7 +184,7 @@ class DownloadManager: else: res = DownloadManager._REMOTE_RESOURCES_CACHE[resource] DBM.g(f"\tQuery '{resource}' loaded from cache!") - if res.status_code in [200, 202]: + if res.status_code == 200 or res.status_code == 202: if convertor is None: return res.json() else: