Skip to content

Commit

Permalink
Make already-merged check case-insensitive
Browse files Browse the repository at this point in the history
Summary: BPF maintainers have normalization scripts that fixes up commits before pushes. One thing it does is capitalize the first word after the prefix.

Reviewed By: anakryiko

Differential Revision: D57895638

fbshipit-source-id: ead8de2e871ad63a5d8f615b0fad75eca55ce3f7
  • Loading branch information
Daniel Xu authored and facebook-github-bot committed May 29, 2024
1 parent 6fe880f commit b9a8b42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions kernel_patches_daemon/branch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,14 @@ async def _series_already_applied(repo: git.Repo, series: Series) -> bool:
"""
try:
summaries = {
commit.summary
commit.summary.lower()
for commit in repo.iter_commits(max_count=ALREADY_MERGED_LOOKBACK)
}
except git.exc.GitCommandError:
logger.exception("Failed to check series application status")
return False

return all(ps in summaries for ps in await series.patch_subjects())
return all(ps.lower() in summaries for ps in await series.patch_subjects())


def _is_outdated_pr(pr: PullRequest) -> bool:
Expand Down
19 changes: 14 additions & 5 deletions tests/test_branch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ def setUp(self):
# Note despite file.txt not changing, this still creates commits.
for i in range(1, 2 * ALREADY_MERGED_LOOKBACK + 1):
self.repo.index.add(["file.txt"])
self.repo.index.commit(f"{i}\n\nThis commit body should never match")
self.repo.index.commit(f"Commit {i}\n\nThis commit body should never match")

def tearDown(self):
shutil.rmtree(self.tmp_dir)
Expand Down Expand Up @@ -936,24 +936,33 @@ async def _get_series(self, m: aioresponses, summaries: List[str]) -> Series:
async def test_applied_all(self, m: aioresponses):
in_1 = ALREADY_MERGED_LOOKBACK + 33
in_2 = ALREADY_MERGED_LOOKBACK + 34
series = await self._get_series(m, [f"{in_1}", f"[tag] {in_2}"])
series = await self._get_series(m, [f"Commit {in_1}", f"[tag] Commit {in_2}"])
self.assertTrue(await _series_already_applied(self.repo, series))

@aioresponses()
async def test_applied_none_newer(self, m: aioresponses):
out_1 = ALREADY_MERGED_LOOKBACK * 2 + 2
out_2 = ALREADY_MERGED_LOOKBACK * 2 + 3
series = await self._get_series(m, [f"[some tags]{out_1}", f"[tag] {out_2}"])
series = await self._get_series(
m, [f"[some tags]Commit {out_1}", f"[tag] Commit {out_2}"]
)
self.assertFalse(await _series_already_applied(self.repo, series))

@aioresponses()
async def test_applied_none_older(self, m: aioresponses):
series = await self._get_series(m, ["[some tags]33", "[tag] 34"])
series = await self._get_series(m, ["[some tags]Commit 33", "[tag] Commit 34"])
self.assertFalse(await _series_already_applied(self.repo, series))

@aioresponses()
async def test_applied_some(self, m: aioresponses):
inside = ALREADY_MERGED_LOOKBACK + 55
out = ALREADY_MERGED_LOOKBACK * 3
series = await self._get_series(m, [str(inside), str(out)])
series = await self._get_series(m, [f"Commit {inside}", f"Commit {out}"])
self.assertFalse(await _series_already_applied(self.repo, series))

@aioresponses()
async def test_applied_all_case_insensitive(self, m: aioresponses):
in_1 = ALREADY_MERGED_LOOKBACK + 33
in_2 = ALREADY_MERGED_LOOKBACK + 34
series = await self._get_series(m, [f"commit {in_1}", f"[tag] COMMIT {in_2}"])
self.assertTrue(await _series_already_applied(self.repo, series))

0 comments on commit b9a8b42

Please sign in to comment.