Skip to content

Instantly share code, notes, and snippets.

@jamieechlin
Created March 19, 2013 11:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamieechlin/5195423 to your computer and use it in GitHub Desktop.
Save jamieechlin/5195423 to your computer and use it in GitHub Desktop.
def restParams = [
className: "com.onresolve.jira.groovy.canned.admin.CopyProject",
args: [
FIELD_SOURCE_PROJECT: SCRUM_TEMPLATE_PKEY,
FIELD_TARGET_PROJECT: projectKey,
FIELD_TARGET_PROJECT_NAME: projectName,
FIELD_COPY_VERSIONS: true,
FIELD_COPY_COMPONENTS: true,
FIELD_COPY_ISSUES: true,
FIELD_COPY_GREENHOPPER: true,
FIELD_COPY_DASH_AND_FILTERS: true,
] as JSON,
]
def http = new HTTPBuilder(baseUrl)
http.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException {
httpRequest.addHeader('Authorization', 'Basic ' + "${getAdmUserName()}:${getAdmPassword()}".toString().bytes.encodeBase64().toString())
}
})
// todo: assumption of context /jira
http.request(Method.POST, ContentType.TEXT) {req ->
uri.path = "/jira/rest/builtinscripts/latest/execute"
body = encodeMapAsUrl(restParams)
headers.Accept = 'application/json'
response.success = {resp, reader ->
log.debug("Succeeded")
log.debug(resp.statusLine)
}
response.failure = {resp, reader ->
log.debug("failed")
def text = reader.text
def errorCollection = new JsonSlurper().parseText(text as String) as Map
log.debug "errors:" + errorCollection.get("errors")
throw new Exception(errorCollection.get("errors").toString())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment