Created
June 5, 2013 19:54
-
-
Save mattfinlayson/5716790 to your computer and use it in GitHub Desktop.
Quick jira integration with python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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