Skip to content

Instantly share code, notes, and snippets.

@mattfinlayson
Created June 5, 2013 19:54
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 mattfinlayson/5716790 to your computer and use it in GitHub Desktop.
Save mattfinlayson/5716790 to your computer and use it in GitHub Desktop.
Quick jira integration with python.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from jira.client import JIRA
import sys
import pprint
def connect_jira(jira_server, jira_user, jira_password):
'''
Connect to JIRA. Return None on error
'''
try:
jira_options = {'server': jira_server}
jira = JIRA(options=jira_options,
# Note the tuple
basic_auth=(jira_user,
jira_password))
return jira
except Exception,e:
print "Failed to connect to JIRA: %s" % e
return None
def print_issue(issue):
'''
Print out formatted jira issue
'''
print "Issue: %s" % issue.key
print "Description: %s" % issue.fields.description
print "Assignee: %s" % issue.fields.assignee.displayName
print "Status: %s" % issue.fields.status.name
print "Link: %s/browse/%s" % (server, issue.key)
server = 'https://jira.domain.com'
jira = connect_jira(server, 'username', 'password')
if len(sys.argv) < 2:
sys.exit("You must give an issue id, dick.")
issueId = sys.argv[1]
try:
issue = jira.issue(issueId)
print dir(issue)
print dir(issue.fields)
pprint.pprint(issue.fields)
except Exception,e:
print "Can't find that ticket, dick."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment