Skip to content

Commit

Permalink
fix(base_branch): fix base branch usage in missing parts (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
alissonperez committed Mar 15, 2024
1 parent 9598c50 commit c2fbefb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gptpr/gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def create_pr(pr_data, yield_confirmation):

if pr_confirmation:
pr = repo.create_pull(title=pr_data.title, body=pr_data.body,
head=pr_data.branch_info.branch, base='main')
head=pr_data.branch_info.branch, base=pr_data.branch_info.base_branch)
print("Pull request created successfully: ", pr.html_url)
else:
print('cancelling...')
18 changes: 10 additions & 8 deletions gptpr/gitutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class BranchInfo:
owner: str
repo: str
base_branch: str
branch: str
commits: list
highlight_commits: list
Expand Down Expand Up @@ -70,10 +71,11 @@ def get_branch_info(base_branch, yield_confirmation):
return BranchInfo(
owner=owner,
repo=repo_name,
base_branch=base_branch,
branch=current_branch.name,
commits=commits,
highlight_commits=highlight_commits,
diff=_get_diff_changes(repo, current_branch.name, yield_confirmation)
diff=_get_diff_changes(repo, base_branch, current_branch.name, yield_confirmation)
)


Expand All @@ -85,7 +87,7 @@ def _branch_exists(repo, branch_name):


def _get_diff_messages_against_base_branch(repo, branch, base_branch):
# Get commit messages that are in the current branch but not in the main branch
# Get commit messages that are in the current branch but not in the base branch
commits_diff = list(repo.iter_commits(f'{base_branch}..{branch}'))

return [commit.message.strip('\n') for commit in commits_diff]
Expand Down Expand Up @@ -147,33 +149,33 @@ def _extract_owner_and_repo(repo_url):
return owner, '.'.join(repo_info.split('.')[:-1])


def _get_diff_changes(repo, branch, yield_confirmation):
def _get_diff_changes(repo, base_branch, branch, yield_confirmation):
diff_changes = []

stats = _get_stats(repo, branch)
stats = _get_stats(repo, base_branch, branch)
files_to_ignore = _get_files_to_ignore(stats, yield_confirmation)

for file_change in stats:
if file_change.file_path in files_to_ignore:
continue

file_diff = repo.git.diff('main', branch, '--', file_change.file_path)
file_diff = repo.git.diff(base_branch, branch, '--', file_change.file_path)

diff_changes.append(file_diff)

return '\n'.join(diff_changes)


def _get_stats(repo, branch):
def _get_stats(repo, base_branch, branch):
'''
Get the stats of the difference between the current branch and the main branch
Get the stats of the difference between the current branch and the base branch
'''

# returns:
# 4 0 README.md
# 2 0 application/aggregator/aggregator.go
# 0 257 go.sum
diff_index = repo.git.diff('main', branch, '--numstat')
diff_index = repo.git.diff(base_branch, branch, '--numstat')

files_changed = []
for line in diff_index.split('\n'):
Expand Down
2 changes: 1 addition & 1 deletion gptpr/prdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def to_display(self):
f'{cc.bold("Repository")}: {cc.yellow(self.branch_info.owner)}/{cc.yellow(self.branch_info.repo)}',
f'{cc.bold("Title")}: {cc.yellow(self.title)}',
f'{cc.bold("Branch name")}: {cc.yellow(self.branch_info.branch)}',
f'{cc.bold("Base branch")}: {cc.yellow("main")}',
f'{cc.bold("Base branch")}: {cc.yellow(self.branch_info.base_branch)}',
f'{cc.bold("PR Description")}:\n{self.body}',
])

Expand Down

0 comments on commit c2fbefb

Please sign in to comment.