is there any way to get the Automated transitioned trigger details from Issue getChangeHistoryManager?

Manjunatha K R July 26, 2016

Hi,

Simillar to the below script runner sample(i,e Date of First Transition), is it possible to get the automated transitioned trigger(i,e user/source i,e kodbuild made commit 202 or Vivek Abraham started review - trigered the transition information) mainly ::

My issue History tab looks as below::

 Automated transition triggered when Vivek Abraham started review KDGPROJECT-128 in 10 - 12/Jul/16 6:27 PM   
StatusIn Progress [ 3 ]CODE REVIEW IN PROGRESS [ 10300 ]

 

Automated transition triggered when kodbuild made commit 202 in 10 - 13/Jul/16 9:49 PM  
StatusCODE REVIEW COMPLETED [ 10301 ]Done [ 10001 ]

 

package com.onresolve.jira.groovy.test.scriptfields.scriptsimport com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager() changeHistoryManager.getChangeItemsForField(issue, "status").find {     it.toString == "In Progress" }?.getCreated()

Please share your feedback/inputs...

-Manju

1 answer

1 accepted

2 votes
Answer accepted
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2016

Its possible to get those descriptions using the HistoryMetadataManager.

The following example should show you how to get this description for when Stash/Bitbucket transitions the issue to "In Review" when a pull request is created:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.changehistory.ChangeHistory
import com.atlassian.jira.issue.changehistory.metadata.HistoryMetadataManager

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def historyMetadataManager = ComponentAccessor.getComponent(HistoryMetadataManager)
List<ChangeHistory> allChangeHistories = changeHistoryManager.getChangeHistoriesForUser(issue, currentUser)

def relevantChangeHistory = allChangeHistories.find { changeHistory ->
    changeHistory.getChangeItemBeans()*.toString.contains("In Review")
}
def historyMetadata = historyMetadataManager.getHistoryMetadata(relevantChangeHistory, currentUser)
historyMetadata.getHistoryMetadata()?.description

It will show something like: (Automated transition triggered by pull request #348 in Stash)

It should work the same for other type of automated transitions.

Manjunatha K R July 28, 2016

Thanks for your prompt feedback Adam !

It really helping me to identify whether a JIRA issue transition is triggered manually by assignee or automatically from sub-version or crucible app links configured in my workflow.

But When a transition is triggered automatically, it ignores any conditions, validators or permissions configured on the transition - is there any way to handle the conditions/validations before the automatic transition becomes successful based on condition result(PASS or Fail)? 

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 28, 2016

The transition would be controlled by whatever plugin does the auto-transition, so you would need to ask whoever that is (there may be an option to not skip these).

It sounds like when they perform the transition automatically they skip permissions, validators and conditions. Theres not much we can do from ScriptRunner if this is what they are doing.

Manjunatha K R July 28, 2016

This plug in is from Jira, They said at the moment, this is not possible to achieve in JIRA. This is not something we can set in the configuration and we have a feature request raised on this JSW-14579. Thanks again for your response !

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events