Merge pull request #4473 from arcwiser/fix/pr-overlap-fetch-batches

fix(tools): batch pr_overlap fetch refspecs
This commit is contained in:
Dean 2026-10-13 07:27:51 +13:00 committed by GitHub
commit 9907993e5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -13,6 +13,7 @@ DEPENDS = re.compile(r'Depends on:[ \t]*((?:#\d+\b(?:(?:[ \t]*,[ \t]*(?:and[ \t]
PLAIN_DEPENDS = re.compile(r'Depends on[ \t]+(#\d+\b(?:(?:[ \t]*,[ \t]*(?:and[ \t]+)?|[ \t]+and[ \t]+)#\d+\b)*)')
HUNK = re.compile(r"^@@ -(\d+)(?:,(\d+))?", re.M)
MARKER = "<!-- pr-overlap -->"
FETCH_REFS = 100
def git(*args):
@ -51,7 +52,8 @@ def open_prs(base):
def fetch(base, prs):
refspecs = [f"+refs/heads/{base}:refs/pr/base"] + [f"+{pr['sha']}:{pr['ref']}" for pr in prs.values()]
git("fetch", "--no-tags", "-q", f"https://github.com/{REPO}.git", *refspecs)
for start in range(0, len(refspecs), FETCH_REFS):
git("fetch", "--no-tags", "-q", f"https://github.com/{REPO}.git", *refspecs[start:start + FETCH_REFS])
def merge(*args):

View File

@ -69,6 +69,22 @@ class FetchTests(unittest.TestCase):
"+refs/heads/main:refs/pr/base", f"+{'a' * 40}:refs/pr/7", f"+{'b' * 40}:refs/pr/9",
)
def test_batches_large_sets_of_pull_request_heads(self):
prs = {
number: {
"ref": f"refs/pr/{number}", "sha": f"{number:040x}",
"author": "contributor", "depends": set(),
}
for number in range(250)
}
with patch.object(pr_overlap, "REPO", "owner/project", create=True), \
patch.object(pr_overlap, "git", return_value="") as git:
pr_overlap.fetch("main", prs)
self.assertEqual(git.call_count, 3)
self.assertEqual([len(call.args) - 4 for call in git.call_args_list], [100, 100, 51])
self.assertEqual(git.call_args_list[0].args[4], "+refs/heads/main:refs/pr/base")
self.assertEqual(git.call_args_list[-1].args[-1], "+00000000000000000000000000000000000000f9:refs/pr/249")
if __name__ == "__main__":
unittest.main()