Skip to main content
Example scripts
arrow icon
To homepage
Confluence
Data centre icon
Data Center

Create a Jira issue when a page or blog post is approved - Comala Document Management integration

Features
Listeners
Created 1 year ago, Updated 1 month(s) ago
App in script
ScriptRunner For Confluence
ScriptRunner For Confluence
by Adaptavist
Compatibility
compatibility bullet
Confluence (6.6 - 6.15)
compatibility bullet
ScriptRunner For Confluence (5.6.14)
Language |
groovy
import com.atlassian.applinks.api.ApplicationLinkService
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 com.atlassian.sal.api.net.ResponseHandler
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import groovy.json.JsonBuilder
import com.comalatech.workflow.event.ContentApproveEvent
import static com.atlassian.sal.api.net.Request.MethodType.POST

@WithPlugin('com.comalatech.workflow')

def appLinkService = ComponentLocator.getComponent(ApplicationLinkService)
def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType)
def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory()

def event = event as ContentApproveEvent
def approvalComment = event.approval.comment
def body = new JsonBuilder([
    fields: [
        project    : [key: 'PROJECT_KEY'],
        summary    : 'Confluence Page Created',
        description: "A page has been created and approved by administrators with comment ${approvalComment}.",
        issuetype  : [name: 'Story']
    ]
]).toString()

def request = applicationLinkRequestFactory.createRequest(POST, '/rest/api/2/issue')
    .addHeader('Content-Type', 'application/json')
    .setEntity(body)

request.execute(new ResponseHandler<Response>() {
    @Override
    void handle(Response response) throws ResponseException {
        if (response.statusCode != 201) {
            log.error("Creating Jira issue failed: ${response.responseBodyAsString}")
        }
    }
})
Having an issue with this script?
Report it here