I followed this tutorial to create an event listner, and I now need to perform certain actions if the issue has certain labels and links .
I am able to extract the labels using
Issue issue =issueEvent.getIssue(); Set<Label> labels =issue.getLabels(); for(Label label :labels){ if(label.getLabel().contains("xyz")){ hasDeskLabel=true; break; } }
I have tried extracting links using
List<IssueLink> links =ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
but this gives me the list of internal links, not external web links.
Is there a way to get those ?
Community moderators have prevented the ability to post new answers.
I think you are referring to remote links for an issue. Try the following code:
final UserManager userManager = ComponentAccessor.getComponentOfType(UserManager.class); final IssueManager issueManager = ComponentAccessor.getComponentOfType(IssueManager.class); RemoteIssueLinkListResult linkResult = ComponentAccessor.getComponentOfType(RemoteIssueLinkService.class).getRemoteIssueLinksForIssue(userManager.getUserObject('username'), issueManager.getIssueObject('pkey')); List<RemoteIssueLink> remoteLinks = result.getRemoteIssueLinks();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
()
import com.atlassian.jira.ComponentManager import groovy.xml.MarkupBuilder import com.atlassian.jira.issue.Issue import com.atlassian.jira.ManagerFactory import static org.apache.log4j.Level.DEBUG import org.apache.log4j.Category import org.apache.log4j.Level import org.apache.log4j.Category import com.atlassian.jira.event.issue.AbstractIssueEventListener import org.apache.log4j.Logger import com.atlassian.jira.event.issue.IssueEvent import com.atlassian.jira.issue.MutableIssue import com.opensymphony.workflow.WorkflowContext import com.atlassian.jira.issue.Issue import com.atlassian.jira.ComponentManager import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult import com.atlassian.jira.bc.issue.IssueService.IssueResult import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult import com.atlassian.jira.issue.IssueInputParametersImpl import com.atlassian.jira.issue.IssueInputParameters import com.atlassian.jira.util.ErrorCollection import com.atlassian.jira.issue.index.IssueIndexManager class CloseParentIssue extends AbstractIssueEventListener { Logger log = Logger.getLogger(CloseParentIssue.class) @Override void workflowEvent (IssueEvent event) { log.setLevel(org.apache.log4j.Level.DEBUG) def itsdIssue Issue issue = event.getIssue() def issuestatus = issue.getStatusObject().getName().toUpperCase() def issueType = issue.issueTypeObject.name def linkedIssue if (issuestatus == "CLOSED" && issueType == "New Feature" ) { //change issue type def componentManager = ComponentManager.getInstance() def issueLinkManager = componentManager.getIssueLinkManager() def allLinkedIssueInWardClosed = false def itsdFound = false issueLinkManager.getInwardLinks(issue.id).each {issueLink -> linkedIssue = issueLink.sourceObject String linkedIssueTemp = linkedIssue.key if(linkedIssueTemp.contains("TEST")){ //change it to ITSD itsdFound = true itsdIssue = linkedIssue } log.debug "Inward linked issue: " + linkedIssue.key if(linkedIssueTemp.contains("TEST") == false) { //change it to ITSD if (linkedIssue.getStatusObject().getName().toUpperCase() == "CLOSED" ) { allLinkedIssueInWardClosed = true } else { allLinkedIssueInWardClosed = false } } } def allLinkedIssueOutWardClosed = false issueLinkManager.getOutwardLinks(issue.id).each {issueLink -> linkedIssue = issueLink.destinationObject String linkedIssueTemp = linkedIssue.key log.debug "Outward linked issue: " + linkedIssue.key if(linkedIssueTemp.contains("TEST") == false) { //change it to ITSD if (linkedIssue.getStatusObject().getName().toUpperCase() == "CLOSED" ) { allLinkedIssueOutWardClosed = true } else { allLinkedIssueOutWardClosed = false } } } if(itsdFound) if(allLinkedIssueOutWardClosed && allLinkedIssueInWardClosed){ issuestatus = itsdIssue.getStatusObject().getName().toUpperCase() if (issuestatus == "WAITING FOR SUPPORT" || issuestatus == "WAITING FOR CUSTOMER" || issuestatus == "WAITING FOR TRIAGE"){ int actionid = 0 if (issuestatus == "WAITING FOR SUPPORT") actionid = 801 //change action id else if (issuestatus == "WAITING FOR CUSTOMER") actionid = 761 //change action id else if (issuestatus == "WAITING FOR TRIAGE") actionid = 831 //change action id def user = itsdIssue.getAssignee() IssueService issueService = ComponentManager.getInstance().getIssueService() IssueInputParameters issueInputParameters = issueService.newIssueInputParameters() TransitionValidationResult validationResult = issueService.validateTransition(user, itsdIssue.id, actionid, issueInputParameters) issueService.transition(user, validationResult) log.debug itsdIssue.key + " got resolved" } } } } }
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.
I restart fixed the issue, but now I only get list of internal jira links.
If you can help me with getting external links (e.g. www.google.com) I will mark your answer as accepted
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
attached code shall give you both inward and outward linked issue.
Please remove additional logic.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.