Ruff after Claude Code
This commit is contained in:
parent
f003169a1b
commit
e04c624aa1
|
@ -156,6 +156,8 @@ class RepositoryConfig:
|
||||||
owner: str
|
owner: str
|
||||||
repo: str
|
repo: str
|
||||||
base_branch: str
|
base_branch: str
|
||||||
|
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(
|
||||||
|
@ -497,7 +499,12 @@ 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)
|
||||||
|
|
||||||
# Then create the PR with the aider label
|
# Prepare assignees list
|
||||||
|
assignees = []
|
||||||
|
if repository_config.assignee:
|
||||||
|
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,
|
||||||
|
@ -506,13 +513,39 @@ 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,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 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'),
|
||||||
int(pr_response.get('number')),
|
pr_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,16 @@ def parse_args():
|
||||||
help='Model to use for evaluating code (overrides default)',
|
help='Model to use for evaluating code (overrides default)',
|
||||||
default=None,
|
default=None,
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--assignee',
|
||||||
|
help='Username to assign as the assignee for created pull requests',
|
||||||
|
default=None,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--reviewer',
|
||||||
|
help='Username to assign as the reviewer for created pull requests',
|
||||||
|
default=None,
|
||||||
|
)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,6 +94,8 @@ def main():
|
||||||
owner=args.owner,
|
owner=args.owner,
|
||||||
repo=repo,
|
repo=repo,
|
||||||
base_branch=args.base_branch,
|
base_branch=args.base_branch,
|
||||||
|
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
|
||||||
|
|
|
@ -139,8 +139,9 @@ class GiteaClient:
|
||||||
head: str,
|
head: str,
|
||||||
base: str,
|
base: str,
|
||||||
labels: list[str] = None,
|
labels: list[str] = None,
|
||||||
|
assignees: list[str] = None,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""Create a pull request and optionally apply labels.
|
"""Create a pull request and optionally apply labels and assignees.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
owner (str): Owner of the repository.
|
owner (str): Owner of the repository.
|
||||||
|
@ -150,6 +151,7 @@ class GiteaClient:
|
||||||
head (str): The name of the branch where changes are implemented.
|
head (str): The name of the branch where changes are implemented.
|
||||||
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.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: The created pull request data.
|
dict: The created pull request data.
|
||||||
|
@ -165,6 +167,9 @@ class GiteaClient:
|
||||||
'base': base,
|
'base': base,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if assignees:
|
||||||
|
json_data['assignees'] = assignees
|
||||||
|
|
||||||
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
|
||||||
if response.status_code == 409:
|
if response.status_code == 409:
|
||||||
|
@ -185,6 +190,34 @@ class GiteaClient:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
def assign_reviewers(
|
||||||
|
self,
|
||||||
|
owner: str,
|
||||||
|
repo: str,
|
||||||
|
pull_number: int,
|
||||||
|
reviewers: list[str],
|
||||||
|
) -> dict:
|
||||||
|
"""Assign reviewers to an existing pull request.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
owner (str): Owner of the repository.
|
||||||
|
repo (str): Name of the repository.
|
||||||
|
pull_number (int): Number of the pull request.
|
||||||
|
reviewers (list[str]): List of usernames to assign as reviewers.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: The response data from the API.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
requests.HTTPError: If the API request fails.
|
||||||
|
"""
|
||||||
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers'
|
||||||
|
json_data = {'reviewers': reviewers}
|
||||||
|
|
||||||
|
response = self.session.post(url, json=json_data)
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
|
||||||
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."""
|
||||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/actions/runs'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/actions/runs'
|
||||||
|
|
|
@ -69,9 +69,10 @@ class TestClaudeCodeIntegration:
|
||||||
'claude',
|
'claude',
|
||||||
'-p',
|
'-p',
|
||||||
'--output-format',
|
'--output-format',
|
||||||
'json',
|
'stream-json',
|
||||||
'--max-turns',
|
'--debug',
|
||||||
'10',
|
'--verbose',
|
||||||
|
'--dangerously-skip-permissions',
|
||||||
issue,
|
issue,
|
||||||
]
|
]
|
||||||
assert cmd == expected
|
assert cmd == expected
|
||||||
|
@ -84,9 +85,10 @@ class TestClaudeCodeIntegration:
|
||||||
'claude',
|
'claude',
|
||||||
'-p',
|
'-p',
|
||||||
'--output-format',
|
'--output-format',
|
||||||
'json',
|
'stream-json',
|
||||||
'--max-turns',
|
'--debug',
|
||||||
'10',
|
'--verbose',
|
||||||
|
'--dangerously-skip-permissions',
|
||||||
'--model',
|
'--model',
|
||||||
'claude-3-sonnet',
|
'claude-3-sonnet',
|
||||||
issue,
|
issue,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user