Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper #31152

Merged
merged 5 commits into from
May 31, 2024
Merged

helper #31152

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions utils/patch_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
ArthurZucker marked this conversation as resolved.
Show resolved Hide resolved
Pass in a list of PR:
`python utils/patch
ArthurZucker marked this conversation as resolved.
Show resolved Hide resolved
ArthurZucker marked this conversation as resolved.
Show resolved Hide resolved
"""

import argparse
from git import Repo, GitCommandError
from packaging import version

def get_merge_commit(repo, pr_number, since_tag):
try:
# Use git log to find the merge commit for the PR within the given tag range
merge_commit = next(repo.iter_commits(f'v{since_tag}...HEAD', grep=f'#{pr_number}'))
return merge_commit
except StopIteration:
print(f"No merge commit found for PR #{pr_number} between tags {since_tag} and {main}")
return None
except GitCommandError as e:
print(f"Error finding merge commit for PR #{pr_number}: {str(e)}")
return None

def main(pr_numbers):
repo = Repo('..') # Initialize the Repo object for the current directory
merge_commits = []

tags = {}
for tag in repo.tags:
try:
# Parse and sort tags, skip invalid ones
tag_ver = version.parse(tag.name)
tags[tag_ver] = tag
except Exception as e:
print(f"Skipping invalid version tag: {tag.name}")

last_tag = sorted(tags)[-1]
major_minor = ".".join([str(last_tag.major),str(last_tag.minor)]) + ".0"
ArthurZucker marked this conversation as resolved.
Show resolved Hide resolved
# Iterate through tag ranges to find the merge commits
for pr in pr_numbers:
commit = get_merge_commit(repo, pr, major_minor)
if commit:
merge_commits.append(commit)

# Sort commits by date
merge_commits.sort(key=lambda commit: commit.committed_datetime)
ArthurZucker marked this conversation as resolved.
Show resolved Hide resolved

# Output the git cherry-pick commands
print("Git cherry-pick commands to run:")
for commit in merge_commits:
print(f"git cherry-pick {commit.hexsha} #{commit.committed_datetime}")

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Find and sort merge commits for specified PRs.")
parser.add_argument('--prs', nargs='+', default=["31108", "31054", "31008", "31010", "31004"],type=int,help="PR numbers to find merge commits for")
ArthurZucker marked this conversation as resolved.
Show resolved Hide resolved

args = parser.parse_args()
main(args.prs)
Loading