| 23 | |
| 24 | |
| 25 | def fetch_all_branches(user, repo): |
| 26 | branches = [] # List to store all branches |
| 27 | page = 1 # Start from first page |
| 28 | while True: |
| 29 | # Make a request to the GitHub API for the branches |
| 30 | response = requests.get(f"https://api.github.com/repos/{user}/{repo}/branches", params={"page": page}) |
| 31 | |
| 32 | # Check if the request was successful |
| 33 | if response.status_code == 200: |
| 34 | # Add the branches from the current page to the list |
| 35 | branches.extend([branch["name"] for branch in response.json()]) |
| 36 | |
| 37 | # Check if there is a 'next' link for pagination |
| 38 | if "next" in response.links: |
| 39 | page += 1 # Move to the next page |
| 40 | else: |
| 41 | break # Exit loop if there is no next page |
| 42 | else: |
| 43 | print("Failed to retrieve branches:", response.status_code) |
| 44 | break |
| 45 | |
| 46 | return branches |
| 47 | |
| 48 | |
| 49 | def main(): |