feat: include commit messages in pull request description
This commit is contained in:
parent
0c4fae510c
commit
7eab429f81
|
@ -173,6 +173,31 @@ def create_aider_command(issue: str) -> list[str]:
|
||||||
return l
|
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(
|
def push_changes(
|
||||||
cwd: Path,
|
cwd: Path,
|
||||||
branch_name: str,
|
branch_name: str,
|
||||||
|
@ -184,6 +209,16 @@ def push_changes(
|
||||||
if not has_commits_on_branch(cwd, base_branch, branch_name):
|
if not has_commits_on_branch(cwd, base_branch, branch_name):
|
||||||
logger.info('No commits made on branch %s, skipping push', branch_name)
|
logger.info('No commits made on branch %s, skipping push', branch_name)
|
||||||
return False
|
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 = [
|
cmd = [
|
||||||
'git',
|
'git',
|
||||||
'push',
|
'push',
|
||||||
|
@ -194,7 +229,7 @@ def push_changes(
|
||||||
'-o',
|
'-o',
|
||||||
f'title={issue_title}',
|
f'title={issue_title}',
|
||||||
'-o',
|
'-o',
|
||||||
f'description=This pull request resolves #{issue_number}',
|
f'description={description}',
|
||||||
]
|
]
|
||||||
run_cmd(cmd, cwd)
|
run_cmd(cmd, cwd)
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue
Block a user