Search in sources :

Example 6 with Version

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));
    }
}
Also used : Pattern(java.util.regex.Pattern) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion) Version(com.atlassian.jira.rest.client.api.domain.Version) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 7 with Version

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);
    }
}
Also used : Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion) Version(com.atlassian.jira.rest.client.api.domain.Version) ArrayList(java.util.ArrayList)

Aggregations

Version (com.atlassian.jira.rest.client.api.domain.Version)7 Issue (com.atlassian.jira.rest.client.api.domain.Issue)5 ExtendedVersion (hudson.plugins.jira.extension.ExtendedVersion)4 ArrayList (java.util.ArrayList)4 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)3 URI (java.net.URI)2 List (java.util.List)2 Pattern (java.util.regex.Pattern)2 Collectors (java.util.stream.Collectors)2 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)1 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)1 IssueInputBuilder (com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)1 Promise (com.atlassian.util.concurrent.Promise)1 JsonPath (com.jayway.jsonpath.JsonPath)1 SystemException (de.simpleworks.staf.commons.exceptions.SystemException)1 Convert (de.simpleworks.staf.commons.utils.Convert)1 UtilsIO (de.simpleworks.staf.commons.utils.UtilsIO)1 JiraProperties (de.simpleworks.staf.module.jira.util.JiraProperties)1 FixVersion (de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion)1 Extension (hudson.Extension)1