Created
January 8, 2014 20:46
-
-
Save jechlin/8324299 to your computer and use it in GitHub Desktop.
Shows only relevant releases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.onresolve.jira.groovy.user | |
import com.atlassian.jira.ComponentManager | |
import com.atlassian.jira.bc.project.component.ProjectComponent | |
import com.atlassian.jira.component.ComponentAccessor | |
def formComponent = getFieldById(fieldChanged) | |
def affectsVersions = getFieldById("versions") | |
def issueContext = getIssueContext() | |
// put your config here: format is | |
// project key -> component -> list of applicable release names | |
def config = [ | |
JRA: [ | |
"Comp1" : ["Version1", "Version2"], | |
"Comp2" : ["Version3"], | |
], | |
PULSE: [ | |
"Some Component": ["1.0", "1.1"], | |
"Other Component": ["2.0"], | |
], | |
] | |
// if it's a list it has more than one value | |
def components = formComponent.getValue() as List | |
if (components.size() > 1) { | |
formComponent.setError("Please select only one component.") | |
} | |
else { | |
formComponent.clearError() | |
} | |
if (! components || components.size() > 1) { | |
affectsVersions.setFieldOptions([:]) | |
return | |
} | |
// get versions for project | |
def versionManager = ComponentAccessor.getVersionManager() | |
def versions = versionManager.getVersions(issueContext.getProjectObject()) | |
log.debug(versions) | |
if (components.size() == 1) { | |
// filter affects versions list | |
def component = components.first() as ProjectComponent | |
// get possible release names | |
def versionNames = config.get(issueContext.projectObject.key)?.get(component.name) | |
// find version IDs by names | |
def applicableVersions = versions.findAll {it.name in versionNames} | |
def options = [:] | |
applicableVersions.each { | |
// optional - hide archived versions - just remove if you don't want it | |
if (it.archived) { | |
return | |
} | |
// optional - hide released versions - uncomment if you do want this | |
// if (it.released) { | |
// return | |
// } | |
options.put(it.id as String, it.name) | |
affectsVersions.setFieldOptions(options) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment