Script to count linked (several) linked issuess, per type

Mihai Mihai September 9, 2019

Hello,

We have a high level issue type called "Capability". That is the 'Parent of', via regular issue links the standard JIRA Epic issue type.

Inside epics, as issues in epics, we have stories and actions issue types. Stories and/or actions might have sub-tasks, or not (called 'Task').

When we transition a Capability to a certain status, we would like to add a comment to it that will write:

Number of Epics with a certain link in a URL field (http:\\test)

Number of stories 

Number of actions

Number of tasks (the tasks have a field called TaskType - select list) . It would be great to count per task type.

Would it be possible to achieve this via a Scriptrunner postfunction?

Any code is appreciated.

 

Thank you!

2 answers

0 votes
Marc Minten _EVS_
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.
September 9, 2019

Hi,

 

Yes, that is easy to do.

I'll give you some examples (counting stories/tasks in Epics and counting subtasks in issues). I guess you can extend this to your requirements ? (your link names, issue type names, ... add tests on custom field, ...)

Count Stories/tasks in Epics (assume you have an Epic in variable epicIssue) :

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()

Integer count = 0
issueLinkManager.getOutwardLinks(epicIssue.getId()).each {epicLink ->
if (epicLink.getIssueLinkType().getName() == "Epic-Story Link") {
Issue epicLinkedIssue = epicLink.getDestinationObject()
String liIssueType = epicLinkedIssue.getIssueType().getName()
if (liIssueType in ["Story", "Task"] {
count ++
}
}
}

 Count subtasks in issue:

Integer count = 0
issue.getSubTaskObjects().each { subIssue ->
String issueType = subIssue.getIssueType().getName()
if (issueType == "Sub-task") {
count ++
}
}
  
0 votes
Andrew
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.
September 9, 2019

Hi @Mihai Mihai ,

My script validator check if story has link to issue type 'test' and project 'PRKEY'.

https://docs.atlassian.com/software/jira/docs/api/7.1.1/com/atlassian/jira/pageobjects/pages/viewissue/link/IssueLink.html

if (issue.issueType?.name == 'Story'){

def hasT = false


def links = issueLinkManager.getOutwardLinks(issue.getId())
if (links.find{ (it.getDestinationObject().issueType?.name == 'TestCase') && (it.getDestinationObject().getProjectObject().getKey() == 'PRKEY') }){
hasT = true


}
if (hasT){
return true
}else{
return false
}
}

B.R.

Suggest an answer

Log in or Sign up to answer