Created
October 14, 2019 21:16
-
-
Save samdoran/a6f901ff7ff83d2c15c757191e02b9c9 to your computer and use it in GitHub Desktop.
Merge GitHub PRs when the web UI is being dumb
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
#!/usr/bin/env python | |
import argparse | |
import re | |
import os | |
from github3 import GitHub | |
parser = argparse.ArgumentParser() | |
parser.add_argument('prs', nargs='+') | |
parser.add_argument('--token', default=os.getenv('GITHUB_TOKEN')) | |
parser.add_argument('--commit-message', '-m', default=None) | |
parser.add_argument('--commit-title', '-t', default=None) | |
args = parser.parse_args() | |
PR_RE = re.compile(r'https://github.com/([^/]+)/([^/]+)/pull/(\d+)') | |
def parse_url(url): | |
match = PR_RE.match(url) | |
if not match: | |
raise SystemExit('Invalid URL: %s' % url) | |
return match.groups() | |
assert args.token | |
g = GitHub(token=args.token) | |
for pr_url in args.prs: | |
owner, _repo, number = parse_url(pr_url) | |
repo = g.repository(owner, _repo) | |
pr = repo.pull_request(int(number)) | |
print('%r %r' % (repo, pr)) | |
pr.merge(merge_method='squash', commit_message=args.commit_message, commit_title=args.commit_title) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment