Search in sources :

Example 1 with Version

use of com.atlassian.jira.rest.client.api.domain.Version in project jira-plugin by jenkinsci.

the class JiraReplaceFixVersionByRegExTest method getIssue.

private Issue getIssue(String fixVersion, long id) throws URISyntaxException {
    List<Version> fixVersions = new ArrayList<Version>();
    fixVersions.add(new Version(new URI("self"), 0L, fixVersion, null, false, false, null));
    return new Issue("", new URI(""), PROJECT_KEY + id, id, null, null, null, null, null, null, null, null, null, null, null, null, null, fixVersions, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
}
Also used : Issue(com.atlassian.jira.rest.client.api.domain.Issue) ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion) Version(com.atlassian.jira.rest.client.api.domain.Version) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 2 with Version

use of com.atlassian.jira.rest.client.api.domain.Version in project jira-plugin by jenkinsci.

the class JiraSession method migrateIssuesToFixVersion.

/**
 * Replaces the fix version list of all issues matching the JQL Query with the version specified.
 *
 * @param projectKey The Jira Project key
 * @param version    The replacement version
 * @param query      The JQL Query
 */
public void migrateIssuesToFixVersion(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 versions with JQL:" + query);
    List<Issue> issues = service.getIssuesFromJqlSearch(query, Integer.MAX_VALUE);
    if (issues == null || issues.isEmpty()) {
        return;
    }
    LOGGER.fine("Found issues: " + issues.size());
    issues.stream().forEach(issue -> {
        LOGGER.fine("Migrating issue: " + issue.getKey());
        service.updateIssue(issue.getKey(), Collections.singletonList(newVersion));
    });
}
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)

Example 3 with Version

use of com.atlassian.jira.rest.client.api.domain.Version in project jira-plugin by jenkinsci.

the class JiraVersionParameterDefinition method getVersions.

public List<JiraVersionParameterDefinition.Result> getVersions() throws IOException {
    Job<?, ?> contextJob = Stapler.getCurrentRequest().findAncestorObject(Job.class);
    JiraSite site = JiraSite.get(contextJob);
    if (site == null)
        throw new IllegalStateException("Jira site needs to be configured in the project " + contextJob.getFullDisplayName());
    JiraSession session = site.getSession(contextJob);
    if (session == null)
        throw new IllegalStateException("Remote access for Jira isn't configured in Jenkins");
    return session.getVersions(projectKey).stream().sorted(VersionComparator.INSTANCE).filter(version -> match(version)).map(version -> new Result(version)).collect(Collectors.toList());
}
Also used : DataBoundConstructor(org.kohsuke.stapler.DataBoundConstructor) StaplerRequest(org.kohsuke.stapler.StaplerRequest) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) JiraSite(hudson.plugins.jira.JiraSite) List(java.util.List) ParameterValue(hudson.model.ParameterValue) Version(com.atlassian.jira.rest.client.api.domain.Version) Stapler(org.kohsuke.stapler.Stapler) JiraSession(hudson.plugins.jira.JiraSession) Extension(hudson.Extension) Job(hudson.model.Job) JSONObject(net.sf.json.JSONObject) Pattern(java.util.regex.Pattern) ParameterDefinition(hudson.model.ParameterDefinition) CLICommand(hudson.cli.CLICommand) JiraSession(hudson.plugins.jira.JiraSession) JiraSite(hudson.plugins.jira.JiraSite)

Example 4 with Version

use of com.atlassian.jira.rest.client.api.domain.Version in project opennms by OpenNMS.

the class ListVersionsCommand method doExecute.

@Override
protected void doExecute(JiraRestClient jiraRestClient) throws Exception {
    final String theProjectKey = Strings.isNullOrEmpty(projectKey) ? getConfig().getProjectKey() : projectKey;
    final Iterable<Version> versions = jiraRestClient.getProjectClient().getProject(theProjectKey).get().getVersions();
    if (!versions.iterator().hasNext()) {
        System.out.println("No versions found for project '" + theProjectKey + "'.");
        return;
    }
    System.out.println(String.format(DEFAULT_ROW_FORMAT, "Id", "Name", "Description"));
    for (Version eachVersion : versions) {
        System.out.println(String.format(DEFAULT_ROW_FORMAT, eachVersion.getId(), eachVersion.getName(), eachVersion.getDescription() == null ? "" : removeNewLines(eachVersion.getDescription())));
    }
}
Also used : Version(com.atlassian.jira.rest.client.api.domain.Version)

Example 5 with Version

use of com.atlassian.jira.rest.client.api.domain.Version in project staf by simpleworks-gmbh.

the class TestFloFixVersion method addFixVersions.

public void addFixVersions(final List<FixVersion> fetchedFixedVersion, final String id) {
    if (Convert.isEmpty(fetchedFixedVersion)) {
        throw new IllegalArgumentException("fetchedFixedVersion can't be null or empty string.");
    }
    if (Convert.isEmpty(id)) {
        throw new IllegalArgumentException("id can't be null or empty string.");
    }
    try {
        final Promise<Issue> promise = jira.getIssue(id);
        final Issue issue = promise.claim();
        if (issue == null) {
            throw new RuntimeException("issue can't be null.");
        }
        final IssueInputBuilder issueBuilder = new IssueInputBuilder();
        List<Version> versions = new ArrayList<Version>();
        for (final FixVersion fixVersion : fetchedFixedVersion) {
            if (!versions.add(new Version(new URI(fixVersion.getSelf()), null, fixVersion.getName(), fixVersion.getDescription(), false, false, null))) {
                TestFloFixVersion.logger.error(String.format("can't add version '%s'.", fixVersion.getId()));
            }
        }
        issueBuilder.setFixVersions(versions);
        final IssueInput newIssue = issueBuilder.build();
        if (newIssue == null) {
            throw new IllegalArgumentException("newIssue can't be null or empty string.");
        }
        final Promise<Void> update = jira.updateIssue(id, newIssue);
        update.claim();
    } catch (Exception ex) {
        if (TestFloFixVersion.logger.isDebugEnabled()) {
            TestFloFixVersion.logger.debug(String.format("can't add fix version '%s' for testcase '%s'.", String.join(", ", fetchedFixedVersion.stream().map(v -> v.toString()).collect(Collectors.toList())), id), ex);
        }
    }
}
Also used : IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) SystemException(de.simpleworks.staf.commons.exceptions.SystemException) Issue(com.atlassian.jira.rest.client.api.domain.Issue) URL(java.net.URL) UtilsIO(de.simpleworks.staf.commons.utils.UtilsIO) ArrayList(java.util.ArrayList) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) Response(okhttp3.Response) Call(okhttp3.Call) URI(java.net.URI) FixVersion(de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion) Convert(de.simpleworks.staf.commons.utils.Convert) ResponseBody(okhttp3.ResponseBody) Request(okhttp3.Request) JiraProperties(de.simpleworks.staf.module.jira.util.JiraProperties) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) JsonPath(com.jayway.jsonpath.JsonPath) Collectors(java.util.stream.Collectors) List(java.util.List) Promise(com.atlassian.util.concurrent.Promise) Logger(org.apache.logging.log4j.Logger) OkHttpClient(okhttp3.OkHttpClient) Version(com.atlassian.jira.rest.client.api.domain.Version) JSONArray(net.minidev.json.JSONArray) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) FixVersion(de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion) Issue(com.atlassian.jira.rest.client.api.domain.Issue) ArrayList(java.util.ArrayList) URI(java.net.URI) SystemException(de.simpleworks.staf.commons.exceptions.SystemException) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) FixVersion(de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion) Version(com.atlassian.jira.rest.client.api.domain.Version) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)

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