Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
errbot jira integration
@botcmd(split_args_with=None)
def tickets(self, mess, args):
"""list jira tickets - options: -user=[def: you], -status=[RE: Closed], -project=[RE: Operations] -search=[string]"""
options = {'server': 'https://jira.company.com'}
user = utils.get_sender_username(mess)
status = '(status = Open OR status = Reopened OR status = "In Progress")'
tmpstatus = None
#project = "Operations"
project = None
search = None
for arg in args:
if re.match(r'-user=', arg):
user = arg.split("=")[1].strip()
if re.match(r'-status=', arg):
tmpstatus = arg.split("=")[1].strip()
if re.match(r'-project=', arg):
project = arg.split("=")[1].strip()
if re.match(r'-search=', arg):
search = arg.split("=")[1].strip()
names = {
"tom": "tomjones",
"allen": "aturing",
"sid": "svicious",
}
if tmpstatus:
status = "status = %s" % (tmpstatus)
if len(user.split()) > 1:
user = user.split()[0]
if user.lower() in names.keys():
user = names[user.lower()]
jira = JIRA(options, basic_auth=('errbot', 'YOURPASSWORDHERE'))
sstring = '%s AND assignee=%s' % (status, user)
if project:
sstring += " AND project=%s" % (project)
if search:
sstring += " AND text ~ %s" % (search)
ops = jira.search_issues('%s' % (sstring), maxResults=False)
tickets = ""
yield "Search: %s" % (sstring)
for issue in ops:
tickets += "https://jira.vast.com/browse/%s - %s - %s\n" % (issue,issue.fields.status,issue.fields.summary)
tickets += "Total tickets: %s" % str(len(tickets.split("\n")) - 2)
yield tickets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.