Use case: You've worked on a lot of issues, many of them have been fixed
and merged. You now want the branches corresponding to fixed issues deleted
from your local repo as well as your github(which was cloned from
apache/incubator-lens).
Assumption: branch names are like LENS-120, LENS-120.1, etc. Remote name
origin is your github fork.
Attaching a utility. Save it anywhere(e.g. ~/) and run it while inside a
repo. python ~/clean_merged_branches.py. This deletes all such branches.
Helps in keeping only the branches that are being worked upon.
import os, sys, commands, urllib, json, re
for branch in (x for x in commands.getoutput("git branch | awk '{print $(NF)}'").strip().split() if x[:5] == 'LENS-'):
issue = re.match(r'^LENS-\d+', branch).group(0)
info = json.loads(urllib.urlopen("https://issues.apache.org/jira/rest/api/latest/issue/%s/" % issue).read())
resolution = info['fields']['resolution']
if resolution is not None:
if resolution['name'] == 'Fixed':
print "Deleting branch %s as issue %s is marked Fixed" % (branch, issue)
os.system("git branch -D %s" % branch)
os.system("git push origin --delete %s" % branch)