Last active
May 18, 2016 07:52
-
-
Save ngoduykhanh/b6b7a4a282e8d120e106 to your computer and use it in GitHub Desktop.
Getting jira webhook data for "issue_created" event
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
#!flask/bin/python | |
import json | |
import traceback | |
from flask import Flask, request, make_response, jsonify | |
app = Flask(__name__) | |
@app.route('/jira-create', methods=['POST']) | |
def create_ticket(): | |
if request.method == 'POST': | |
data = request.data | |
try: | |
jdata = json.loads(data) | |
if jdata['webhookEvent'] == 'jira:issue_created': | |
ticket_key = jdata['issue']['key'] | |
ticket_summary = jdata['issue']['fields']['summary'] | |
ticket_priority = jdata['issue']['fields']['priority']['name'] | |
ticket_description = jdata['issue']['fields']['description'] | |
ticket_assignee_displayname = jdata['issue']['fields']['assignee']['displayName'] if jdata['issue']['fields']['assignee'] else 'null' | |
ticket_assignee_username = jdata['issue']['fields']['assignee']['name'] if jdata['issue']['fields']['assignee'] else 'null' | |
ticket_reporter_displayname = jdata['issue']['fields']['reporter']['displayName'] if jdata['issue']['fields']['reporter'] else 'null' | |
ticket_reporter_username = jdata['issue']['fields']['reporter']['name'] if jdata['issue']['fields']['reporter'] else 'null' | |
print 'Ticket: %s | %s' % (ticket_key, ticket_summary) | |
print 'Priority: %s' % ticket_priority | |
print 'Description: %s' % ticket_description | |
print 'Assignee: %s (%s)' % (ticket_assignee_displayname, ticket_assignee_username) | |
print 'Reporter: %s (%s)' % (ticket_reporter_displayname, ticket_reporter_username) | |
return make_response('ok', 200) | |
else: | |
msg = 'Invalid JIRA hook event. It should be "jira:issue_created"' | |
print msg | |
return make_response(msg, 403) | |
except: | |
print traceback.format_exc() | |
msg = 'Incorrect data! Can not parse to json format' | |
print msg | |
return make_response(msg, 500) | |
else: | |
msg = "This method is not support" | |
print msg | |
return make_response(msg, 403) | |
@app.route('/', methods=['GET']) | |
def index(): | |
return make_response("Skype bot API for JIRA notification", 200) | |
if __name__ == '__main__': | |
app.run(debug = True, host='0.0.0.0', port=9191) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment