Is it possible to to create in ticket a link to a page in confluence using scriptrunner in jira post function?
The option described in the docking is not suitable, The page is needed in the wiki.
On the confluence side, I create a ticket backlink using {jira: key = $ {issue.key}} in the pagebody. But I do not understand how to create a link of the "Confluence page" type on the jira side.
import com.atlassian.applinks.api.ApplicationLink
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.jira.issue.Issue
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import com.atlassian.sal.api.net.ResponseHandler
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def ApplicationLink getPrimaryConfluenceLink() {
def applicationLinkService = ComponentLocator.getComponent(ApplicationLinkService)
final ApplicationLink conflLink = applicationLinkService.getPrimaryApplicationLink(ConfluenceApplicationType)
conflLink
}
Issue Issue = issue
def confluenceLink = getPrimaryConfluenceLink()
assert confluenceLink
def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()
def pageTitle = issue.key + " Discussion" as String
def pageBody = """h3. ${issue.summary}
{jira: key = ${issue.key}}
{quote}${issue.description}{quote}
"""
def params = [
type : "page",
title: pageTitle,
space: [
key: "testovoe"
],
body : [
storage: [
value : pageBody,
representation: "wiki"
],
],
]
authenticatedRequestFactory
.createRequest(Request.MethodType.POST, "rest/api/content")
.addHeader("Content-Type", "application/json")
.setRequestBody(new JsonBuilder(params).toString())
.execute(new ResponseHandler<Response>() {
@Override
void handle(Response response) throws ResponseException {
def webUrl = new JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]
def newurl = webUrl as String
def newweb = "https://my.confluenceserver.com" + newurl -"]"-"["
log.debug newweb
}
})