From dd2249ea4f472fea6c541c7e2c879e3c33e12c66 Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Wed, 26 Jun 2024 23:24:07 +0530 Subject: [PATCH] DEVOPS-95 added pagination for repo end point --- create_new_labels.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/create_new_labels.py b/create_new_labels.py index 4352131..df5ffe9 100644 --- a/create_new_labels.py +++ b/create_new_labels.py @@ -18,14 +18,35 @@ def list_repos_in_org(org_name: str): "Authorization": f"Bearer {os.getenv('GH_TOKEN')}", "X-GitHub-Api-Version": "2022-11-28" } + params = { + 'sort': 'created', + 'per_page': 30, + 'page': 1 + } + + # List to hold all repositories + all_repositories = [] + # Paginate through all pages + while True: + # Make the GET request with query parameters + response = requests.get(url=repo_url, headers=headers, params=params) + + # Check the response status code + if response.status_code == 200: + # Parse the JSON response + repositories = response.json() + if not repositories: + break + all_repositories.extend(repositories) + params["page"] += 1 + else: + print(f"Failed to fetch repositories: {response.status_code}") + break - response = requests.get(url=repo_url, headers=headers) - response_json = response.json() - # print(response_json) repo_names = [] - for repo in response_json: + for repo in all_repositories: print(repo['name']) repo_names.append(repo['name'])