I have a post function that extracts the components and finds email addresses to send from a list. However even when converting the found components and emails to string using <string>.join(", ") it inserts brackets in the email.
In Script Console the email contains what I expect:
Test notification referencing : service1, service2; email john.doe@company.com, joti.bath@company.com
However when attached as a post function the same code gives an email containing:
Test notification referencing : [{service1, {service2; email
- with extra brackets and no email addresses
I'm new to groovy so the code could be better. The post function is of the form:
def myField = issue.fields.find { it.key == "components" }
def value = myField.getValue()
String s = value // Have to assign the value to s to make value a String
def toks = s.tokenize(', ')
def componentsFound = []
toks.eachWithIndex{it, i -> if(it.contains("name=")){componentsFound.add(toks[i].replaceAll("name=",""))}}
def components = ['service1':'john.doe@company.com', 'service2':'joti.bath@domino-uk.com']
def owners = []
components.each{ k, v -> if(componentsFound.contains(k)) {owners.add(v)}}
String componentList = componentsFound.join(", ")
String ownerList = owners.join(", ")
String message = "Test notification referencing : "+componentList+"; email "+ownerList
def resp = post("/rest/api/3/issue/${issue.key}/notify")
.header("Content-Type", "application/json")
.body([
subject: 'Component Bug Notification',
textBody: message,
htmlBody: message,
to: [
watchers: true,
users: [[
name: '<email@company.com>'
]]
]
])
.asString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.