We have two Jira instances. We need to do a jql query based on a filter to get a list of keys from instance 1 and then get their remote link keys in instance 2 where key matches RMI-*.
Is a custom jql function the way to approach this?
Hi @Admin User welcome to the community. If you already have Scriptrunner installed then there already is a jql function for this. Have a look here for review.
Hi, thanks for the response. Unless I am missing something linkedIssuesOfRemote("filter='ABC 1.0.1'") or something like it isn't possible.
I need to jql query instance 2 with the filter and end up with a list of issues from instance that are remotely linked to the jql.
So I don't need to just find the issue with links, I need to find the remote link keys.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't believe so. But I'm thinking a custom jql that runs against a remote host which returns a list of keys allows us to query each individual key against the rest API to get remote link keys should be possible.
So in Jira A:
ScriptRunner uses ApplicationLinkService to perform a rest call doing a JQL query against Jira B. The results will be parsed to produce a list of keys.
We then iterate through those list of keys querying the rest API for remote link keys starting with ABC-* and produce a list of keys in Jira A.
With a custom JQL we can hopefully run a JQL with a Jira B filter to get Jira A keys.
Following code is partly done and tested in the script console but need to complete getting the remote links from the initial query and then figure out how to run this into a custom JQL.
import groovy.json.JsonSlurper
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.applinks.api.application.jira.JiraApplicationType
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import org.apache.log4j.Level
import static com.atlassian.sal.api.net.Request.MethodType.GET
import com.atlassian.applinks.api.ApplicationLinkResponseHandler
log.setLevel(Level.DEBUG)
def appLinkService = ComponentLocator.getComponent(ApplicationLinkService)
def remoteJiraUrl = "https://jira.com"
def applicationLinkService = ComponentAccessor.getComponent(ApplicationLinkService)
def applicationLink = applicationLinkService.getApplicationLinks(JiraApplicationType).find {
it.displayUrl.toString() == remoteJiraUrl
}
// Check if the application link was found
if (applicationLink) {
log.debug "Application link found for ${remoteJiraUrl}: ${applicationLink.getDisplayUrl()}"
} else {
log.debug "Application link not found for ${remoteJiraUrl}"
}
applicationLinkRequestFactory = applicationLink.createAuthenticatedRequestFactory()
// Define the remote host URL and JQL filter
jqlFilter = "filter = 'ABC 1.0.1'"
// Connect to the remote host and run the JQL query
def runJQLQueryOnRemote(String host, String jql, int start = 0, int limit = 50) {
def apiUrl = "/rest/api/latest/search?jql=${URLEncoder.encode(jqlFilter, "UTF-8")}&fields=key?startAt=${start}&maxResults=${limit}"
log.debug apiUrl
def request = applicationLinkRequestFactory.createRequest(GET, apiUrl)
def handler = new ApplicationLinkResponseHandler<Map>() {
@Override
Map credentialsRequired(Response response) throws ResponseException {
null
}
@Override
Map handle(Response response) throws ResponseException {
assert response.statusCode == 200
new JsonSlurper().parseText(response.getResponseBodyAsString()) as Map
}
}
def sessionDetails = request.execute(handler)
return sessionDetails
}
// Get the list of issues from the remote host
def issues = []
def start = 0
def limit = 200
def totalResults = 0
def remoteIssues = runJQLQueryOnRemote(remoteJiraUrl, jqlFilter, start, limit)
remoteIssues.issues.each {
issues.add it.key
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.