Hello all,
I would like to request a macro where on the labels are supposed to get updated automatically depending on the labels present on the Story task.
I want the labels to be updated only if the Story has SEO_EMEA or MA_EMEA as one of its label.
Hello @sai_kiran
Do you have Script Runner plugin installed in your Jira instance ?
Hello @sai_kiran
Here is a script you should add as a Listener of type Custom listener with events of type "Issue Updated":
// Listener to synchronise certains to label of certains
// issues type to it's subtasks
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
def labelMgr = ComponentAccessor.getComponent(LabelManager)
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// List of label to synchronise
def labelsToCopy = ["SEO_EMEA", "MA_EMEA"]
// List of issue type that we apply synchronisation
def issueType = ["Bug", "Story"]
//Filter issue type
if (issueType.any{it == event?.issue.issueType.name})
{
// Get changes of labels
def labelsChange = event?.getChangeLog()?.getRelated("ChildChangeItem")?.findAll {it.field == "labels"}
if (labelsChange)
{
//get issue
def issue = event.issue
// Get previous labels
def previousLabels = Arrays.asList(((String)labelsChange.oldstring[0]).split())
// Get new labels
def newLabels = Arrays.asList(((String)labelsChange.newstring[0]).split())
// Filter previous labels
def previousLabelsToVerify = labelsToCopy.intersect(previousLabels)
// Filter new labels
def newLabelsToVerify = labelsToCopy.intersect(newLabels)
// Compute labels to delete
def labelsToDelete = previousLabelsToVerify - newLabelsToVerify
// Compute labels to add
def labelsToAdd = newLabelsToVerify - previousLabelsToVerify
//get subtasks
def subtasks = issue.subTaskObjects
subtasks.each { subtask ->
// get current label of the subtask
def subtaskLabels = labelMgr.getLabels(subtask.id).collect{it.label}
// Delete labels
subtaskLabels -= labelsToDelete
// Add labels
subtaskLabels += labelsToAdd
// Change labels of subtask
labelMgr.setLabels(currentUser, subtask.id, subtaskLabels.toSet(), false, true)
}
}
}
Just configure the two first array:
If you need all issueType this can be easyly modified (delete first if)
If you need a filter on subtasks issueType create a filter on the subtasks collection.
Regards,
Adrien
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.