Sign in
agent:

Get the last deployment branch for a repo

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

This code lists all the branches of the specified GitHub repository using the GitHub API.

import json import requests # Get environment variables GITHUB_TOKEN = getEnvVar('GITHUB_TOKEN') GITHUB_REPO_OWNER = getEnvVar('GITHUB_REPO_OWNER') # Print input parameters print(f"Input Parameters:\nrepo_name: {repo_name}") # GitHub API URL to list branches url = f"https://api.github.com/repos/{GITHUB_REPO_OWNER}/{repo_name}/branches" # Headers for authentication headers = { 'Authorization': f'Bearer {GITHUB_TOKEN}', 'Accept': 'application/vnd.github.v3+json' } # Make the request to GitHub API response = requests.get(url, headers=headers) # Check if the request was successful if response.status_code == 200: branches = [branch['name'] for branch in response.json()] # print(f"Output:\n{json.dumps(branches, indent=4, default=str)}") else: branches = [] print(f"Failed to fetch branches. Status code: {response.status_code}") branch_ids = [] for branch in branches: if branch.startswith("deployment-branch-"): branch_id = int(branch.split("deployment-branch-")[1]) branch_ids.append(branch_id) latest_branch_id = max(branch_ids) latest_deployment_branch = f"deployment-branch-{latest_branch_id}" print(latest_deployment_branch)
copied