Skip to content

Instantly share code, notes, and snippets.

@eurica
Created June 17, 2016 08:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save eurica/6d5ee78b8da68f94a092702f32ca0070 to your computer and use it in GitHub Desktop.
function transform(PD) {
var webhook = PD.inputRequest
var body = webhook.body || JSON.parse(webhook.rawBody);
var incident_key = (body.message.markdown||")").split(")")[0]; /*so hacky, but resource.workItemId isn't populated on create*/
var description = body.message.text.split("\r\n")[0];
var url = null;
if(incident_key.split("(").length==2) {url = incident_key.split("(")[1];}
var event_type = PD.Trigger;
try {
if(body.resource.fields["System.State"].newValue == "Resolved") { event_type = PD.Resolve; }
} catch (e) {}
var normalized_event = {
event_type: event_type,
incident_key: incident_key,
description: description,
details: body.resource.fields,
client: "View in Team Foundation Server",
client_url: url
};
PD.emitEvent(normalized_event);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment