Scriptrunner - Get Project Release Change History

Jake Jollimore October 24, 2019

Is it possible to get the change history of a project's releases using Scriptrunner? 

I want to iterate through all of my issues, look at each of the fix versions for each issue, find the fix version that was most recently modified and set each issue's due date equal to the Release date of the most recently modified fix version/release. 

Is this possible?

2 answers

0 votes
Ravi Sagar _Sparxsys_
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.
October 24, 2019

Ok you can find that in the change history. Take a look at this example.

Jake Jollimore October 25, 2019

Unfortunately, that's not what I need either. 

 

Here's my current script:

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.MutableIssue

log.setLevel(org.apache.log4j.Level.DEBUG)

def issue = event.issue as MutableIssue;

//Only do work if the Fix Version field has changed
if (event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Fix Version"}) {
log.info "The Review Type field has changed"
Date latestReleaseDate = null;

//Find the fix version with the latest date and store it in latestReleaseDate
issue.fixVersions.each{fixVersion->
if(fixVersion.releaseDate != null && (latestReleaseDate == null || latestReleaseDate.compareTo(fixVersion.releaseDate) < 0)){
latestReleaseDate = fixVersion.releaseDate
}
}

//If at least one valid release date was found, set the issue's due date to match.
if(latestReleaseDate != null){
IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setDueDate(latestReleaseDate.format("d/MMM/yy"))

ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if (!loggedInUser) {
loggedInUser = UserManager.getUserByName('jira_bot')
}

UpdateValidationResult validationResult = issueService.validateUpdate(loggedInUser, issue.getId(), issueInputParameters)

if (validationResult.isValid()) {
IssueResult result = issueService.update(loggedInUser, validationResult)
} else {
log.info "ERROR: ${validationResult.getFieldValuesHolder()} : ${validationResult.getErrorCollection()}"
}
}
}

This script runs when the Fix Versions field changes for an issue, and sets the issue's Due Date field to the latest Release Date among its fix versions.

What I need to do is check which Fix Version (or Release) was most recently modified by a user. That is to say, I'm not interested in how the Fix Version field values changed for a given issue, I'm concerned with when the actual Releases listed in the Fix Versions field were modified (had their name, release date, start date, etc. changed). Whichever one was modified most recently, I want to set my issue's due date to it's Release Date value. 

I'm beginning to think this isn't possible, though I hope I'm wrong. What I'm looking for is some kind of value like 

fixVersion.modifiedOn
0 votes
Ravi Sagar _Sparxsys_
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.
October 24, 2019

Hi @Jake Jollimore 

I don't have a handy script to give you at this moment but I believe it can be done.

You may want to take a look at this post here to get some pointers.

Ravi

Jake Jollimore October 24, 2019

Thanks for the quick response. I had a look at the post you mentioned, but, unfortunately, it's not what I need. 

I need to check the date/time a version was modified (not it's start or release date values)in order to determine which version is 'most current'. 

Suggest an answer

Log in or Sign up to answer