Code quality
This commit is contained in:
parent
8a77769500
commit
59e3efaf3c
|
@ -75,7 +75,7 @@ def create_aider_command(issue: str) -> list[str]:
|
|||
'--lint-cmd',
|
||||
AIDER_LINT,
|
||||
'--auto-test',
|
||||
'--auto-lint',
|
||||
'--no-auto-lint',
|
||||
'--api-key',
|
||||
secrets.llm_api_key(),
|
||||
'--read',
|
||||
|
@ -167,7 +167,11 @@ def push_changes(
|
|||
issue_title: str,
|
||||
issue_description: str,
|
||||
base_branch: str,
|
||||
) -> None:
|
||||
) -> bool:
|
||||
# Check if there are any commits on the branch before pushing
|
||||
if not has_commits_on_branch(cwd, base_branch, branch_name):
|
||||
logger.info(f'No commits made on branch {branch_name}, skipping push')
|
||||
return False
|
||||
cmd = [
|
||||
'git',
|
||||
'push',
|
||||
|
@ -181,6 +185,7 @@ def push_changes(
|
|||
f'description=This pull request resolves #{issue_number}',
|
||||
]
|
||||
run_cmd(cmd, cwd)
|
||||
return True
|
||||
|
||||
|
||||
def has_commits_on_branch(cwd: Path, base_branch: str, current_branch: str) -> bool:
|
||||
|
@ -204,14 +209,14 @@ def run_cmd(cmd: list[str], cwd: Path | None = None) -> None:
|
|||
subprocess.run(cmd, check=True, cwd=cwd)
|
||||
|
||||
|
||||
def process_issue(
|
||||
def solve_issue_in_repository(
|
||||
args,
|
||||
tmpdirname: Path,
|
||||
branch_name: str,
|
||||
issue_title: str,
|
||||
issue_description: str,
|
||||
issue_number: str,
|
||||
):
|
||||
) -> bool:
|
||||
repo_url = f'{args.gitea_url}:{args.owner}/{args.repo}.git'.replace(
|
||||
'https://',
|
||||
'git@',
|
||||
|
@ -223,9 +228,7 @@ def process_issue(
|
|||
run_cmd(create_aider_command(f'# {issue_title}\n{issue_description}'), tmpdirname)
|
||||
run_cmd(['git', 'add', '.'], tmpdirname)
|
||||
|
||||
# Check if there are any commits on the branch before pushing
|
||||
if has_commits_on_branch(tmpdirname, args.base_branch, branch_name):
|
||||
push_changes(
|
||||
return push_changes(
|
||||
tmpdirname,
|
||||
branch_name,
|
||||
issue_number,
|
||||
|
@ -233,8 +236,6 @@ def process_issue(
|
|||
issue_description,
|
||||
args.base_branch,
|
||||
)
|
||||
else:
|
||||
logger.info(f'No commits made on branch {branch_name}, skipping push')
|
||||
|
||||
|
||||
def handle_issues(args, client, seen_issues_db):
|
||||
|
@ -259,9 +260,8 @@ def handle_issues(args, client, seen_issues_db):
|
|||
continue
|
||||
|
||||
branch_name = generate_branch_name(issue_number, title)
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
process_issue(
|
||||
solved = solve_issue_in_repository(
|
||||
args,
|
||||
Path(tmpdirname),
|
||||
branch_name,
|
||||
|
@ -269,10 +269,8 @@ def handle_issues(args, client, seen_issues_db):
|
|||
issue_description,
|
||||
issue_number,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception('Error processing issue')
|
||||
sys.exit(1)
|
||||
|
||||
if solved:
|
||||
seen_issues_db.mark_as_seen(issue_text)
|
||||
|
||||
|
||||
|
@ -294,7 +292,7 @@ def main():
|
|||
logger.info(f'Sleeping for {args.interval} seconds...')
|
||||
time.sleep(args.interval)
|
||||
except KeyboardInterrupt:
|
||||
logger.info('Daemon stopped by user')
|
||||
logger.exception('Daemon stopped by user')
|
||||
else:
|
||||
# One-off run
|
||||
handle_issues(args, client, seen_issues_db)
|
||||
|
|
Loading…
Reference in New Issue
Block a user