Skip to content

Instantly share code, notes, and snippets.

@mpobrien
Last active December 24, 2015 04:19
Show Gist options
  • Save mpobrien/6742945 to your computer and use it in GitHub Desktop.
Save mpobrien/6742945 to your computer and use it in GitHub Desktop.
util for taking output of "git branch" and printing jira status and summary for all branches named after issues in jira.
#!/usr/bin/env python
import fileinput
import getpass
import requests
import json
import re
import keyring
import sys
#SETUP:
#sudo pip install keyring requests
#Edit the script to contain your jira username: JIRA_USER = "<username>"
#Run it by piping output of "git branch" to the script.
#Before:
#$ git branch
#* master
# mci-224
# mci-462
# mci-548
#After:
#
#$ git branch | jirabranch
#* master
# mci-224 Resolved [ Put MCI into Jenkins ]
# mci-462 In Code Review [ Timeline UI is slow and frequently timing out ]
# mci-548 Resolved [ update tasks page to use new formatting colors/icons/etc ]
JIRA_USER = "mpobrien" #edit this to your jira username.
JIRA_SERVER = "jira.mongodb.org"
lineregex = re.compile("\s*\*?\s*(\w+-\d+).*")
def main(args):
if args and args[0] == "--logout":
keyring.delete_password(JIRA_SERVER,JIRA_USER)
sys.exit(0)
pw = keyring.get_password(JIRA_SERVER, JIRA_USER)
if not pw:
print "Password for ", JIRA_USER
pw = getpass.getpass()
keyring.set_password(JIRA_SERVER, JIRA_USER, pw)
mode = None
for line in fileinput.input():
matches = lineregex.match(line)
if matches:
ticketid = matches.groups()[0]
resp = requests.get("https://%s/rest/api/latest/issue/%s" % (JIRA_SERVER, ticketid), auth=(JIRA_USER,pw), verify=False)
if resp.status_code != 200:
print line,
data = json.loads(resp.content)
summary = data['fields']['summary']
status = data['fields']['status']['name']
print line.rstrip(), status, "[",summary.strip(),"]"
#pprint.pprint(data['fields'])
else:
print line,
if __name__ == '__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment