#56 - Add support to archive (retire) release versions.

Added support for Jira. There's no such concept for GitHub.
This commit is contained in:
Mark Paluch
2017-06-07 15:06:47 +02:00
parent 6eb97ca7a5
commit 469e06e4b9
6 changed files with 94 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ import org.springframework.plugin.core.Plugin;
/**
* Interface for issue tracker operations.
*
*
* @author Oliver Gierke
* @author Mark Paluch
*/
@@ -56,7 +56,7 @@ public interface IssueTracker extends Plugin<Project> {
/**
* Returns the {@link Ticket} that tracks modifications in the context of a release.
*
*
* @param module the module to lookup the {@link Ticket} for, must not be {@literal null}.
* @return
*/
@@ -74,16 +74,23 @@ public interface IssueTracker extends Plugin<Project> {
/**
* Creates a release version if release version is missing.
*
*
* @param module must not be {@literal null}.
*/
void createReleaseVersion(ModuleIteration module);
/**
* Retire the release version from the active versions for a {@link ModuleIteration}.
*
* @param module must not be {@literal null}.
*/
void archiveReleaseVersion(ModuleIteration module);
/**
* Create release ticket if release ticket is missing.
* <p>
* TODO: Return created ticket
*
*
* @param module must not be {@literal null}.
*/
void createReleaseTicket(ModuleIteration module);
@@ -98,7 +105,7 @@ public interface IssueTracker extends Plugin<Project> {
/**
* Assigns the release ticket for the given {@link ModuleIteration} to the current user.
*
*
* @param module must not be {@literal null}.
* @return
*/
@@ -106,7 +113,7 @@ public interface IssueTracker extends Plugin<Project> {
/**
* Returns the {@link Changelog} for the given {@link ModuleIteration}.
*
*
* @param module must not be {@literal null}.
* @return
*/
@@ -114,7 +121,7 @@ public interface IssueTracker extends Plugin<Project> {
/**
* Closes the given {@link ModuleIteration}.
*
*
* @param module must not be {@literal null}.
*/
void closeIteration(ModuleIteration module);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -110,6 +110,11 @@ class IssueTrackerCommands extends TimedCommand {
iteration.forEach(module -> getTrackerFor(module).closeIteration(module));
}
@CliCommand("tracker archive")
public void archiveIteration(@CliOption(key = "", mandatory = true) TrainIteration iteration) {
iteration.forEach(module -> getTrackerFor(module).archiveReleaseVersion(module));
}
private Changelog getChangelog(ModuleIteration module) {
return getTrackerFor(module).getChangelogFor(module);
}

View File

@@ -222,6 +222,15 @@ class GitHub implements IssueTracker {
new HttpEntity<Object>(githubMilestone.toMilestone(), httpHeaders), GitHubIssue.Milestone.class, parameters);
}
/*
* (non-Javadoc)
* @see org.springframework.data.release.tracker.IssueTracker#retireReleaseVersion(org.springframework.data.release.model.ModuleIteration)
*/
@Override
public void archiveReleaseVersion(ModuleIteration module) {
logger.log(module, "Skipping milestone archival");
}
/*
*
* (non-Javadoc)

View File

@@ -209,7 +209,7 @@ class Jira implements JiraConnector {
/*
* (non-Javadoc)
* @see org.springframework.data.release.jira.JiraConnector#createReleaseVersion(org.springframework.data.release.model.ModuleIteration, org.springframework.data.release.jira.Credentials)
* @see org.springframework.data.release.jira.JiraConnector#createReleaseVersion(org.springframework.data.release.model.ModuleIteration)
*/
@Override
public void createReleaseVersion(ModuleIteration moduleIteration) {
@@ -236,8 +236,34 @@ class Jira implements JiraConnector {
/*
* (non-Javadoc)
* @see org.springframework.data.release.jira.JiraConnector#findJiraReleaseVersion(org.springframework.data.release.model.ModuleIteration)
* @see org.springframework.data.release.jira.JiraConnector#retireReleaseVersion(org.springframework.data.release.model.ModuleIteration)
*/
@Override
public void archiveReleaseVersion(ModuleIteration module) {
Assert.notNull(module, "ModuleIteration must not be null.");
HttpHeaders httpHeaders = newUserScopedHttpHeaders();
findJiraReleaseVersion(module) //
.filter(JiraReleaseVersion::isActive) //
.map(JiraReleaseVersion::markArchived) //
.ifPresent(version -> {
logger.log(module, "Marking version %s as archived.", version);
Map<String, Object> parameters = newUrlTemplateVariables();
parameters.put("id", version.getId());
operations.exchange(VERSION_TEMPLATE, HttpMethod.PUT, new HttpEntity<Object>(version, httpHeaders), Map.class,
parameters);
});
}
/*
* (non-Javadoc)
* @see org.springframework.data.release.jira.JiraConnector#findJiraReleaseVersion(org.springframework.data.release.model.ModuleIteration)
*/
@Cacheable("release-version")
public Optional<JiraReleaseVersion> findJiraReleaseVersion(ModuleIteration moduleIteration) {

View File

@@ -16,15 +16,16 @@
package org.springframework.data.release.issues.jira;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Value;
import org.springframework.data.release.model.ModuleIteration;
import org.springframework.util.Assert;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Value object to bind REST responses to.
*
*
* @author Mark Paluch
*/
@Value
@@ -32,6 +33,7 @@ class JiraReleaseVersion {
String id, name, project, description;
boolean released;
boolean archived;
public static JiraReleaseVersion of(ModuleIteration moduleIteration, JiraVersion jiraVersion) {
@@ -39,11 +41,15 @@ class JiraReleaseVersion {
Assert.notNull(jiraVersion, "JiraVersion must not be null.");
return new JiraReleaseVersion(null, jiraVersion.toString(), moduleIteration.getProjectKey().getKey(),
jiraVersion.getDescription(), false);
jiraVersion.getDescription(), false, false);
}
public JiraReleaseVersion markReleased() {
return new JiraReleaseVersion(id, name, project, description, true);
return new JiraReleaseVersion(id, name, project, description, true, false);
}
public JiraReleaseVersion markArchived() {
return new JiraReleaseVersion(id, name, project, description, released, true);
}
public boolean hasSameNameAs(JiraVersion jiraVersion) {
@@ -54,4 +60,9 @@ class JiraReleaseVersion {
public boolean isOpen() {
return !released;
}
@JsonIgnore
public boolean isActive() {
return !archived;
}
}

View File

@@ -56,6 +56,7 @@ public class JiraConnectorIntegrationTests extends AbstractIntegrationTests {
static final String CREATE_ISSUE_URI = "/rest/api/2/issue";
static final String CREATE_VERSION_URI = "/rest/api/2/version";
static final String UPDATE_VERSION_URI = "/rest/api/2/version/15475";
static final String SEARCH_URI = "/rest/api/2/search";
static final String PROJECT_VERSION_URI = "/rest/api/2/project/%s/version";
static final String PROJECT_COMPONENTS_URI = "/rest/api/2/project/%s/components";
@@ -167,7 +168,7 @@ public class JiraConnectorIntegrationTests extends AbstractIntegrationTests {
jira.createReleaseVersion(REST_HOPPER_RC1);
verify(postRequestedFor(urlPathMatching(CREATE_VERSION_URI)).withRequestBody(equalToJson(
"{\"name\":\"2.5 RC1 (Hopper)\",\"project\":\"DATAREST\",\"description\":\"Hopper RC1\", \"released\":false}")));
"{\"name\":\"2.5 RC1 (Hopper)\",\"project\":\"DATAREST\",\"description\":\"Hopper RC1\", \"released\":false, \"archived\":false}")));
}
/**
@@ -185,6 +186,25 @@ public class JiraConnectorIntegrationTests extends AbstractIntegrationTests {
verify(0, postRequestedFor(urlPathMatching(CREATE_VERSION_URI)));
}
/**
* @see #56
*/
@Test
public void archiveReleaseVersionShouldArchiveReleaseVersion() throws Exception {
ModuleIteration moduleIteration = ReleaseTrains.HOPPER.getModuleIteration(Iteration.RC1, "REST");
mockGetProjectVersionsWith("releaseVersions.json", moduleIteration.getProjectKey());
mockService.stubFor(put(urlPathMatching(UPDATE_VERSION_URI)).//
willReturn(json("versionCreated.json")));
jira.archiveReleaseVersion(moduleIteration);
verify(putRequestedFor(urlPathMatching(UPDATE_VERSION_URI))
.withRequestBody(equalToJson("{\"id\":\"15475\",\"name\":\"2.5 RC1 (Hopper)\","
+ "\"description\":\"Hopper RC1\", \"released\":true,\"archived\":true}")));
}
/**
* @see #5
*/