I am trying to get all linked tasks when pull request is opened:

Let me explain what I mean. For example, I have:
- two projects - "Project_A" and "Project_B".
- one issue of "Project_A" such as "project_A_issue_1" and 4 issues of "Project_B" such as "project_B_issue_1" and "project_B_issue_2", "project_B_issue_3" and "project_B_issue_4"
And I am creating a pull request of issues "Project_B" such as "project_B_issue_3" and "project_B_issue_4". The issue "project_B_issue_3" has links to issues:
- "project_A_issue_1"
- "project_B_issue_1" and "project_B_issue_2"
What I want is when pull request is created, then I need to read all these issues such as "project_A_issue_1", "project_B_issue_1" and "project_B_issue_2" in custom event handler "PullRequestOpenedEvent".
So I've borrowed code from here and adapted it to create task in Jira. Tasks are created perfectly.
How can all these issues ("project_A_issue_1", "project_B_issue_1" and "project_B_issue_2") can be read in these piece of code?
package examples.bitbucket.handler
import com.atlassian.applinks.api.ApplicationLinkResponseHandler
import com.atlassian.plugin.PluginAccessor
import com.atlassian.sal.api.UrlMode
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.Response
import com.atlassian.bitbucket.event.pull.PullRequestOpenRequestedEvent
import com.atlassian.bitbucket.integration.jira.JiraIssueService
import com.onresolve.scriptrunner.canned.bitbucket.util.BitbucketBaseScript
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.bitbucket.event.CancelableEvent
import com.atlassian.bitbucket.event.pull.PullRequestOpenedEvent
@BaseScript BitbucketBaseScript baseScript
def pluginAccessor = ComponentLocator.getComponent(PluginAccessor.class)
def jiraIssueService = ScriptRunnerImpl.getOsgiService(JiraIssueService)
def pullRequest = event.getPullRequest()
def repository = pullRequest.fromRef.repository
assert pullRequest
def keys = jiraIssueService.getIssuesForPullRequest(repository.id, pullRequest.id)*.key
def keySize = keys.size()
def jiraLink = getJiraAppLink()
def authenticatedRequestFactory = jiraLink.createImpersonatingAuthenticatedRequestFactory()
def input = '''{
"fields":
{
"project" : { "key" : "E" },
"issuetype" : { "name" : "Task" },
"summary" : "Foo summary''' + "${key}" + '''",
"description" : "''' + "Foo summary" + '''",
"components": [{ "id": "11382" }],
"reporter": {"name": "fooUser"}
}
}'''
authenticatedRequestFactory
.createRequest(Request.MethodType.POST, "rest/api/2/issue")
.addHeader("Content-Type", "application/json")
.setEntity(input)
.execute([
handle: { Response response ->
if (response.successful) {
log.debug "issue is created"
} else {
log.warn "Failed to create comment: $response.responseBodyAsStream"
}
}] as ApplicationLinkResponseHandler<Void>
)
}