Hi All, I am using a post-function in the create step of one of my issues that generates a new confluence page and links the page. There is a link in Jira to confluence, and a link in confluence to Jira.
So it works if I use the "Create" issue link from the main Jira page. But most of the time I need to create these issues from another issue type. So I call a post-function ->Clones and link issue. It creates the issue, generates the wiki page, there is a link in the confluence page back to jira but Jira does not have a link to the confluence page.
-So I know the script works, because it works from create button
-I know the script is being called when using the "Clone and links" script because the wiki page is created.
But I don't see how in this script it is creating the link so I am not sure how to fix it. I have tried adding
checkLink = {link -> true}; in the additional actions section of the clone link, but no difference.
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 groovy.xml.MarkupBuilder
static ApplicationLink getPrimaryConfluenceLink() {
def applicationLinkService = ComponentLocator.getComponent(ApplicationLinkService.class)
final ApplicationLink conflLink = applicationLinkService.getPrimaryApplicationLink(ConfluenceApplicationType.class)
conflLink
}
// the issue provided to us in the binding
Issue issue = issue
def confluenceLink = getPrimaryConfluenceLink()
assert confluenceLink // must have a working app link set up
def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()
// write storage format using an XML builder
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.'ac:structured-macro'('ac:name': "jira") {
'ac:parameter'('ac:name': "key", issue.key)
'ac:parameter' ('ac:name': "server", "ES PoC JIRA")
'ac:parameter' ('ac:name': "serverId", "########")
}
// retrieve contents of "template page"
def confResponse = null
authenticatedRequestFactory
.createRequest(Request.MethodType.GET, "rest/api/content?type=page&title=fm00876_IndependentDesignReviewRecord&expand=body.storage.value")
.addHeader("Content-Type", "application/json")
.execute(
new ResponseHandler<Response>()
{
@Override
void handle(Response response) throws ResponseException {
confResponse = new JsonSlurper().parseText(response.getResponseBodyAsString())
}
})
// set the page title - this should be unique in the space or page creation will fail
def pageTitle = issue.key + " Independent Design Review"
def params = [
type : "page",
title: pageTitle,
space: [
key: "TES" // set the space key - or calculate it from the project or something
],
body : [
storage: [
value : writer.toString() + confResponse.results.body.storage.value[0],
representation: "storage"
]
]
]
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 {
if (response.statusCode != HttpURLConnection.HTTP_OK) {
throw new Exception(response.getResponseBodyAsString())
} else {
def webUrl = new JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]
}
}
})
No I have not found an answer
I did a workaround to add another transition to call this script to "start" an issue. Only purpose of that transition is to run this script.
So the script operates correctly when called from "Create" step started from web page.
Script does not work when issue "Create" called from the link and clone script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.