Skip to content

Commit 43d91e5

Browse files
Copilotharupyclaude
authored
Sort commits by date for correct cherry-pick ordering in check_patch_prs.py (#20228)
Signed-off-by: harupy <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: harupy <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: Harutaka Kawamura <[email protected]>
1 parent 4225478 commit 43d91e5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

dev/check_patch_prs.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def get_release_branch(version: str) -> str:
4141
class Commit:
4242
sha: str
4343
pr_num: int
44+
date: str
4445

4546

4647
def get_commit_count(branch: str, since: str) -> int:
@@ -79,6 +80,7 @@ def get_commit_count(branch: str, since: str) -> int:
7980
def get_commits(branch: str) -> list[Commit]:
8081
"""
8182
Get the commits in the release branch via GitHub API (last 90 days).
83+
Returns commits sorted by date (oldest first).
8284
"""
8385
per_page = 100
8486
pr_rgx = re.compile(r".+\s+\(#(\d+)\)$")
@@ -111,14 +113,17 @@ def fetch_page(page: int) -> list[Commit]:
111113
for item in response.json():
112114
msg = item["commit"]["message"].split("\n")[0]
113115
if m := pr_rgx.search(msg):
114-
commits.append(Commit(sha=item["sha"], pr_num=int(m.group(1))))
116+
# Use committer date (not author date) because cherry-picked commits
117+
# retain the original author date but get a new committer date.
118+
date = item["commit"]["committer"]["date"]
119+
commits.append(Commit(sha=item["sha"], pr_num=int(m.group(1)), date=date))
115120
return commits
116121

117122
# Fetch all pages in parallel. executor.map preserves order.
118123
with concurrent.futures.ThreadPoolExecutor() as executor:
119124
results = executor.map(fetch_page, range(1, total_pages + 1))
120125

121-
return list(itertools.chain.from_iterable(results))
126+
return sorted(itertools.chain.from_iterable(results), key=lambda c: c.date)
122127

123128

124129
@dataclass(frozen=True)
@@ -171,15 +176,14 @@ def main(version: str, dry_run: bool) -> None:
171176

172177
master_commits = get_commits("master")
173178
cherry_picks = [c.sha for c in master_commits if c.pr_num in not_cherry_picked]
174-
# reverse the order of cherry-picks to maintain the order of PRs
175179
print("\n# Steps to cherry-pick the patch PRs:")
176180
print(
177181
f"1. Make sure your local master and {release_branch} branches are synced with "
178182
"upstream."
179183
)
180184
print(f"2. Cut a new branch from {release_branch} (e.g. {release_branch}-cherry-picks).")
181185
print("3. Run the following command on the new branch:\n")
182-
print("git cherry-pick " + " ".join(cherry_picks[::-1]))
186+
print("git cherry-pick " + " ".join(cherry_picks))
183187
print(f"\n4. File a PR against {release_branch}.")
184188
sys.exit(0 if dry_run else 1)
185189

0 commit comments

Comments
 (0)