Hi community!
I need your help:
I have the follow code to insert epic information through API and I need to validate the field "description" is is filled or not
How do I make this?
This is the code:
def endpointUrl = "https://xpto/v1/integration/jira/epic/${issue.key}"
def http = new HTTPBuilder(endpointUrl)
def msg_update_epico = ""
http.request(PUT, ContentType.JSON) {
def requestContentType2 = ContentType.JSON
request.addHeader("Authorization: Bearer ${token}", "ContentType: application/json")
def commentManager = ComponentAccessor.getCommentManager()
if (issuescription.getText().isEmpty())
{
body = """
{
"status_id": "${status_cvv_id.toString()}",
"name": "${issuesummary}",
"delivery_date": "${devdate_value}",
"username": "${event_username}",
"useremail": "${event_useremail}",
"epic_description": "${issuedescription}",
"Progresso": "${progress.toString()}"
}"""
}
else
{
body = """
{
"status_id": "${status_cvv_id.toString()}",
"name": "${issuesummary}",
"delivery_date": "${devdate_value}",
"username": "${event_username}",
"useremail": "${event_useremail}",
"epic_description": "${issuedescription.replaceAll("(\r\n)", "")}",
"Progresso": "${progress.toString()}"
}"""
}
log.info("POSTING update epic: ${endpointUrl}")
log.info("${body}")
msg_update_epico = JSON.message
//log.debug("Retorno update épico: ${msg_update_epico}")
log.debug("Retorno update épico: Automação executada com sucesso")
}
Are you sure this is a question about Jira? Because this
https://xpto/v1/integration/jira/epic/${issue.key}
is not a Jira endpoint.
I'm also terribly confused what I'm looking at
I have the follow code to insert epic information through API and I need to validate the field "description" is is filled or not
What is "epic information"? Where are you trying to insert this information? What source object are you getting the "description" data from?
Isn't this what you're doing in :
if (issuescription.getText().isEmpty())
?
Which by the way, is not Jira API either, because the way you get description is via Issue.getDescription() and this return String, and String does not have any "getText()" method - because you already have the text, that's what String is. That is, assuming "issuescription" is issue description, which by nature, is String.
Not to mention the code is incomplete, you're referring to undefined variables. Where are those coming from?
I have absolutely no idea what this code is supposed to do, and I doubt it is used towards Jira because this endpoint does not look like anything Jira related.
It might be some other server/application passing that information elsewhere, but it 100% is not an out of box endpoint.
Edit: Okay maybe I sound a bit harsh and I sort of assume you want to get something out of Jira and send it to some other server. The main point still stands, this is not the complete code, and I doubt it doesn't throw a nullpointer exception given the above typo.
I need to bring jira information to another system by API
Here is the complete code:
import com.atlassian.event.Event
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import org.apache.log4j.Logger
import org.apache.log4j.Level
import java.time.format.DateTimeFormatter
def log = Logger.getLogger("br.com.viavarejo")
log.setLevel(Level.DEBUG)
def Issue issue = event.getIssue()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectsByName("Status CVV")
def status_cvv_id = issue.getCustomFieldValue(cField) ? issue.getCustomFieldValue(cField).getOptionId() : 0
def id_epico = issue.key
def event_username = event.user.getDisplayName()
def event_useremail = event.user.getEmailAddress()
def issuesummary = issue.getSummary()
def name = name
//def issuedescription = underlyingIssue.description
//def issuedescriptionValueInForm = getFieldById("description").value
def issuedescription = issue.getDescription()
def devdate = customFieldManager.getCustomFieldObject("customfield_14503")
String devdate_value = issue.getCustomFieldValue(devdate) ? new Date().parse("yyyy-mm-dd",issue.getCustomFieldValue(devdate).toString()).format("yyyy-mm-dd") : null
//def devdate_cvv = "delivery_date"
def cField_progress = customFieldManager.getCustomFieldObject("customfield_17708")
def progress = issue.getCustomFieldValue(cField_progress)
//def progress = customFieldManager.getCustomFieldObject("customfield_17708")
//String progress_value = issue.getCustomFieldValue(progress)
if(status_cvv_id>0 && issue.issueType.name == "Epic"){
log.info("Status ID CVV: ${status_cvv_id.toString()}")
log.info("issueType: ${issue.issueType.name}")
log.info("issue Key: ${issue.key}")
log.info("username: ${event_username}")
log.info("useremail: ${event_useremail}")
log.info("issuesummary: ${issuesummary}")
log.info("issuedescription: ${issue.description}")
log.info("progress: ${progress}")
//--------------Chamada para Gerar o Token de autenticação-------------------------------------------------------------------
def endpoint_token = "https://xpto.com.br/v1/integration/authentication"
def httptoken = new HTTPBuilder(endpoint_token)
def usercvv = "sxpto@xxxx.onmicrosoft.com"
def senhacvv = "123456"
def token = ""
httptoken.request(POST, ContentType.JSON) {
def requestContentType = ContentType.JSON
body = "{ \"username\": \"${usercvv}\", \"password\": \"${senhacvv}\" }"
response.success = { resp, JSON ->
log.warn("Successful = " + JSON)
token = JSON.accessToken
log.info("Token ${token}")
//--------------Chamada da API de Updade do epico-------------------------------------------------------------------
def endpointUrl = "https://xpto.com.br/v1/integration/jira/epic/${issue.key}"
def http = new HTTPBuilder(endpointUrl)
def msg_update_epico = ""
http.request(PUT, ContentType.JSON) {
def requestContentType2 = ContentType.JSON
request.addHeader("Authorization: Bearer ${token}", "ContentType: application/json")
def commentManager = ComponentAccessor.getCommentManager()
if (issuescription.getText().isEmpty())
// body = "{ \"status_id\": \"${status_cvv_id.toString()}"
{
body = """
{
"status_id": "${status_cvv_id.toString()}",
"name": "${issuesummary}",
"delivery_date": "${devdate_value}",
"username": "${event_username}",
"useremail": "${event_useremail}",
"epic_description": "${issuedescription}",
"Progresso": "${progress.toString()}"
}"""
}
else
{
body = """
{
"status_id": "${status_cvv_id.toString()}",
"name": "${issuesummary}",
"delivery_date": "${devdate_value}",
"username": "${event_username}",
"useremail": "${event_useremail}",
"epic_description": "${issuedescription.replaceAll("(\r\n)", "")}",
"Progresso": "${progress.toString()}"
}"""
}
log.info("POSTING update epic: ${endpointUrl}")
log.info("${body}")
msg_update_epico = JSON.message
//log.debug("Retorno update épico: ${msg_update_epico}")
log.debug("Retorno update épico: Automação executada com sucesso")
}
//---------------------------------------------------------------------------------
}
response.failure = { resp, JSON ->
log.warn("Failed = " + JSON)
}
log.info("POSTING to ${endpoint_token}")
log.info("${body}")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.