Created
October 7, 2013 07:16
-
-
Save francismartens318/6863710 to your computer and use it in GitHub Desktop.
Allow to bulk add / remove fix versions
https://answers.atlassian.com/questions/176774/how-can-i-bulk-update-jira-issues-and-add-a-fix-version
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
import java.util.List; | |
import com.atlassian.jira.ComponentManager; | |
import com.atlassian.jira.project.version.Version; | |
import com.atlassian.jira.project.version.VersionManager; | |
import com.atlassian.jira.issue.MutableIssue; | |
import com.idalko.jira.groovy.FieldValueUtil; | |
import org.apache.log4j.Category; | |
log = Category.getInstance("com.idalko.scripts.manageVersions"); | |
log.debug("Adapt the versions on issue ${issue.getKey()}"); | |
VersionManager vm = ComponentManager.getInstance().getVersionManager(); | |
FieldValueUtil fvuAddFixVersion = new FieldValueUtil("Add fix version"); | |
FieldValueUtil fvuDelFixVersion = new FieldValueUtil("Remove fix version"); | |
/* | |
* Add the selected version to the issue if not yet there. | |
*/ | |
MutableIssue mi = (MutableIssue) issue; | |
Collection<Version> issueFixVersions = mi.getFixVersions(); | |
Boolean updateFixVersions = false; | |
/* | |
* For all versions, if the version is not yet in the list, add it | |
*/ | |
List vList = null; | |
vList = fvuAddFixVersion.getFieldValue(mi); | |
if (vList) { | |
/* | |
* User wants to add a version. | |
*/ | |
String addFixVersionName = vList.get(0); | |
Boolean addNewFixVersion = true; | |
issueFixVersions.each { | |
Version iVersion = (Version) it; | |
if (addFixVersionName == iVersion.getName()) { | |
addNewFixVersion = false; | |
} | |
} | |
if (addNewFixVersion) { | |
log.debug("${addFixVersionName} should be added to ${issueFixVersions}"); | |
Version newFixVersion = vm.getVersion(mi.getProjectObject().getId(), addFixVersionName); | |
if (newFixVersion) { | |
issueFixVersions.add(newFixVersion); | |
updateFixVersions = true; | |
} | |
} | |
} | |
/* | |
* For all versions, if the remove version is in the list, remove it | |
*/ | |
Version delVersion = null; | |
vList = fvuDelFixVersion.getFieldValue(mi); | |
if (vList) { | |
String delFixVersionName = vList.get(0); | |
issueFixVersions.each { | |
Version iVersion = (Version) it; | |
if (delFixVersionName == iVersion.getName()) { | |
delVersion = iVersion; | |
} | |
} | |
if (delVersion) { | |
log.debug("${delFixVersionName} should be removed from ${issueFixVersions}") | |
issueFixVersions.remove (delVersion); | |
updateFixVersions = true; | |
} | |
else { | |
log.debug("'${delFixVersionName}' not found in list ${issueFixVersions}") | |
} | |
} | |
if (updateFixVersions) { | |
log.debug("Resulting fixVersion list = ${issueFixVersions}"); | |
mi.setFixVersions(issueFixVersions); | |
mi.store(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Me too - where can I get the package?