Compare commits

..

2 Commits

Author SHA1 Message Date
a1d1f01606 Ruff after Claude Code
All checks were successful
Run Python tests (through Pytest) / Test (push) Successful in 25s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 23s
2025-06-09 18:04:24 +02:00
a2a465f5c7 Initial ruff pass 2025-06-09 18:00:00 +02:00
3 changed files with 91 additions and 58 deletions

View File

@ -157,7 +157,6 @@ class RepositoryConfig:
repo: str repo: str
base_branch: str base_branch: str
assignee: str | None = None assignee: str | None = None
reviewer: str | None = None
def repo_url(self) -> str: def repo_url(self) -> str:
return f'{self.gitea_url}:{self.owner}/{self.repo}.git'.replace( return f'{self.gitea_url}:{self.owner}/{self.repo}.git'.replace(
@ -499,12 +498,10 @@ def push_changes(
cmd = ['git', 'push', 'origin', branch_name, '--force'] cmd = ['git', 'push', 'origin', branch_name, '--force']
run_cmd(cmd, cwd) run_cmd(cmd, cwd)
# Prepare assignees list # Then create the PR with the aider label and optional assignee/reviewer
assignees = [] assignees = [repository_config.assignee] if repository_config.assignee else None
if repository_config.assignee: reviewers = [repository_config.assignee] if repository_config.assignee else None
assignees.append(repository_config.assignee)
# Then create the PR with the aider label and assignees
pr_response = gitea_client.create_pull_request( pr_response = gitea_client.create_pull_request(
owner=repository_config.owner, owner=repository_config.owner,
repo=repository_config.repo, repo=repository_config.repo,
@ -513,39 +510,15 @@ def push_changes(
head=branch_name, head=branch_name,
base=repository_config.base_branch, base=repository_config.base_branch,
labels=['aider'], labels=['aider'],
assignees=assignees if assignees else None, assignees=assignees,
reviewers=reviewers,
) )
# Extract PR number
pr_number = int(pr_response.get('number'))
# Assign reviewer if specified (must be done after PR creation)
if repository_config.reviewer:
try:
gitea_client.assign_reviewers(
owner=repository_config.owner,
repo=repository_config.repo,
pull_number=pr_number,
reviewers=[repository_config.reviewer],
)
logger.info(
'Assigned reviewer %s to PR #%s',
repository_config.reviewer,
pr_number,
)
except Exception:
logger.warning(
'Failed to assign reviewer %s to PR #%s',
repository_config.reviewer,
pr_number,
exc_info=True,
)
# Extract PR number and URL if available # Extract PR number and URL if available
return IssueResolution( return IssueResolution(
True, True,
pr_response.get('html_url'), pr_response.get('html_url'),
pr_number, int(pr_response.get('number')),
) )

View File

@ -57,12 +57,7 @@ def parse_args():
) )
parser.add_argument( parser.add_argument(
'--assignee', '--assignee',
help='Username to assign as the assignee for created pull requests', help='Username to automatically assign as assignee and reviewer for created pull requests',
default=None,
)
parser.add_argument(
'--reviewer',
help='Username to assign as the reviewer for created pull requests',
default=None, default=None,
) )
return parser.parse_args() return parser.parse_args()
@ -95,7 +90,6 @@ def main():
repo=repo, repo=repo,
base_branch=args.base_branch, base_branch=args.base_branch,
assignee=args.assignee, assignee=args.assignee,
reviewer=args.reviewer,
) )
solve_issues_in_repository(repository_config, client, seen_issues_db) solve_issues_in_repository(repository_config, client, seen_issues_db)
del repo del repo

View File

@ -140,8 +140,9 @@ class GiteaClient:
base: str, base: str,
labels: list[str] = None, labels: list[str] = None,
assignees: list[str] = None, assignees: list[str] = None,
reviewers: list[str] = None,
) -> dict: ) -> dict:
"""Create a pull request and optionally apply labels and assignees. """Create a pull request and optionally apply labels, assignees, and reviewers.
Args: Args:
owner (str): Owner of the repository. owner (str): Owner of the repository.
@ -152,6 +153,7 @@ class GiteaClient:
base (str): The name of the branch you want the changes pulled into. base (str): The name of the branch you want the changes pulled into.
labels (list[str], optional): List of label names to apply to the pull request. labels (list[str], optional): List of label names to apply to the pull request.
assignees (list[str], optional): List of usernames to assign to the pull request. assignees (list[str], optional): List of usernames to assign to the pull request.
reviewers (list[str], optional): List of usernames to request reviews from.
Returns: Returns:
dict: The created pull request data. dict: The created pull request data.
@ -167,8 +169,11 @@ class GiteaClient:
'base': base, 'base': base,
} }
# Add assignees and reviewers if provided
if assignees: if assignees:
json_data['assignees'] = assignees json_data['assignees'] = assignees
if reviewers:
json_data['reviewers'] = reviewers
response = self.session.post(url, json=json_data) response = self.session.post(url, json=json_data)
# If a pull request for this head/base already exists, return it instead of crashing # If a pull request for this head/base already exists, return it instead of crashing
@ -184,39 +189,100 @@ class GiteaClient:
pr.get('head', {}).get('ref') == head pr.get('head', {}).get('ref') == head
and pr.get('base', {}).get('ref') == base and pr.get('base', {}).get('ref') == base
): ):
# Try to set assignees and reviewers on existing PR
pr_number = pr.get('number')
if assignees and pr_number:
self.set_pull_request_assignees(
owner,
repo,
pr_number,
assignees,
)
if reviewers and pr_number:
self.set_pull_request_reviewers(
owner,
repo,
pr_number,
reviewers,
)
return pr return pr
# fallback to raise if we cant find it # fallback to raise if we cant find it
response.raise_for_status() response.raise_for_status()
response.raise_for_status() response.raise_for_status()
return response.json()
def assign_reviewers( pr_data = response.json()
# If initial creation didn't set assignees/reviewers, try setting them separately
pr_number = pr_data.get('number')
if pr_number:
if assignees:
self.set_pull_request_assignees(owner, repo, pr_number, assignees)
if reviewers:
self.set_pull_request_reviewers(owner, repo, pr_number, reviewers)
return pr_data
def set_pull_request_assignees(
self, self,
owner: str, owner: str,
repo: str, repo: str,
pull_number: int, pr_number: int,
reviewers: list[str], assignees: list[str],
) -> dict: ) -> bool:
"""Assign reviewers to an existing pull request. """Set assignees for a pull request.
Args: Args:
owner (str): Owner of the repository. owner (str): Owner of the repository.
repo (str): Name of the repository. repo (str): Name of the repository.
pull_number (int): Number of the pull request. pr_number (int): Pull request number.
reviewers (list[str]): List of usernames to assign as reviewers. assignees (list[str]): List of usernames to assign.
Returns: Returns:
dict: The response data from the API. bool: True if successful, False otherwise.
Raises:
requests.HTTPError: If the API request fails.
""" """
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers' url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_number}/assignees'
json_data = {'reviewers': reviewers} json_data = {'assignees': assignees}
try:
response = self.session.put(url, json=json_data)
response.raise_for_status()
logger.info('Assigned users %s to PR #%s', assignees, pr_number)
return True
except Exception:
logger.warning('Failed to assign users %s to PR #%s', assignees, pr_number)
return False
response = self.session.post(url, json=json_data) def set_pull_request_reviewers(
response.raise_for_status() self,
return response.json() owner: str,
repo: str,
pr_number: int,
reviewers: list[str],
) -> bool:
"""Set reviewers for a pull request.
Args:
owner (str): Owner of the repository.
repo (str): Name of the repository.
pr_number (int): Pull request number.
reviewers (list[str]): List of usernames to request reviews from.
Returns:
bool: True if successful, False otherwise.
"""
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_number}/reviewers'
json_data = {'reviewers': reviewers}
try:
response = self.session.post(url, json=json_data)
response.raise_for_status()
logger.info('Requested reviews from %s for PR #%s', reviewers, pr_number)
return True
except Exception:
logger.warning(
'Failed to request reviews from %s for PR #%s',
reviewers,
pr_number,
)
return False
def get_failed_pipelines(self, owner: str, repo: str, pr_number: str) -> list[int]: def get_failed_pipelines(self, owner: str, repo: str, pr_number: str) -> list[int]:
"""Fetch pipeline runs for a PR and return IDs of failed runs.""" """Fetch pipeline runs for a PR and return IDs of failed runs."""