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 1/2] 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 -- 2.45.1 From 3bdbf2e621f3da82a53f5eb78eede25b64597aa8 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Mon, 14 Apr 2025 23:51:34 +0200 Subject: [PATCH 2/2] Ruff --- aider_gitea/__init__.py | 15 ++++++++------- test/test_seen_issues_db.py | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index 76659ce..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', @@ -195,7 +196,7 @@ def get_commit_messages(cwd: Path, base_branch: str, current_branch: str) -> str return result.stdout.strip() except subprocess.CalledProcessError: logger.exception(f'Failed to get commit messages on branch {current_branch}') - return "" + return '' def push_changes( @@ -209,16 +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" - + description = f'This pull request resolves #{issue_number}\n\n' + if commit_messages: - description += "## Commit Messages\n\n" + description += '## Commit Messages\n\n' for message in commit_messages.split('\n'): - description += f"- {message}\n" - + description += f'- {message}\n' + cmd = [ 'git', 'push', 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 -- 2.45.1