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());
}
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;
}
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());
}
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);
}
}
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);
}
}
Aggregations