Created
August 22, 2014 17:18
-
-
Save chaseroden/c71fd1d5b8547e0a983d to your computer and use it in GitHub Desktop.
Pivotal Tracker / Zendesk integrator
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 | |
# This script receives POSTs from a Zendesk target and submits comments to existing Pivotal Tracker stories via | |
# the Pivotal API | |
# The Zendesk target is a URL target with the following settings: | |
# Url: http://SERVER_ADDRESS/pvt?token=PVT_API_TOKEN_HERE&project=PVT_PROJECT_ID_HERE&story={{ticket.ticket_field_XXXXXXX}} | |
# Method: POST | |
# Attribute name: comment | |
# where: | |
# SERVER_ADDRESS is replaced with your server's address, obviously | |
# PVT_API_TOKEN_HERE is replaced with your API token from Pivotal Tracker | |
# PVT_PROJECT_ID_HERE is replaced with your Pivotal Tracker project ID from the URL | |
# and the X's in ticket_field_XXXXXXX are replaced to supply a custom field ID form | |
# Zendesk where you've put the Pivotal story number on each ticket. | |
# This works well with the built-in Zendesk Pivotal integration if you set up triggers to create the | |
# tickets and then use this integrator to update comments on the Pivotal stories. You will | |
# need some triggers set up to prevent looping -- make sure that Zendesk doesn't send its own comments back to | |
# Pivotal. | |
import json, requests | |
from bottle import get, post, request, route, run, template | |
@route('/hello/<name>') | |
def index(name): | |
return template('<b>Hello {{name}}</b>!', name=request.remote_addr) | |
@post('/pvt') | |
def submit_pvt_comment(): | |
# if request.remote_addr.startswith("192.161.144" or "173.201.33"): | |
# ^^ IP address ranges that Zendesk requests come from. Saved for future implementation if necessary. | |
pvtoken = request.params.get('token') | |
pvprojectid = request.params.get('project') | |
pvstoryid = request.params.get('story') | |
pvcomment = request.params.get('comment') | |
if pvtoken: | |
return postcomment(pvprojectid, pvstoryid, pvtoken, pvcomment).content | |
else: | |
return "<p>Your request was not understood.</p>" | |
def postcomment(projectid, storyid, token, commenttext): | |
storyurl = 'https://www.pivotaltracker.com/services/v5/projects/' + projectid + '/stories/' + storyid + '/comments' | |
headers = { "Content-Type": "application/json", "X-TrackerToken": token } | |
data = { "text": commenttext } | |
r = requests.post( storyurl, data=json.dumps(data), headers=headers ) | |
return r | |
run(host='0.0.0.0', port=80, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment