System Field to be changed

Deleted user October 23, 2017

Hi Team,

Some examples. 

Resolution : No Fix

a.Bug A is Need More Info

b.Bug A is Cannot Reproduce, Bug B Is Won’t Fix, and Bug C is Unaffected

c.Bug A is Won’t Fix, Bug B is Won’t Fix

By doing this the resolution field value should move to "No Fix" Here we developed some script please refer and advise.

Note : Please look into below for your reference. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import java.lang.String

log.setLevel(org.apache.log4j.Level.DEBUG)
import org.apache.log4j.Level
import org.apache.log4j.Logger
Logger.getLogger("com.onresolve").setLevel(Level.DEBUG)

//Define necessary managers/components
def currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def issueManager = ComponentAccessor.issueManager
def issueService = ComponentAccessor.issueService
def linkManager = ComponentAccessor.issueLinkManager
def changeHolder = new DefaultIssueChangeHolder();

//Get MutableIssue of issue in event
//def issue = issueManager.getIssueByCurrentKey(event.issue.key)

def issueInputParameters = issueService.newIssueInputParameters()
// 121 for intest to closed
def actionId = 121 // change this to the step that you want the issue to be transitioned to
// 191 for inprogress
//def inprogress_actionId = 191

def transitionValidationResult
def transitionResult
log.warn("The issue type is: " + issue.getIssueType().name)


//check that issue is a bug
if (issue.getIssueType().name == "Bug") {

//Get outward links and check for link type Blocks
linkManager.getOutwardLinks(issue.id).each{
//log.warn("Link Type: "+it.issueLinkType.name)
if(it.issueLinkType.name == "Blocks")
{
//Check that blocked issue is a Story and has a specific status
def blockedIssue = it.destinationObject

if(blockedIssue.issueType.name == "Story" && blockedIssue.status.name in ["In Test","Scanning","In Progress","In Validation"])
{
log.warn("story Resolution field value: " + blockedIssue.resolution.name)
String res = "Resolution"
log.warn("====story resolution field value === : " + blockedIssue.getFieldByName(res))
//Get the Story's linked bugs
def storyBugs = linkManager.getInwardLinks(blockedIssue.id).findAll{it.sourceObject.issueType.name == "Bug"}
def canTransition_to_closed = true
def canTransition_to_inprogress = false
def canTransition_scanning_to_intest = false

//Check that all bugs are in the status "Closed"
for(link in storyBugs)
{
if(link.issueLinkType.name == "Blocks")
{
def linkedBug = link.sourceObject
//If one of the bugs is not "In Test" then set canTransition to false and break from loop
if(!(linkedBug.status.name in ["Closed"]))
{
canTransition_to_closed = false
break
}

}
}

def canSetStoryField = false
//set story resolution field as Fixed.
for(link in storyBugs)
{
if(link.issueLinkType.name == "Blocks")
{
log.warn("Issue resolution: " + issue.resolution.name)
def linkedBug1 = link.sourceObject
//If one of the bugs is not "In Test" then set canTransition to false and break from loop
if(linkedBug1.issue.resolution.name in ["Need More Info", "Unaffected", "Cannot Reproduce", "Won't Fix"])
{
canSetStoryField = true
break
}

}
}
log.warn("Can Set Story field: " + canSetStoryField)

if(canSetStoryField){
def option = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find {it.toString() == "No Fix"}
//blockedIssue.resolution.updateValue(null, blockedissue, new ModifiedValue(blockedIssue.resolution, option),changeHolder);
//IssueConstant issueResolutionConstant = constantsManager.getIssueConstantByName(ConstantsManager.CONSTANT_TYPE.RESOLUTION.getType(), "No Fix");
}

if(!(canTransition_to_closed)){
// ================
//Check that all bugs are in the status "In Progress"
for(link in storyBugs)
{

if(link.issueLinkType.name == "Blocks")
{
def linkedBug = link.sourceObject
//If one of the bugs is not "In Validation," then set canTransition true and break from loop
if(linkedBug.status.name in ["In Test", "Pending Release", "Hotfix", "Closed", "In Progress"])
{
canTransition_to_inprogress = true 
}
else
{ 
canTransition_to_inprogress = false
break
}

}
}
// =================

//scanning to intest
for(link in storyBugs)
{
if(link.issueLinkType.name == "Blocks")
{
def linkedBug = link.sourceObject
//If one of the bugs is not "In Validation," then set canTransition true and break from loop
if(!(linkedBug.status.name in ["In Progress"]))
{
canTransition_scanning_to_intest = true 
}
else
{ 
canTransition_scanning_to_intest = false
break
}

}
}
// =================


}

//Will transition if ALL bugs were in status "Closed"
if(canTransition_to_closed || canTransition_to_inprogress)
{
if(canTransition_to_closed){
actionId = 121
log.debug("==canTransition_to_closed==")
}
if(canTransition_to_inprogress){
actionId = 191
log.debug("==canTransition_to_inprogress==")
}
if(canTransition_scanning_to_intest){
log.debug("==canTransition_scanning_to_intest==")
actionId = 211
}
//log.warn("Attmepting Transition")
//Validate the issue transition
transitionValidationResult = issueService.validateTransition(currentUser, blockedIssue.id, actionId, issueInputParameters)

if (transitionValidationResult.isValid()) {
//Attempt to transition the issue
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.debug("Transitioned issue $blockedIssue.key through action $actionId") }
else
{
log.debug("Transition result is not valid")
log.debug("ErrorCollection: "+transitionValidationResult.errorCollection)
}
}
else {
log.debug("The transitionValidation is not valid")
log.debug("ErrorCollection: "+transitionValidationResult.errorCollection)
}
}// if statement closed
}
}
}
}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events