Last active
June 25, 2020 16:01
-
-
Save matts-mpg/bacc9a6c8da752946e954d46fcad6184 to your computer and use it in GitHub Desktop.
A twist on the prior example, this will create multiple issues- first an Epic and then a Task.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 groovy.json.JsonBuilder | |
import groovy.json.JsonSlurper | |
import static com.atlassian.sal.api.net.Request.MethodType.POST | |
// Define all the issues we want to create as variables | |
String body = new JsonBuilder([fields: [ | |
project : [key: "PROJECT"],"customfield_10002" : "Epic 22",summary : "Epic 22",issuetype : [id: 10000L] | |
]]).toString() | |
Map phases = ["Intake":"", "Assess":"", "Report":""] | |
// This function will iterate over collections to create API request bodies for new issues | |
String reqBodyBuilder(String summ, String desc, Long issType) { | |
String body = new JsonBuilder([ | |
fields: [ | |
project : [key: "PROJECT"], | |
summary : summ, | |
description : desc, | |
issuetype : [id: issType] | |
] | |
]).toString() | |
return body | |
} | |
// This function will actually execute each request | |
def requester(String body) { | |
def appLinkService = ComponentLocator.getComponent(ApplicationLinkService) | |
def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType) | |
def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory() | |
def request = applicationLinkRequestFactory.createRequest(POST, "/rest/api/2/issue") | |
.addHeader("Content-Type", "application/json") | |
.setEntity(body) | |
request.execute() | |
} | |
// First, create the Epic | |
requester(body) | |
// Now create all the Tasks for the phases | |
phases.each { key, value -> | |
String bod = reqBodyBuilder(key, value, 10002L) | |
requester(bod) | |
} | |
// Now create all the Sub-tasks for the actual tasks that need to be completed | |
// TBD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment