From 541165ed42fe1bd406b75ed2a972b804f12429b8 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 29 Jun 2023 17:08:28 +0200 Subject: [PATCH] Begin implementing pagination to process more than 100 issues --- main.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 3fe1689..4bb393a 100755 --- a/main.py +++ b/main.py @@ -18,27 +18,36 @@ def main() -> None: # TODO: Query more than 100 issues by performing several requests. query = gql( """ - query { - repository(owner: "godotengine", name: "godot") { - issues(last: 100) { - edges { - node { - body - author { - login + query($cursor: String) { + repository(owner: "godotengine", name: "godot") { + issues(last: 100, before: $cursor) { + edges { + cursor + node { + body + author { + login + } } } } } } - } - """ + """ ) - result = client.execute(query) + # We're querying the first page, so we don't need to supply a valid cursor. + # GQL will take care of not submitting the variable if it's set to `None`. + cursor = None + result = client.execute(query, variable_values={"cursor": cursor}) + # Array of dictionaries with user and system information string. user_system_infos = [] + # Get the cursor value of the last returned item, as we need it for subsequent requests (pagination). + # TODO: Use this cursor value. + cursor = result["repository"]["issues"]["edges"][-1]["cursor"] + # Counters for all statistics (values are a set of usernames). # A set is used, so that each user may only increment a given counter once. # A single user may increment multiple counters in the same category, @@ -316,7 +325,9 @@ def main() -> None: .replace(",", "") .replace("(r)", "") .replace("(tm)", "") - .replace("graphics", "") # Makes it easier to parse "Intel HD Graphics ...". + .replace( + "graphics", "" + ) # Makes it easier to parse "Intel HD Graphics ...". ) print(system_information_trimmed)