Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Validator Script

Mani Reddy October 20, 2018

Hi,

Behavior of the below script,

Epic will only be allowed to close if "issues in Epic" are in "completed" state, works without any errors.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager

// Allow logging for debug and tracking purposes
import org.apache.log4j.Level
import org.apache.log4j.Logger

// Script code for easy log identification
String scriptCode = "Check all stories closed -"

// Setup the log and leave a message to show what we're doing
Logger logger = log
logger.setLevel( Level.ERROR )
logger.debug( "$scriptCode Triggered by $issue.key" )

if (issue.issueType.name == 'Epic')
{
IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager
def foundLinks = issueLinkManager.getOutwardLinks(issue.id)
log.debug(foundLinks.size())
log.info(foundLinks.size())

for (i in foundLinks)
{
def issuelink = i.getIssueLinkType()
if (issuelink.getName() == "Epic-Story Link")
{
def status = i.destinationObject.getStatus().getName()
log.debug(status)
if (i.destinationObject.getStatus().getName() != "Completed")
{
log.debug("Found an open/status issue link")
return false;



}
log.debug("found an epic story link")
}

}

return true;

}

How do I include more status (To Do, Open) apart from completed? I tried "||" and  "if" statement no luck.

How to Validate each epic has at least one story and task in "issues in epic" ?

 

Any help would be appreciated.

-M

2 answers

1 accepted

2 votes
Answer accepted
Ivan Tovbin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 21, 2018 edited

For more statuses I'd do something like this:

def statusList = Arrays.asList("Status1", "Status2", "Status3")

if(statusList.contains(i.destinationObject.getStatus().getName())){
.....
}

Multiple issue types can be handled in the same manner. 

Mani Reddy November 14, 2018

@Ivan Tovbin Thank you for your input.  I am now able to add more status to my script  using,

def statusList = Arrays.asList("Completed", "Resolved")

if(!statusList.contains(i.destinationObject.getStatus().getName()))

{
log.debug("Found an open/status issue link")
return false;

 

However, I would like to add a validator , Every epic should have a Story and a Task under issues epic in order to close the epic.

I tried using below, which doesn't seem to work.

 if (foundLinks.size() == 0)

{
return false;

Mani Reddy November 14, 2018

@Ivan Tovbin Never mind , the if block works. I forgot to publish the workflow.

Thank you for help.

-M

Ivan Tovbin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 15, 2018

@Mani Reddy Glad I could help. Please mark this answer as "Accepted" if it resolved your issue.

Cheers.

0 votes
Tom Lister
Community Champion
October 21, 2018

How about a variation on

String mask = “Completed To Do Open”

mask.contains(i.destinationObject.getStatus().getName())

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events