Friday, April 9, 2010

Prevent Closing JIRA Issues as Duplicate Unless Linked to the Duplicated Issue

Using the JIRA JSS plugin, Justin de Vesine came up with the following Validator:

from com.atlassian.jira import ComponentManager
from import IssueLinkTypeManager;

authenticationContext = ComponentManager.getInstance().getJiraAuthenticationContext()
ilm = ComponentManager.getInstance().getIssueLinkManager();

iltm = ComponentManager.getComponentInstanceOfType(IssueLinkTypeManager)
dup_link_type = iltm.getIssueLinkType(10010);

user = authenticationContext.getUser()

resolution_ob = issue.getResolutionObject()
if resolution_ob and resolution_ob.getName() == "Duplicate":
    result = False
    description = 'Link this issue to the issue it duplicates before Closing or Resolving as Duplicate.'
    links = ilm.getLinkCollection(issue, user)
    if links.getLinkTypes().contains(dup_link_type):
        result = True