Created
October 22, 2020 15:35
-
-
Save nafeger/dc754f59645120df3f5e030dd0166067 to your computer and use it in GitHub Desktop.
Jira Adaptavist ScriptRunner Listener to post to Airtable
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
import groovy.json.JsonBuilder | |
import groovyx.net.http.ContentType | |
import groovyx.net.http.HTTPBuilder | |
import groovyx.net.http.Method | |
import org.apache.log4j.Logger | |
import org.apache.log4j.Level | |
import groovyx.net.http.* | |
/** | |
Change these based on api.airtable.com | |
*/ | |
final API_KEY = "YOUR API KEY HERE" | |
final AIRTABLE_BASE_ID = "appXXXXXX" | |
final AIRTABLE_TABLE_NAME = "Table Name" | |
def key = event.issue.getKey() | |
def type = event.issue.getIssueType().getName() | |
def action = event.getEventTypeId() | |
log.error("key identified: "+key) | |
def http = new HTTPBuilder("https://api.airtable.com") | |
http.request(Method.POST, ContentType.TEXT) { | |
uri.path = "/v0/${AIRTABLE_BASE_ID}/${AIRTABLE_TABLE_NAME}" | |
requestContentType = ContentType.JSON | |
headers.Authorization = "Bearer ${API_KEY}" | |
/* | |
This is not super pretty, but it is effective for writing a single record. | |
*/ | |
body = | |
"""{ | |
"records": [ | |
{ | |
"fields": { | |
"Info" : "${key}", | |
"Action": "${action}", | |
"Type": "${type}" | |
} | |
} | |
] | |
}""" | |
// log.error("Tracking body: >"+body+"<") | |
response.success = { resp, json -> log.error("key written: "+key)} | |
response.failure = { resp, json -> | |
log.error("key not deleted: "+key+" response: "+resp.statusLine) | |
throw new RuntimeException("Failure to record key: "+key) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is for a ScriptRunner running on JIRA server