I am trying to create a custom picker using Jira Cloud REST API to fetch and return specific issues based on JQL filter.
What works:
What does not work
Questions:
import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
HTTPBuilder getHttpBuilder() {
new HTTPBuilder("https://mycompany.atlassian.net/rest/api/3/")
}
def fields = "summary"
search = { String inputValue ->
def jql= "project=DEVEX"
if(!inputValue.blank) jql += " AND summary ~ $inputValue"
def username = "my_email"
def password = "my_password"
def response = httpBuilder.request(Method.GET, ContentType.JSON) {
headers."Authorization" = "Basic ${"${username}:${password}".bytes.encodeBase64()}"
headers."User-Agent" = "Jira Data Center"
headers."Acceot" = "application/json"
uri.path = 'search'
uri.query = [jql: jql, fields: fields]
response.failure = { null }
} as Map
// issues[0].key => KEY-1
// issues[0].fields.summary => My issue
// issues[0].fields.customfield_10150.displayName => Last Name, First Name
response.issues
}
toOption = { Map<String, String> issue, Closure highlight ->
new PickerOption(
value: issue.key,
label: "${issue.key}: ${issue['fields']['summary']}",
html: "${highlight("${issue.key}: ${issue['fields']['summary']}", false)}",
)
}
getItemFromId = { String key ->
httpBuilder.request(Method.GET, ContentType.JSON) {
uri.path = "issue/$key"
uri.query = [fields: fields]
response.failure = { null }
}
}
renderItemViewHtml = { Map issue ->
"${issue.key}: ${issue['fields']['summary']}"
}
renderItemTextOnlyValue = renderItemViewHtml