diff --git a/sleuthpr/services/branches.py b/sleuthpr/services/branches.py index c5cd656..13d5f48 100644 --- a/sleuthpr/services/branches.py +++ b/sleuthpr/services/branches.py @@ -9,14 +9,17 @@ logger = logging.getLogger(__name__) -def update_sha(installation: Installation, repository: Repository, name: str, sha: str): +def update_sha(installation: Installation, repository: Repository, name: str, sha: str) -> RepositoryBranch: existing = repository.branches.filter(name=name).first() if not existing: - RepositoryBranch.objects.create(repository=repository, name=name, head_sha=sha) + branch = RepositoryBranch.objects.create(repository=repository, name=name, head_sha=sha) dirty = True else: dirty = dirty_set_all(existing, dict(head_sha=sha)) existing.save() + branch = existing if dirty: pull_requests.on_source_change(installation, repository, name, sha) + + return branch diff --git a/sleuthpr/variables.py b/sleuthpr/variables.py index 0effd36..dc39336 100644 --- a/sleuthpr/variables.py +++ b/sleuthpr/variables.py @@ -7,6 +7,7 @@ from sleuthpr.models import PullRequest from sleuthpr.models import ReviewState from sleuthpr.models import TriState +from sleuthpr.services import branches from sleuthpr.triggers import BASE_BRANCH_UPDATED from sleuthpr.triggers import PR_CLOSED from sleuthpr.triggers import PR_CREATED @@ -163,6 +164,16 @@ def _is_base_branch_synchronized(pull_request: PullRequest): repo = pull_request.repository branch_head = repo.branches.filter(name=pull_request.base_branch_name).first() + + if not branch_head: + # this doesn't exist because it is a github action and doesn't have the data loaded from the push + # event, so load it here + branch_head = branches.update_sha( + pull_request.repository.installation, + pull_request.repository, + pull_request.base_branch_name, + pull_request.base_sha, + ) if branch_head: branch_head.refresh_from_db() logger.info(f"Branch {branch_head.name} and head {branch_head.head_sha} for pr {pull_request.remote_id}")