From e6a63789d8e86c3abf458e99eab0cd08ccb3ee2c Mon Sep 17 00:00:00 2001 From: pseusys Date: Wed, 12 Apr 2023 06:18:39 +0200 Subject: [PATCH 1/5] `None` repositories (not fetched by various reasons) are filtered out. --- sources/main.py | 3 +++ sources/manager_download.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/sources/main.py b/sources/main.py index 747b496f..192c64f1 100644 --- a/sources/main.py +++ b/sources/main.py @@ -129,14 +129,17 @@ 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) + repositories = {key: value for key, value in repositories["data"]["user"]["repositories"]["nodes"] if value is not None} repo_names = [repo["name"] for repo in repositories["data"]["user"]["repositories"]["nodes"]] DBM.g("\tUser repository list collected!") contributed = await DM.get_remote_graphql("repos_contributed_to", username=GHM.USER.login) + contributed = {key: value for key, value in contributed["data"]["user"]["repositoriesContributedTo"]["nodes"] if value is not None} contributed_nodes = [r for r in contributed["data"]["user"]["repositoriesContributedTo"]["nodes"] if 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 + return repositories diff --git a/sources/manager_download.py b/sources/manager_download.py index a90bf397..96352c61 100644 --- a/sources/manager_download.py +++ b/sources/manager_download.py @@ -224,6 +224,10 @@ async def _fetch_graphql_query(query: str, retries_count: int = 10, **kwargs) -> "https://api.github.com/graphql", json={"query": Template(GITHUB_API_QUERIES[query]).substitute(kwargs)}, headers=headers ) if res.status_code == 200: + response_data = res.json() + if "errors" in response_data: + for error in response_data["errors"]: + DBM.w(f"GraphQL request returned an error: {error['message']}!") return res.json() elif res.status_code == 502 and retries_count > 0: return await DownloadManager._fetch_graphql_query(query, retries_count - 1, **kwargs) From cbbebb0415f836d0c8ba167d00d7e0ab417525e8 Mon Sep 17 00:00:00 2001 From: pseusys Date: Wed, 12 Apr 2023 06:34:11 +0200 Subject: [PATCH 2/5] list filtering done instead of dict --- sources/main.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sources/main.py b/sources/main.py index 192c64f1..ea00e9c6 100644 --- a/sources/main.py +++ b/sources/main.py @@ -129,17 +129,15 @@ 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) - repositories = {key: value for key, value in repositories["data"]["user"]["repositories"]["nodes"] if value is not None} + repositories["data"]["user"]["repositories"]["nodes"] = [repo for repo in repositories["data"]["user"]["repositories"]["nodes"] if repo is not None] repo_names = [repo["name"] for repo in repositories["data"]["user"]["repositories"]["nodes"]] DBM.g("\tUser repository list collected!") contributed = await DM.get_remote_graphql("repos_contributed_to", username=GHM.USER.login) - contributed = {key: value for key, value in contributed["data"]["user"]["repositoriesContributedTo"]["nodes"] if value is not None} - contributed_nodes = [r for r in contributed["data"]["user"]["repositoriesContributedTo"]["nodes"] if r["name"] not in repo_names and not r["isFork"]] + cn = [r for r in contributed["data"]["user"]["repositoriesContributedTo"]["nodes"] if r is not 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 - + repositories["data"]["user"]["repositories"]["nodes"] += cn return repositories From cd7df8f26094f2fca6e0926717f8f8925cfbafe7 Mon Sep 17 00:00:00 2001 From: Jan Jaden Schmidt Date: Thu, 13 Apr 2023 14:27:04 +0200 Subject: [PATCH 3/5] Changed variable name back to contributed_nodes I think it makes more sense to leave the variable written out to make the code easier to understand. --- sources/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/main.py b/sources/main.py index 8cdf5cd2..d3b2fab6 100644 --- a/sources/main.py +++ b/sources/main.py @@ -134,10 +134,10 @@ 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) - cn = [r for r in contributed["data"]["user"]["repositoriesContributedTo"]["nodes"] if r is not None and r["name"] not in repo_names and not r["isFork"]] + contributed_nodes = [r for r in contributed["data"]["user"]["repositoriesContributedTo"]["nodes"] if r is not 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"] += cn + repositories["data"]["user"]["repositories"]["nodes"] += contributed_nodes return repositories From ad4a82ce0f0c9b52d555521ab054b5e335b6d09b Mon Sep 17 00:00:00 2001 From: Jan Jaden Schmidt Date: Thu, 1 Jun 2023 13:44:09 +0200 Subject: [PATCH 4/5] Fix code style problem --- sources/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sources/main.py b/sources/main.py index d3b2fab6..10fb28b2 100644 --- a/sources/main.py +++ b/sources/main.py @@ -124,6 +124,8 @@ async def get_short_github_info() -> str: async def collect_user_repositories() -> Dict: """ Collects information about all the user repositories available. + + Side note: "cn" stands for contributed nodes but is shortened to conform to the code style :returns: Complete list of user repositories. """ @@ -134,10 +136,10 @@ 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 is not None and r["name"] not in repo_names and not r["isFork"]] + cn = [r for r in contributed["data"]["user"]["repositoriesContributedTo"]["nodes"] if r is not 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 + repositories["data"]["user"]["repositories"]["nodes"] += cn return repositories From cb537e95196c4d7b51de1bf4b638798d36eabef9 Mon Sep 17 00:00:00 2001 From: Jan Jaden Schmidt Date: Thu, 1 Jun 2023 13:46:34 +0200 Subject: [PATCH 5/5] Fix code style again.. --- sources/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/main.py b/sources/main.py index 10fb28b2..951988f5 100644 --- a/sources/main.py +++ b/sources/main.py @@ -124,7 +124,7 @@ async def get_short_github_info() -> str: async def collect_user_repositories() -> Dict: """ Collects information about all the user repositories available. - + Side note: "cn" stands for contributed nodes but is shortened to conform to the code style :returns: Complete list of user repositories.