Skip to content

Commit 26926b2

Browse files
Merge pull request #6 from devwithkrishna/feature/bugfix
Added pagination for repo names for list repo api DEVOPS-90
2 parents 1e42a9a + 0f6f5b3 commit 26926b2

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ updates:
1313
commit-message:
1414
prefix: "dependabot python package"
1515
# Use reviewers to specify individual reviewers or teams of reviewers for all pull requests raised for a package manager.
16-
# reviewers:
17-
# - "devwithkrishna/admin"
16+
reviewers:
17+
- "devwithkrishna/admin"
1818
# Raise pull requests for version updates to pip against the `main` branch
1919
target-branch: "main"
2020
# Labels on pull requests for version updates only
2121
labels:
22-
- "pip"
23-
- "dependancies"
22+
- "pip dependancies"
2423
# Increase the version requirements for Composer only when required
2524
versioning-strategy: increase-if-necessary
2625
# Dependabot opens a maximum of five pull requests for version updates. Once there are five open pull requests from Dependabot,

add_repos_to_gh_teams.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def main():
7878
# function call
7979
repo_names = list_all_github_org_repos(organization=organization)
8080
print(repo_names)
81+
print(f'Number of repos found: {len(repo_names)}')
8182
github_teams_list = list_all_github_teams_in_organization(organization=organization)
8283
print(github_teams_list)
8384
add_repos_to_github_team(organization=organization, github_team_name=github_team_name, repo_names=repo_names, github_teams_list=github_teams_list, permission=permission)

list_all_org_repos.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,38 @@ def list_all_github_org_repos(organization:str):
1515
"Authorization": f"Bearer {os.getenv('GH_TOKEN')}",
1616
"X-GitHub-Api-Version": "2022-11-28"
1717
}
18-
response = requests.get(url=repo_endpoint, headers=headers)
19-
response_json = response.json()
18+
params = {
19+
'sort':'created',
20+
'per_page': 30,
21+
'page': 1
22+
}
23+
24+
# List to hold all repositories
25+
all_repositories = []
26+
# Paginate through all pages
27+
while True:
28+
# Make the GET request with query parameters
29+
response = requests.get(url=repo_endpoint, headers=headers, params=params)
30+
31+
# Check the response status code
32+
if response.status_code == 200:
33+
# Parse the JSON response
34+
repositories = response.json()
35+
if not repositories:
36+
break
37+
all_repositories.extend(repositories)
38+
params["page"] += 1
39+
else:
40+
print(f"Failed to fetch repositories: {response.status_code}")
41+
break
42+
43+
# response = requests.get(url=repo_endpoint, headers=headers)
44+
# response_json = response.json()
2045
repo_names = []
21-
for repos in response_json:
46+
for repos in all_repositories:
2247
repo_names.append(repos['name'])
2348

24-
return repo_names
49+
return repo_names
2550

2651

2752
def main():

0 commit comments

Comments
 (0)