From 7eab429f81b614ed27d1efcc2a2c1be6fd8b3149 Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Mon, 14 Apr 2025 23:51:30 +0200 Subject: [PATCH] feat: include commit messages in pull request description --- aider_gitea/__init__.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index b87b2ed..76659ce 100644 --- a/aider_gitea/__init__.py +++ b/aider_gitea/__init__.py @@ -173,6 +173,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 +209,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 +229,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