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