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

Overview

This script allows Comala Workflows users to automatically create a Jira issue once a page was approved in a Confluence workflow.

Example

Your team can collaborate on documents like feature descriptions, get them approved by management, and then get issues created for those features immediately.

Good to Know

  • The integration requires both Comala Workflows and Scriptrunner to be installed on the same Confluence instance. You must also clearly identify the "final" states of your Workflow in the script in order for it to work correctly.
  • This is a Custom Event Listener that listens for an ApprovalApprovedEvent.

Watch the video to find out more.

Requirements

Confluence Confluence (6.6 - 6.15)

    
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() { @Override void handle(Response response) throws ResponseException { if (response.statusCode != 201) { log.error("Creating Jira issue failed: ${response.responseBodyAsString}") } } })
Discovered an issue? Report it here

Suggested for you