Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
titleScript content
collapsetrue
import org.apache.log4j.Logger
import org.apache.log4j.Level

def transitionIssue(issueKey, transitionId){
    def res = post("/rest/api/2/issue/" + issue.key + "/transitions")
    .header("Content-Type", "application/json")
    .body([
        "transition": [
            "id": transitionId
        ]
    ])
    .asString()
}

def log = Logger.getLogger("com.example.script")

log.setLevel(org.apache.log4j.Level.DEBUG)

def issueKey = 'CALC-1'

def result = get('/rest/api/2/issue/' + issue.key)
        .header('Content-Type', 'application/json')
        .asObject(Map)
if (result.status == 200){
    //return result.body.fields.issuelinks[0]
    
    /*
    result.body.fields.issuelinks.each { ilink ->
        if (ilink.name == "Test") {
            ilink.inwardIssue.key
        }
    }
    */
    
    
    def issueLinks = (List<Map<String, Object>>) result.body.fields.issuelinks
    
    def mapping = issueLinks.groupBy { issueLink -> 
        ((Map<String, Map>) issueLink).type.inward
    }.collectEntries { linkName, linkList ->
        [(linkName): linkList.size()]
    }
    
        log.debug mapping['is tested by']
        
    def testsCountCF = "customfield_10027"
    def res = put("/rest/api/2/issue/${issue.key}") 
     .header("Content-Type", "application/json")
     .body([
         fields:[
         (testsCountCF): mapping['is tested by'].toString()
         ]
     ])
     .asString()
 

} else {
    return "Failed to find issue: Status: ${result.status} ${result.body}"
}

...