Comala Workflows
Create Jira Issue When a Page or Blog Post is Approved
You can register Event Listeners to fire on events provided by 3rd party plugins.
In the example below, once the final ApprovalApprovedEvent
happens (not a partial approval), a new Jira issue will be created (on behalf of the current user) in the linked Jira instance.
Have a look at Comala Workflow’s JavaDoc for more information/more events.
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.comalatech.workflow.event.approval.ApprovalApprovedEvent import com.onresolve.scriptrunner.runner.customisers.WithPlugin import groovy.json.JsonBuilder import static com.atlassian.sal.api.net.Request.MethodType.POST @WithPlugin("com.comalatech.workflow") def event = event as ApprovalApprovedEvent if (!event.isPartial()) { def appLinkService = ComponentLocator.getComponent(ApplicationLinkService) def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType) // <1> def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory() def approvalComment = event.approval.comment def body = new JsonBuilder([ fields: [ // <2> 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>() { // <3> @Override void handle(Response response) throws ResponseException { if (response.statusCode != 201) { log.error("Creating Jira issue failed: ${response.responseBodyAsString}") } } }) }
Line 20: Retrieves the primary Jira application link
Line 25: Specify values for the issue's fields here. Further examples of this can be found here.
Line 37: Executes the request
Jira and Confluence need to be properly linked for this to work. If you haven't done so, you can find instructions here.