Created
April 4, 2012 21:02
-
-
Save stevez/2305629 to your computer and use it in GitHub Desktop.
groovy_request_jira_issue
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 groovy.json.JsonSlurper | |
/* | |
def urlRoot = "https://example.com" | |
def issueId = "" | |
def userName = "" | |
def password = "" | |
def addr = "${urlRoot}/rest/api/2/issue/${issueId}" | |
def authString = "${userName}:${password}".getBytes().encodeBase64().toString() | |
*/ | |
def urlRoot = "https://jira.atlassian.com" | |
def issueId = "JIRA-9" | |
def userName = "" | |
def password = "" | |
def addr = "${urlRoot}/rest/api/2/issue/${issueId}" | |
def authString = "" | |
def conn = addr.toURL().openConnection() | |
if(authString.length() > 0) | |
{ | |
conn.setRequestProperty( "Authorization", "Basic ${authString}" ) | |
} | |
if( conn.responseCode == 200 ) { | |
def result = parseJSON(conn.content.text) | |
println "json id:${result.id}" | |
println "json key:${result.key}" | |
} else { | |
println "Something bad happened." | |
println "${conn.responseCode}: ${conn.responseMessage}" | |
} | |
def parseJSON(text) | |
{ | |
def slurper = new JsonSlurper() | |
def result = slurper.parseText(text) | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment