From 10d35c340184f010c2d7b66b9032466996e1492c Mon Sep 17 00:00:00 2001 From: pseusys Date: Fri, 11 Aug 2023 05:08:04 +0200 Subject: [PATCH 1/2] 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 929de8ee..d7c0a28b 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 d8d7955d..dd9a1818 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 a90bf397..90bb9782 100644 --- a/sources/manager_download.py +++ b/sources/manager_download.py @@ -271,9 +271,7 @@ async def _fetch_graphql_paginated(query: str, **kwargs) -> Dict: 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 5ce0c947..e5914143 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/2] 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 e5914143..83ffd3f5 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: