Sign in
agent:

Collect all the commits since the last deployment for this repo

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


import requests import json branch_1 = latest_deployment_branch branch_2 = new_branch_name # Get environment variables GITHUB_TOKEN = getEnvVar('GITHUB_TOKEN') GITHUB_REPO_OWNER = getEnvVar('GITHUB_REPO_OWNER') # Define headers for GitHub API headers = { 'Authorization': f'token {GITHUB_TOKEN}', 'Accept': 'application/vnd.github.v3+json' } # Function to get the creation date of a branch def get_branch_creation_date(repo_owner, repo_name, branch_name): url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/branches/{branch_name}' response = requests.get(url, headers=headers) response.raise_for_status() branch_info = response.json() commit_sha = branch_info['commit']['sha'] url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/commits/{commit_sha}' response = requests.get(url, headers=headers) response.raise_for_status() commit_info = response.json() return commit_info['commit']['committer']['date'] # Get creation dates of the branches branch_1_creation_date = get_branch_creation_date(GITHUB_REPO_OWNER, repo_name, branch_1) branch_2_creation_date = get_branch_creation_date(GITHUB_REPO_OWNER, repo_name, branch_2) print(f'Branch 1 creation date: {branch_1_creation_date}') print(f'Branch 2 creation date: {branch_2_creation_date}') # Function to get commits between two dates def get_commits_between_dates(repo_owner, repo_name, branch_name, start_date, end_date): url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/commits' params = { 'sha': branch_name, 'since': start_date, 'until': end_date } response = requests.get(url, headers=headers, params=params) response.raise_for_status() return response.json() # Get commits between the creation dates of the two branches commits = get_commits_between_dates(GITHUB_REPO_OWNER, repo_name, 'main', branch_1_creation_date, branch_2_creation_date) # Extract required information from commits commit_list = [] for commit in commits: commit_info = { 'commit_id': commit['sha'], 'commit_user': commit['commit']['committer']['name'], 'commit_comments': commit['commit']['message'], 'commit_date': commit['commit']['committer']['date'] } commit_list.append(commit_info) print(json.dumps(commit_list, indent=4, default=str)) # Output the commits commits = commit_list
copied