Created
December 31, 2019 08:14
-
-
Save woky/7f32b03a45fc183dda99fb16d01a53e6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
import re | |
from subprocess import check_output | |
from typing import Iterator | |
class BadCommitEx(Exception): | |
def __init__(self, log_line): | |
(sha1, author, subject) = log_line.split(None, 2) | |
super().__init__( | |
'Top commit does not appear to be a Bors merge. ' | |
f'SHA1={sha1}, Author="{author}", Subject="{subject}"') | |
def parse_pr_numbers_from_bors_merge() -> Iterator[int]: | |
cmd = "git log --format='%h %an %s' -1" | |
log_line = check_output(cmd, text=True, shell=True).strip() | |
parts = log_line.split() | |
if parts[1:3] != ['bors[bot]', 'Merge']: | |
raise BadCommitEx(log_line) | |
pr_parts = parts[3:] | |
if not pr_parts: | |
raise BadCommitEx(log_line) | |
for pr_str in pr_parts: | |
match = re.match(r'#(\d+)', pr_str) | |
if not match: | |
raise BadCommitEx(log_line) | |
yield int(match.group(1)) | |
for pr_num in parse_pr_numbers_from_bors_merge(): | |
print(pr_num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment