@@ -17,42 +17,37 @@ def list_repos_in_github_org(orgaization: str, search_string: str):
17
17
}
18
18
19
19
# Define pagination parameters
20
- per_page = 100 # Number of records per page
20
+ per_page = 20 # Number of records per page
21
21
page = 1 # Initial page number
22
- list_of_repo_names = []
22
+ params = { 'per_page' : per_page , 'page' : page }
23
23
24
+ all_repositories = []
24
25
while True :
25
26
# Add pagination parameters to the URL
26
- params = {'per_page' : per_page , 'page' : page }
27
27
response = requests .get (repo_url , headers = headers , params = params )
28
- response_json = response .json () ## Github repo details
29
-
30
- # Checking the API status code
31
28
if response .status_code == 200 :
32
- print (f"API request successful on { repo_url } " )
33
- # print(response_json)
29
+ # Parse the JSON response
30
+ repositories = response .json ()
31
+ if not repositories :
32
+ break
33
+ all_repositories .extend (repositories )
34
+ params ["page" ] += 1
34
35
else :
35
- print (f"API request failed with status code { response .status_code } :" )
36
- # print(response_json)
36
+ print (f"Failed to fetch repositories: { response .status_code } " )
37
37
break
38
38
39
- # Get the repo names from the list of dictionaries and add to another list
40
- for repo in response_json :
41
- repo_dict = {}
42
- repo_dict ['name' ] = repo ['full_name' ]
43
- repo_dict ['id' ] = repo ['id' ]
44
- list_of_repo_names .append (repo_dict )
45
-
46
- page += 1 # Move to the next page
47
-
39
+ # Get the repo names from the list of dictionaries and add to another list
40
+ list_of_repo_names = []
41
+ for repo in all_repositories :
42
+ repo_dict = {}
43
+ repo_dict ['name' ] = repo ['full_name' ]
44
+ repo_dict ['id' ] = repo ['id' ]
45
+ list_of_repo_names .append (repo_dict )
48
46
49
- # Finding repos starting with search string
50
- matching_repos = [repo for repo in list_of_repo_names if repo ['name' ].startswith (f'{ orgaization } /{ search_string } ' )]
51
- print (f"Matching repos { search_string } are: { matching_repos } " )
52
- return matching_repos
53
- # Break the loop if no more pages
54
- if len (response_json ) < per_page :
55
- break
47
+ # Finding repos starting with search string
48
+ matching_repos = [repo for repo in list_of_repo_names if repo ['name' ].startswith (f'{ orgaization } /{ search_string } ' )]
49
+ print (f"Matching repos { search_string } are: { matching_repos } " )
50
+ return matching_repos
56
51
57
52
58
53
def main ():
0 commit comments