Sign in
agent:

Assign a pull request to a user

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

This script assigns the specified reviewer to the pull request for the specified GitHub repository.

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 assign a reviewer to a pull request def assign_reviewer(owner, repo_name, pull_number, reviewers): token = getEnvVar('GITHUB_TOKEN') url = f'https://api.github.com/repos/{owner}/{repo_name}/pulls/{pull_number}/requested_reviewers' headers = { 'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json' } data = { 'reviewers': reviewers } response = requests.post(url, headers=headers, data=json.dumps(data)) return response # Input print(f'Input owner: {owner}') print(f'Input repo_name: {repo_name}') print(f'Input pull_number: {pull_number}') print(f'Input reviewers: {reviewers}') # Check token validity is_valid = check_github_token_validity() if is_valid: # Assign reviewer response = assign_reviewer(owner, repo_name, pull_number, reviewers) print('Raw response:') print(response.text) print(f'Status code: {response.status_code}') if response.status_code == 201: explanation = 'Reviewer assigned successfully.' elif response.status_code == 422: explanation = 'Validation failed. Please check if the reviewer is a collaborator on the repository.' elif response.status_code == 404: explanation = 'The pull request or repository was not found. Please check the owner, repository name, and pull request number.' 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