From 5a1be2610ff9003ec124ae12a2f510d0867c83b0 Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Fri, 4 Oct 2024 16:05:34 -0700 Subject: [PATCH] Factor out code change detection into helper function Summary: Set up for next diff where we add additional checks. Reviewed By: danielocfb Differential Revision: D63914822 fbshipit-source-id: a4e9d6bea3be657b5fb4538b6c021a50aec07dca --- kernel_patches_daemon/branch_worker.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel_patches_daemon/branch_worker.py b/kernel_patches_daemon/branch_worker.py index 1386544..8a01ca7 100644 --- a/kernel_patches_daemon/branch_worker.py +++ b/kernel_patches_daemon/branch_worker.py @@ -448,6 +448,14 @@ async def _series_already_applied(repo: git.Repo, series: Series) -> bool: return any(ps.lower() in summaries for ps in await series.patch_subjects()) +def _is_branch_changed(repo: git.Repo, old_branch: str, new_branch: str) -> bool: + """ + Returns whether or not the new_branch (in local repo) is different from + the old_branch (remote repo). + """ + return repo.git.diff(new_branch, old_branch) + + def _is_outdated_pr(pr: PullRequest) -> bool: """ Check if a pull request is outdated, i.e., whether it has not seen an update recently. @@ -928,8 +936,8 @@ async def apply_push_comment( # which could mean that we applied new set of patches or just rebased if branch_name in self.branches and ( branch_name not in self.all_prs # NO PR yet - or self.repo_local.git.diff( - branch_name, f"remotes/origin/{branch_name}" + or _is_branch_changed( + self.repo_local, f"remotes/origin/{branch_name}", branch_name ) # have code changes ): # we have branch, but either NO PR or there is code changes, we must try to