Versioner sammenlignet

Nøgle

  • Linjen blev tilføjet.
  • Denne linje blev fjernet.
  • Formatering blev ændret.

...

Kodeblok
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.label.LabelManager
import org.springframework.util.StringUtils
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

labelManager = ComponentManager.getComponentInstanceOfType(LabelManager.class)
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();


CustomField UseCustomer = customFieldManager.getCustomFieldObject(10600);
CustomField Customer = customFieldManager.getCustomFieldObject(10900);


labelManager.removeLabelsForCustomField(10900)


Set labelSet = new HashSet();
labelSet.add(issue.getCustomFieldValue(UseCustomer));


def componentManager = ComponentManager.getInstance()
def authContext = componentManager.getJiraAuthenticationContext()
def user = authContext.getUser()


// issue.getCustomFieldValue(UseCustomer)
// Does not work - the "labelSet" is not a valid set - https://answers.atlassian.com/questions/332748/set-labels-in-jira
labelManager.setLabels(user, issue.id,labelSet, false,false)

 

Transist Linked Issues

This is very nice, for "auto" progressing linked issues. (Idea and source from this)

Kodeblok
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink;

def componentManager = ComponentManager.getInstance()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()

import org.apache.log4j.Category
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "debug statements"

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );


issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
        if (issueLink.issueLinkType.name == "parent-child") {
        // Transist Issue
                workflowTransitionUtil.setIssue(issueLink.getDestinationObject());
                workflowTransitionUtil.setUsername(currentUser);
                workflowTransitionUtil.setAction (741)    // 741 = Waiting
        // validate and transition issue
                workflowTransitionUtil.validate();
                workflowTransitionUtil.progress();
        // Add a comment so people have a clue why the child has been closed
                CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class);
                String comment = "Status changed to *WAit for solution* as a result of the *Resolve* action being applied to the TD Issue.";
                commentManager.create(issueLink.getDestinationObject(), currentUser, comment, true);
       }
}

 

Get CurrentUser

Kodeblok
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
User = ComponentManager.getInstance().getJiraAuthenticationContext().getUser().getName();

...