Skip to content

Commit 64d8da1

Browse files
Merge pull request #2 from devwithkrishna/feature/add-pagination
DEVOPS-95 added pagination for repo end point
2 parents 5696841 + dd2249e commit 64d8da1

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

create_new_labels.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,35 @@ def list_repos_in_org(org_name: str):
1818
"Authorization": f"Bearer {os.getenv('GH_TOKEN')}",
1919
"X-GitHub-Api-Version": "2022-11-28"
2020
}
21+
params = {
22+
'sort': 'created',
23+
'per_page': 30,
24+
'page': 1
25+
}
26+
27+
# List to hold all repositories
28+
all_repositories = []
29+
# Paginate through all pages
30+
while True:
31+
# Make the GET request with query parameters
32+
response = requests.get(url=repo_url, headers=headers, params=params)
33+
34+
# Check the response status code
35+
if response.status_code == 200:
36+
# Parse the JSON response
37+
repositories = response.json()
38+
if not repositories:
39+
break
40+
all_repositories.extend(repositories)
41+
params["page"] += 1
42+
else:
43+
print(f"Failed to fetch repositories: {response.status_code}")
44+
break
2145

22-
response = requests.get(url=repo_url, headers=headers)
23-
response_json = response.json()
24-
# print(response_json)
2546

2647
repo_names = []
2748

28-
for repo in response_json:
49+
for repo in all_repositories:
2950
print(repo['name'])
3051
repo_names.append(repo['name'])
3152

0 commit comments

Comments
 (0)