agent: |
Cw69JwUqencDt51NTThHList branches of a given repo
List branches of a given repo
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
This script checks why the branches of a specified GitHub repository cannot be listed and provides a more detailed explanation.
inputs
outputs
import requests
import json
# Function to check if the GitHub token is valid
def check_github_token_validity():
token = getEnvVar('GITHUB_TOKEN')
url = 'https://api.github.com/user'
headers = {
'Authorization': f'token {token}'
}
response = requests.get(url, headers=headers)
return response.status_code == 200
# Function to list branches of a repo
def list_branches(owner, repo_name):
token = getEnvVar('GITHUB_TOKEN')
url = f'https://api.github.com/repos/{owner}/{repo_name}/branches'
headers = {
'Authorization': f'token {token}',
'Accept': 'application/vnd.github.v3+json'
}
response = requests.get(url, headers=headers)
return response
# Input
print(f'Input owner: {owner}')
print(f'Input repo_name: {repo_name}')
# Check token validity
is_valid = check_github_token_validity()
if is_valid:
# List branches
response = list_branches(owner, repo_name)
if response.status_code == 200:
branches = response.json()
explanation = json.dumps(branches, indent=4)
elif response.status_code == 404:
explanation = 'The repository was not found. Please check the owner and repository name.'
elif response.status_code == 403:
explanation = 'Access to the repository is forbidden. Please check your permissions.'
else:
explanation = f'Error: {response.status_code} - {response.text}'
else:
explanation = 'The GitHub token is not valid.'
# Output
print('Output explanation:')
print(explanation)
copied