use of com.atlassian.jira.rest.client.api.domain.Version in project jira-plugin by jenkinsci.
the class JiraSession method replaceFixVersion.
/**
* Replaces the given fromVersion with toVersion in all issues matching the JQL query.
*
* @param projectKey The Jira Project
* @param fromVersion The name of the version to replace
* @param toVersion The name of the replacement version
* @param query The JQL Query
*/
public void replaceFixVersion(String projectKey, String fromVersion, String toVersion, String query) throws TimeoutException {
Version newVersion = getVersionByName(projectKey, toVersion);
if (newVersion == null) {
LOGGER.warning("Version " + toVersion + " was not found");
return;
}
LOGGER.fine("Fetching versions with JQL:" + query);
List<Issue> issues = service.getIssuesFromJqlSearch(query, Integer.MAX_VALUE);
if (issues == null) {
return;
}
LOGGER.fine("Found issues: " + issues.size());
for (Issue issue : issues) {
Set<Version> newVersions = new HashSet<>();
newVersions.add(newVersion);
if (StringUtils.startsWith(fromVersion, "/") && StringUtils.endsWith(fromVersion, "/")) {
String regEx = StringUtils.removeStart(fromVersion, "/");
regEx = StringUtils.removeEnd(regEx, "/");
LOGGER.fine("Using regular expression: " + regEx);
Pattern fromVersionPattern = Pattern.compile(regEx);
for (Version currentVersion : issue.getFixVersions()) {
Matcher versionToRemove = fromVersionPattern.matcher(currentVersion.getName());
if (!versionToRemove.matches()) {
newVersions.add(currentVersion);
}
}
} else {
for (Version currentVersion : issue.getFixVersions()) {
if (!currentVersion.getName().equals(fromVersion)) {
newVersions.add(currentVersion);
}
}
}
LOGGER.fine("Replacing version in issue: " + issue.getKey());
service.updateIssue(issue.getKey(), new ArrayList(newVersions));
}
}
use of com.atlassian.jira.rest.client.api.domain.Version in project jira-plugin by jenkinsci.
the class JiraSession method addFixVersion.
/**
* Adds the specified version to the fix version list of all issues matching the JQL.
*
* @param projectKey The Jira Project
* @param version The version to add
* @param query The JQL Query
*/
public void addFixVersion(String projectKey, String version, String query) throws TimeoutException {
Version newVersion = getVersionByName(projectKey, version);
if (newVersion == null) {
LOGGER.warning("Version " + version + " was not found");
return;
}
LOGGER.fine("Fetching issues with JQL:" + query);
List<Issue> issues = service.getIssuesFromJqlSearch(query, Integer.MAX_VALUE);
if (issues == null || issues.isEmpty()) {
return;
}
LOGGER.fine("Found issues: " + issues.size());
for (Issue issue : issues) {
LOGGER.fine("Adding version: " + newVersion.getName() + " to issue: " + issue.getKey());
List<Version> fixVersions = new ArrayList<>();
issue.getFixVersions().forEach(fixVersions::add);
fixVersions.add(newVersion);
service.updateIssue(issue.getKey(), fixVersions);
}
}
Aggregations