Skip to content

Commit

Permalink
fixup! Refactor main arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
sebalix committed Sep 18, 2024
1 parent 5694b98 commit b030998
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions oca_port/port_addon_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import os
import hashlib
import itertools
import shutil
import tempfile
import urllib.parse
Expand Down Expand Up @@ -115,11 +116,17 @@ def run(self):
session.clear()
return True, None

def _get_dest_branch_name(self, prs):
def _get_dest_branch_name(self, branches_diff):
dest_branch_name = self.app.destination.branch
# Define a destination branch if not set
if prs and not dest_branch_name:
h = hashlib.shake_256(prs.encode())
if branches_diff.commits_diff and not dest_branch_name:
commits_to_port = [
commit.hexsha
for commit in itertools.chain.from_iterable(
branches_diff.commits_diff.values()
)
]
h = hashlib.shake_256("-".join(commits_to_port).encode())
key = h.hexdigest(3)
dest_branch_name = PR_BRANCH_NAME.format(
addon=self.app.addon,
Expand All @@ -131,10 +138,9 @@ def _get_dest_branch_name(self, prs):

def _port_pull_requests(self, branches_diff):
"""Open new Pull Requests (if it doesn't exist) on the GitHub repository."""
prs = "-".join(str(pr.number) for pr in branches_diff.commits_diff)
dest_branch_name = self._get_dest_branch_name(prs)
dest_branch_name = self._get_dest_branch_name(branches_diff)
# Nothing to port
if not prs or not dest_branch_name:
if not branches_diff.commits_diff or not dest_branch_name:
return False
self.app.destination.branch = dest_branch_name
# Check if destination branch exists, and create it if not
Expand Down

0 comments on commit b030998

Please sign in to comment.