-
-
Save tbg/c518ba3844f94abf4fff826f13be5300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import re | |
def get_commit_range(start_sha, end_sha): | |
command = ["git", "rev-list", f"^{start_sha}", f"{end_sha}"] | |
result = subprocess.run(command, capture_output=True, text=True) | |
return result.stdout.splitlines() | |
def generate_markdown(start_sha, end_sha): | |
commit_shas = get_commit_range(start_sha, end_sha) | |
current_pr = None | |
for commit_sha in commit_shas: | |
commit_info_cmd = ["git", "log", "-1", "--pretty=format:%s", commit_sha] | |
commit_info_result = subprocess.run(commit_info_cmd, capture_output=True, text=True) | |
commit_title = commit_info_result.stdout.strip() | |
pr_match = re.search(r'\(#(\d+)\)', commit_title) | |
if pr_match: | |
pr_number = pr_match.group(1) | |
if pr_number != current_pr: | |
current_pr = pr_number | |
print(f"- [ ] grpc/grpc-go#{pr_number}") | |
else: | |
if current_pr is not None: | |
current_pr = None | |
print("- [ ] grpc/grpc-go#0 [link](https://github.com/grpc/grpc-go/pull/0)") | |
print(f" - [{commit_title}](https://github.com/grpc/grpc-go/commit/{commit_sha})") | |
# Usage example | |
start_sha = 'v1.56.3' # older commit | |
end_sha = 'v1.68.0' # newer commit | |
generate_markdown(start_sha, end_sha) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment