Skip to content

Instantly share code, notes, and snippets.

@Zannick
Created June 1, 2021 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zannick/1f3dbdd156b7a09c4f5fe4a85f2307da to your computer and use it in GitHub Desktop.
Save Zannick/1f3dbdd156b7a09c4f5fe4a85f2307da to your computer and use it in GitHub Desktop.
Github merge PR aliases
[alias]
pr = "!f() { git fetch -fu ${2:-$(git remote |grep ^upstream || echo origin)} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f"
pr-clean = "!git for-each-ref refs/heads/pr/* --format='%(refname)' | while read ref ; do branch=${ref#refs/heads/} ; git branch -D $branch ; done"
mpr = "!f() { git merge --no-ff --no-commit pr/$1 -m \"Merge $(github_get_issue $( (git remote get-url upstream 2>/dev/null || git remote get-url origin ) | sed -e 's/^[^:]*://' -e 's/[.].*$//') $1)\"; }; f"
jfmpr = "!f() { git fetch -fu ${2:-$(git remote |grep ^upstream || echo origin)} refs/pull/$1/head:pr/$1 && git merge --no-ff --no-commit pr/$1 -m \"Merge $(github_get_issue $( (git remote get-url upstream 2>/dev/null || git remote get-url origin ) | sed -e 's/^[^:]*://' -e 's/[.].*$//') $1)\"; }; f"
#!/usr/bin/python3
# -*- encoding=utf-8 -*-
#
# Prereq:
# $ pip3 install --user PyGithub
#
# Rename this file `github_get_issue`, move it to `~/bin`, and make it executable to use the aliases.
import github
import sys
def get_issue(repo, issue_num):
g = github.Github()
return g.get_repo(repo, lazy=True).get_issue(issue_num)
if __name__ == '__main__':
if len(sys.argv) < 3:
print('Usage: {0} <user/repo: str> <issue_num: int>'.format(sys.argv[0]))
sys.exit(1)
if not sys.argv[2].isnumeric():
print('Usage: {0} <user/repo: str> <issue_num: int>\nERROR: {1!r} is not numeric'.format(
sys.argv[0], sys.argv[2]))
sys.exit(1)
i = get_issue(sys.argv[1], int(sys.argv[2]))
br = '"' if "'" in i.title else "'"
print('{br}{i.title}{br} (#{i.number})'.format(br=br, i=i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment