Skip to content

Instantly share code, notes, and snippets.

@cben0ist
Last active August 29, 2015 14:13
Show Gist options
  • Save cben0ist/b343f3e1c41fe30c1acd to your computer and use it in GitHub Desktop.
Save cben0ist/b343f3e1c41fe30c1acd to your computer and use it in GitHub Desktop.
Get the next version and replace the version name in the summary (post create successor and link)
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.UpdateIssueRequest;
if (issue.getFixVersions().size() > 0) {
def componentManager = ComponentManager.getInstance()
versionManager = componentManager.getVersionManager()
projectManager = componentManager.getProjectManager()
issueManager = componentManager.getIssueManager()
def versions = versionManager.getVersions(projectManager.getProjectObjByKey(issue.getProjectObject().getKey())).findAll {it.releaseDate && ! it.released}
def gotit = 0
def nextVersion = ""
def nextVersionId = ""
if (versions.size() > 0) {
versions.each {
if (gotit == 1){
nextVersion = it.name
nextVersionId = it
gotit = 0
}
if (it.name == issue.getFixVersions()[0].getName()) {
gotit = 1
}
}
}
if (nextVersion != ""){
def newsummary = sourceIssue.getSummary().replace(issue.getFixVersions()[0].getName(), nextVersion)
issue.summary = newsummary
issue.fixVersions = Collections.singleton(nextVersionId)
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Sprint'}
issue.setCustomFieldValue(cf, null)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment