Skip to content

Commit

Permalink
Don't load info if api can't be contacted
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-parlette committed Jan 6, 2017
1 parent ce9bc6a commit 8d25ec3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 44 deletions.
53 changes: 33 additions & 20 deletions jira-to-trello/jira-to-trello
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import sys
import yaml
import trello
import trello.util
from jira import JIRA
import jira

global config
global log
Expand Down Expand Up @@ -189,23 +189,36 @@ if __name__ == "__main__":
options = {
'server': config['jira']['url'],
}
jira = JIRA(options, basic_auth=(
config['jira']['username'],
config['jira']['password']))
if not jira.search_issues("assignee={}".format(
config['jira']['username'])):
log.error("Error verifying Jira API connection")
sys.exit(2)

issue = jira.issue(args.issue)

if issue:
log.debug("Found issue {}, processing...".format(issue.key))
create_card(
name="{}: {}".format(
issue.key,
issue.fields.summary),
description=issue.fields.description,
link="{}/browse/{}".format(config['jira']['url'], issue.key))
api = None
try:
api = jira.JIRA(options, basic_auth=(
config['jira']['username'],
config['jira']['password']))
except jira.exceptions.JIRAError:
pass

if api:
if not api.search_issues("assignee={}".format(
config['jira']['username'])):
log.error("Error verifying Jira API connection")
sys.exit(2)

issue = api.issue(args.issue)

if issue:
log.debug("Found issue {}, processing...".format(issue.key))
create_card(
name="{}: {}".format(
issue.key,
issue.fields.summary),
description=issue.fields.description,
link="{}/browse/{}".format(config['jira']['url'], issue.key))
else:
log.error("Issue {} not found".format(args.issue))

else:
log.error("Issue {} not found".format(args.issue))
log.error("JIRA could not be contacted, no issue data will be loaded")
create_card(
name="{}: {}".format(args.issue, 'JIRA'),
description='',
link="{}/browse/{}".format(config['jira']['url'], args.issue))
61 changes: 37 additions & 24 deletions zendesk-to-trello/zendesk-to-trello
Original file line number Diff line number Diff line change
Expand Up @@ -182,31 +182,44 @@ if __name__ == "__main__":

log.debug("Initialization complete")

log.debug("Initializing Zendesk API...")
creds = {
'email': config['zendesk']['email'],
'password': config['zendesk']['password'],
'subdomain': config['zendesk']['subdomain'],
}
zendesk = zenpy.Zenpy(**creds)
if not zendesk.users.me():
log.error("Error getting current user with Zendesk API")
sys.exit(2)
zendesk = None
if (config['zendesk']['email'] and
config['zendesk']['password'] and
config['zendesk']['subdomain']):
log.debug("Initializing Zendesk API...")
creds = {
'email': config['zendesk']['email'],
'password': config['zendesk']['password'],
'subdomain': config['zendesk']['subdomain'],
}
zendesk = zenpy.Zenpy(**creds) or None
if not zendesk or not zendesk.users.me():
log.error("Error connecting to Zendesk API, Zendesk will not be queried...")

# I don't see a way to get a ticket except by search, 2016-06-08
for ticket in zendesk.search(args.ticket, type='ticket'):
log.debug("Processing {} from ticket search...".format(ticket.id))
# Only create ticket for the ID passed in
if str(ticket.id) != str(args.ticket):
log.debug("Skipping {}, as it does not match {}".format(
ticket.id,
args.ticket))
continue
log.info("Creating trello card for #{}".format(ticket.id))
if zendesk:
for ticket in zendesk.search(args.ticket, type='ticket'):
log.debug("Processing {} from ticket search...".format(ticket.id))
# Only create ticket for the ID passed in
if str(ticket.id) != str(args.ticket):
log.debug("Skipping {}, as it does not match {}".format(
ticket.id,
args.ticket))
continue
log.info("Creating trello card for #{}".format(ticket.id))
create_card(
name="{}: {}".format(
ticket.id,
ticket.subject),
description=ticket.description,
link="https://zenoss.zendesk.com/agent/tickets/{}".format(
ticket.id))
else:
log.info("Creating trello card for #{}".format(args.ticket))
create_card(
name="{}: {}".format(
ticket.id,
ticket.subject),
description=ticket.description,
link="https://zenoss.zendesk.com/agent/tickets/{}".format(
ticket.id))
args.ticket,
''),
description='',
link="https://guardrail.zendesk.com/agent/tickets/{}".format(
args.ticket))

0 comments on commit 8d25ec3

Please sign in to comment.