Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def issueManager = ComponentAccessor.getIssueManager();
 
//def currentIssue = Issues.getByKey("TEST2-2") as MutableIssue
def currentIssue = event.issue as MutableIssue
 
def components = currentIssue.getComponents()
//如果存在多个模块,这里只取第一个模块的lead
def componentLeader = components.getAt(0).componentLead

def changeHistories = changeHistoryManager.getChangeHistories(event.issue)
if (changeHistories) {
    //log
    changeHistories.last().getChangeItemBeans().each { it-> {
        log.warn("修改项: ${it.field}")
    } }

    def changeItem = changeHistories.last().getChangeItemBeans().find {
        // 检查Assignee是否修改了
        it.field == 'assignee' && it.fromString != it.toString
    }
    def changeItem2 = changeHistories.last().getChangeItemBeans().find {
        // 检查Assignee是否修改了
        it.field == 'Component' && it.fromString != it.toString
    }

    //如果修改了经办人就不按Component来,以用户修改的为准
    if (changeItem) {

    } else if(changeItem2) {
        //如果修改了模块就按模块Leader来
        currentIssue.setAssignee(componentLeader)
        issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), currentIssue, EventDispatchOption.ISSUE_UPDATED, true);
    }
    //修改其它字段不处理。
    
}
                    
  • No labels