Search in sources :

Example 1 with ExtendedVersion

use of hudson.plugins.jira.extension.ExtendedVersion in project jira-plugin by jenkinsci.

the class VersionCreatorTest method buildDidNotFailWhenVersionExists.

@Test
public void buildDidNotFailWhenVersionExists() throws IOException, InterruptedException {
    when(build.getEnvironment(listener)).thenReturn(env);
    ExtendedVersion releasedVersion = new ExtendedVersion(null, ANY_ID, JIRA_VER, null, false, true, ANY_DATE, ANY_DATE);
    when(site.getSession(any())).thenReturn(session);
    when(session.getVersions(JIRA_PRJ)).thenReturn(Arrays.asList(releasedVersion));
    versionCreator.perform(project, JIRA_VER_PARAM, JIRA_PRJ_PARAM, build, listener);
    verify(session, times(0)).addVersion(any(), any());
}
Also used : ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion) Test(org.junit.Test)

Example 2 with ExtendedVersion

use of hudson.plugins.jira.extension.ExtendedVersion in project jira-plugin by jenkinsci.

the class JiraSession method getVersionByName.

/**
 * Get a version by its name
 *
 * @param projectKey The key for the project
 * @param name       The version name
 * @return A RemoteVersion, or null if not found
 */
public ExtendedVersion getVersionByName(String projectKey, String name) {
    LOGGER.fine("Fetching versions from project: " + projectKey);
    List<ExtendedVersion> versions = getVersions(projectKey);
    if (versions == null) {
        return null;
    }
    for (ExtendedVersion version : versions) {
        if (version.getName().equals(name)) {
            return version;
        }
    }
    return null;
}
Also used : ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion)

Example 3 with ExtendedVersion

use of hudson.plugins.jira.extension.ExtendedVersion in project jira-plugin by jenkinsci.

the class JiraRestService method getVersions.

public List<ExtendedVersion> getVersions(String projectKey) {
    final URIBuilder builder = new URIBuilder(uri).setPath(String.format("%s/project/%s/versions", baseApiPath, projectKey));
    List<Map<String, Object>> decoded = Collections.emptyList();
    try {
        URI uri = builder.build();
        final Content content = buildGetRequest(uri).execute().returnContent();
        decoded = objectMapper.readValue(content.asString(), new TypeReference<List<Map<String, Object>>>() {
        });
    } catch (Exception e) {
        LOGGER.log(WARNING, "Jira REST client get versions error. cause: " + e.getMessage(), e);
    }
    return decoded.stream().map(decodedVersion -> {
        final DateTime startDate = decodedVersion.containsKey("startDate") ? DATE_TIME_FORMATTER.parseDateTime((String) decodedVersion.get("startDate")) : null;
        final DateTime releaseDate = decodedVersion.containsKey("releaseDate") ? DATE_TIME_FORMATTER.parseDateTime((String) decodedVersion.get("releaseDate")) : null;
        return new ExtendedVersion(URI.create((String) decodedVersion.get("self")), Long.parseLong((String) decodedVersion.get("id")), (String) decodedVersion.get("name"), (String) decodedVersion.get("description"), (Boolean) decodedVersion.get("archived"), (Boolean) decodedVersion.get("released"), startDate, releaseDate);
    }).collect(Collectors.toList());
}
Also used : Priority(com.atlassian.jira.rest.client.api.domain.Priority) StringUtils(org.apache.commons.lang.StringUtils) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) TimeoutException(java.util.concurrent.TimeoutException) Base64(org.apache.commons.codec.binary.Base64) Request(org.apache.http.client.fluent.Request) Content(org.apache.http.client.fluent.Content) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Map(java.util.Map) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) URI(java.net.URI) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SearchResult(com.atlassian.jira.rest.client.api.domain.SearchResult) DateTimeFormat(org.joda.time.format.DateTimeFormat) Status(com.atlassian.jira.rest.client.api.domain.Status) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) ExtendedVersionInput(hudson.plugins.jira.extension.ExtendedVersionInput) URIBuilder(org.apache.http.client.utils.URIBuilder) Jenkins(jenkins.model.Jenkins) WARNING(java.util.logging.Level.WARNING) JiraIssueField(hudson.plugins.jira.model.JiraIssueField) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) List(java.util.List) BasicUser(com.atlassian.jira.rest.client.api.domain.BasicUser) Comment(com.atlassian.jira.rest.client.api.domain.Comment) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FieldInput(com.atlassian.jira.rest.client.api.domain.input.FieldInput) ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion) Issue(com.atlassian.jira.rest.client.api.domain.Issue) INFO(java.util.logging.Level.INFO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComplexIssueInputFieldValue(com.atlassian.jira.rest.client.api.domain.input.ComplexIssueInputFieldValue) StreamSupport(java.util.stream.StreamSupport) Transition(com.atlassian.jira.rest.client.api.domain.Transition) IssueFieldId(com.atlassian.jira.rest.client.api.domain.IssueFieldId) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) ProxyConfiguration(hudson.ProxyConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) TransitionInput(com.atlassian.jira.rest.client.api.domain.input.TransitionInput) ExtendedJiraRestClient(hudson.plugins.jira.extension.ExtendedJiraRestClient) TimeUnit(java.util.concurrent.TimeUnit) User(com.atlassian.jira.rest.client.api.domain.User) Permissions(com.atlassian.jira.rest.client.api.domain.Permissions) Version(com.atlassian.jira.rest.client.api.domain.Version) BasicProject(com.atlassian.jira.rest.client.api.domain.BasicProject) Nullable(edu.umd.cs.findbugs.annotations.Nullable) HttpHost(org.apache.http.HttpHost) Collections(java.util.Collections) Component(com.atlassian.jira.rest.client.api.domain.Component) Content(org.apache.http.client.fluent.Content) ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) HashMap(java.util.HashMap) URI(java.net.URI) TimeoutException(java.util.concurrent.TimeoutException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DateTime(org.joda.time.DateTime) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 4 with ExtendedVersion

use of hudson.plugins.jira.extension.ExtendedVersion in project jira-plugin by jenkinsci.

the class JiraTester method main.

public static void main(String[] args) throws Exception {
    final URI uri = new URL(JiraConfig.getUrl()).toURI();
    final ExtendedJiraRestClient jiraRestClient = new ExtendedAsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(uri, JiraConfig.getUsername(), JiraConfig.getPassword());
    final JiraRestService restService = new JiraRestService(uri, jiraRestClient, JiraConfig.getUsername(), JiraConfig.getPassword(), JiraSite.DEFAULT_TIMEOUT);
    final String projectKey = "TESTPROJECT";
    final String issueId = "TESTPROJECT-425";
    final Integer actionId = 21;
    final Issue issue = restService.getIssue(issueId);
    System.out.println("issue:" + issue);
    final List<Transition> availableActions = restService.getAvailableActions(issueId);
    for (Transition action : availableActions) {
        System.out.println("Action:" + action);
    }
    for (IssueType issueType : restService.getIssueTypes()) {
        System.out.println(" issue type: " + issueType);
    }
    // restService.addVersion("TESTPROJECT", "0.0.2");
    final List<Component> components = restService.getComponents(projectKey);
    for (Component component : components) {
        System.out.println("component: " + component);
    }
    // BasicComponent backendComponent = null;
    // final Iterable<BasicComponent> components1 = Lists.newArrayList(backendComponent);
    // restService.createIssue("TESTPROJECT", "This is a test issue created using Jira jenkins plugin. Please ignore it.", "TESTUSER", components1, "test issue from Jira jenkins plugin");
    final List<Issue> searchResults = restService.getIssuesFromJqlSearch("project = \"TESTPROJECT\"", 3);
    for (Issue searchResult : searchResults) {
        System.out.println("JQL search result: " + searchResult);
    }
    final List<String> projectsKeys = restService.getProjectsKeys();
    for (String projectsKey : projectsKeys) {
        System.out.println("project key: " + projectsKey);
    }
    final List<Status> statuses = restService.getStatuses();
    for (Status status : statuses) {
        System.out.println("status:" + status);
    }
    final User user = restService.getUser("TESTUSER");
    System.out.println("user: " + user);
    final List<ExtendedVersion> versions = restService.getVersions(projectKey);
    for (ExtendedVersion version : versions) {
        System.out.println("version: " + version);
    }
    for (int i = 0; i < 10; i++) {
        callUniq(restService);
    }
    for (int i = 0; i < 10; i++) {
        callDuplicate(restService);
    }
}
Also used : Status(com.atlassian.jira.rest.client.api.domain.Status) Issue(com.atlassian.jira.rest.client.api.domain.Issue) User(com.atlassian.jira.rest.client.api.domain.User) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) ExtendedJiraRestClient(hudson.plugins.jira.extension.ExtendedJiraRestClient) URI(java.net.URI) URL(java.net.URL) ExtendedAsynchronousJiraRestClientFactory(hudson.plugins.jira.JiraSite.ExtendedAsynchronousJiraRestClientFactory) Transition(com.atlassian.jira.rest.client.api.domain.Transition) ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion) JiraRestService(hudson.plugins.jira.JiraRestService) Component(com.atlassian.jira.rest.client.api.domain.Component)

Example 5 with ExtendedVersion

use of hudson.plugins.jira.extension.ExtendedVersion in project jira-plugin by jenkinsci.

the class VersionReleaser method releaseVersion.

/**
 * Release a given version.
 *
 * @param projectKey  The Project Key
 * @param versionName The name of the version
 * @param versionDescription The description of the version
 */
protected void releaseVersion(String projectKey, String versionName, String versionDescription, JiraSession session) {
    if (session == null) {
        LOGGER.warning("Jira session could not be established");
        return;
    }
    List<ExtendedVersion> versions = session.getVersions(projectKey);
    java.util.Optional<ExtendedVersion> matchingVersion = versions.stream().filter(version -> version.getName().equals(versionName)).findFirst();
    if (matchingVersion.isPresent()) {
        ExtendedVersion version = matchingVersion.get();
        ExtendedVersion releaseVersion = new ExtendedVersion(version.getSelf(), version.getId(), version.getName(), !StringUtils.isEmpty(versionDescription) ? versionDescription : version.getDescription(), version.isArchived(), true, version.getStartDate(), new DateTime());
        session.releaseVersion(projectKey, releaseVersion);
    }
}
Also used : ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion) TaskListener(hudson.model.TaskListener) List(java.util.List) StringUtils(org.apache.commons.lang.StringUtils) BuildListener(hudson.model.BuildListener) Result(hudson.model.Result) DateTime(org.joda.time.DateTime) Job(hudson.model.Job) Optional(java.util.Optional) Logger(java.util.logging.Logger) Run(hudson.model.Run) ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion) DateTime(org.joda.time.DateTime)

Aggregations

ExtendedVersion (hudson.plugins.jira.extension.ExtendedVersion)7 Issue (com.atlassian.jira.rest.client.api.domain.Issue)3 URI (java.net.URI)3 List (java.util.List)3 Test (org.junit.Test)3 Component (com.atlassian.jira.rest.client.api.domain.Component)2 IssueType (com.atlassian.jira.rest.client.api.domain.IssueType)2 Status (com.atlassian.jira.rest.client.api.domain.Status)2 Transition (com.atlassian.jira.rest.client.api.domain.Transition)2 User (com.atlassian.jira.rest.client.api.domain.User)2 ExtendedJiraRestClient (hudson.plugins.jira.extension.ExtendedJiraRestClient)2 ArrayList (java.util.ArrayList)2 Logger (java.util.logging.Logger)2 StringUtils (org.apache.commons.lang.StringUtils)2 DateTime (org.joda.time.DateTime)2 RestClientException (com.atlassian.jira.rest.client.api.RestClientException)1 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)1 BasicProject (com.atlassian.jira.rest.client.api.domain.BasicProject)1 BasicUser (com.atlassian.jira.rest.client.api.domain.BasicUser)1 Comment (com.atlassian.jira.rest.client.api.domain.Comment)1