Skip to content

Instantly share code, notes, and snippets.

@samdoran
Created October 14, 2019 21:16
Show Gist options
  • Save samdoran/a6f901ff7ff83d2c15c757191e02b9c9 to your computer and use it in GitHub Desktop.
Save samdoran/a6f901ff7ff83d2c15c757191e02b9c9 to your computer and use it in GitHub Desktop.
Merge GitHub PRs when the web UI is being dumb
#!/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