diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index b87b2ed..20f0d6a 100644 --- a/aider_gitea/__init__.py +++ b/aider_gitea/__init__.py @@ -138,6 +138,7 @@ For code tasks: MODEL = None + def create_aider_command(issue: str) -> list[str]: l = [ 'aider', @@ -173,6 +174,31 @@ def create_aider_command(issue: str) -> list[str]: return l +def get_commit_messages(cwd: Path, base_branch: str, current_branch: str) -> str: + """Get commit messages between base branch and current branch. + + Args: + cwd: The current working directory (repository path). + base_branch: The name of the base branch to compare against. + current_branch: The name of the current branch to check for commits. + + Returns: + A string containing all commit messages, one per line. + """ + try: + result = subprocess.run( + ['git', 'log', f'{base_branch}..{current_branch}', '--pretty=format:%s'], + check=True, + cwd=cwd, + capture_output=True, + text=True, + ) + return result.stdout.strip() + except subprocess.CalledProcessError: + logger.exception(f'Failed to get commit messages on branch {current_branch}') + return '' + + def push_changes( cwd: Path, branch_name: str, @@ -184,6 +210,16 @@ def push_changes( if not has_commits_on_branch(cwd, base_branch, branch_name): logger.info('No commits made on branch %s, skipping push', branch_name) return False + + # Get commit messages for PR description + commit_messages = get_commit_messages(cwd, base_branch, branch_name) + description = f'This pull request resolves #{issue_number}\n\n' + + if commit_messages: + description += '## Commit Messages\n\n' + for message in commit_messages.split('\n'): + description += f'- {message}\n' + cmd = [ 'git', 'push', @@ -194,7 +230,7 @@ def push_changes( '-o', f'title={issue_title}', '-o', - f'description=This pull request resolves #{issue_number}', + f'description={description}', ] run_cmd(cmd, cwd) return True diff --git a/test/test_seen_issues_db.py b/test/test_seen_issues_db.py index 4b4dcc0..71a0d2e 100644 --- a/test/test_seen_issues_db.py +++ b/test/test_seen_issues_db.py @@ -1,4 +1,3 @@ - from aider_gitea.seen_issues_db import SeenIssuesDB