#67 - Set release tickets to in progress.

This commit is contained in:
Mark Paluch
2018-02-06 11:38:15 +01:00
parent d9a99b618f
commit 08d98d58e1
5 changed files with 154 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 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.
@@ -111,6 +111,14 @@ public interface IssueTracker extends Plugin<Project> {
*/
Ticket assignReleaseTicketToMe(ModuleIteration module);
/**
* Start progress on release tickets.
*
* @param module
* @return
*/
Ticket startReleaseTicketProgress(ModuleIteration module);
/**
* Returns the {@link Changelog} for the given {@link ModuleIteration}.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 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.
@@ -68,6 +68,34 @@ class IssueTrackerCommands extends TimedCommand {
Tickets.toTicketsCollector()).toString();
}
/**
* Prepare this release by self-assigning release tickets and setting them to in-progress.
*
* @param iteration
* @return
*/
@CliCommand(value = "tracker prepare")
public String trackerPrepare(@CliOption(key = "", mandatory = true) TrainIteration iteration) {
jiraSelfAssignReleaseTickets(iteration);
return jiraStartProgress(iteration);
}
/**
* Prepare a new, upcoming release by creating release versions and release tickets.
*
* @param iteration
* @return
*/
@CliCommand(value = "tracker setup-next")
public String trackerSetupNext(@CliOption(key = "", mandatory = true) TrainIteration iteration) {
jiraCreateReleaseVersions(iteration);
return createReleaseTickets(iteration);
}
@CliCommand(value = "tracker self-assign releasetickets")
public String jiraSelfAssignReleaseTickets(@CliOption(key = "", mandatory = true) TrainIteration iteration) {
@@ -75,6 +103,12 @@ class IssueTrackerCommands extends TimedCommand {
Tickets.toTicketsCollector()).toString();
}
public String jiraStartProgress(@CliOption(key = "", mandatory = true) TrainIteration iteration) {
return runAndReturn(iteration, module -> getTrackerFor(module).startReleaseTicketProgress(module),
Tickets.toTicketsCollector()).toString();
}
@CliCommand(value = "tracker create releaseversions")
public void jiraCreateReleaseVersions(@CliOption(key = "", mandatory = true) TrainIteration iteration) {
iteration.forEach(this::createReleaseVersion);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 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.
@@ -299,6 +299,15 @@ class GitHub implements IssueTracker {
return toTicket(response);
}
/*
* (non-Javadoc)
* @see org.springframework.data.release.jira.IssueTracker#startReleaseTicketProgress(org.springframework.data.release.model.ModuleIteration)
*/
@Override
public Ticket startReleaseTicketProgress(ModuleIteration module) {
return getReleaseTicketFor(module);
}
private String stripHash(Ticket ticket) {
return ticket.getId().startsWith("#") ? ticket.getId().substring(1) : ticket.getId();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 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.
@@ -35,6 +35,7 @@ import org.springframework.data.release.issues.Tickets;
import org.springframework.data.release.issues.jira.JiraIssue.Fields;
import org.springframework.data.release.issues.jira.JiraIssue.Resolution;
import org.springframework.data.release.issues.jira.JiraIssue.Status;
import org.springframework.data.release.issues.jira.JiraIssue.StatusCategory;
import org.springframework.data.release.model.ModuleIteration;
import org.springframework.data.release.model.Project;
import org.springframework.data.release.model.ProjectKey;
@@ -49,6 +50,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestOperations;
import org.springframework.web.util.UriTemplate;
@@ -62,13 +65,16 @@ class Jira implements JiraConnector {
private static final String BASE_URI = "{jiraBaseUrl}/rest/api/2";
private static final String CREATE_ISSUES_TEMPLATE = BASE_URI + "/issue";
private static final String ISSUE_TEMPLATE = BASE_URI + "/issue/{ticketId}";
private static final String TRANSITION_TEMPLATE = BASE_URI + "/issue/{ticketId}/transitions";
private static final String PROJECT_VERSIONS_TEMPLATE = BASE_URI + "/project/{project}/version?startAt={startAt}";
private static final String PROJECT_COMPONENTS_TEMPLATE = BASE_URI + "/project/{project}/components";
private static final String VERSIONS_TEMPLATE = BASE_URI + "/version";
private static final String VERSION_TEMPLATE = BASE_URI + "/version/{id}";
private static final String SEARCH_TEMPLATE = BASE_URI + "/search?jql={jql}&fields={fields}&startAt={startAt}";
public static final String INFRASTRUCTURE_COMPONENT_NAME = "Infrastructure";
private static final String INFRASTRUCTURE_COMPONENT_NAME = "Infrastructure";
private static final String IN_PROGRESS_STATUS_CATEGORY = "indeterminate";
private static final int IN_PROGRESS_TRANSITION = 4;
private final RestOperations operations;
private final Logger logger;
@@ -230,8 +236,12 @@ class Jira implements JiraConnector {
JiraReleaseVersion jiraReleaseVersion = JiraReleaseVersion.of(moduleIteration, jiraVersion);
operations.exchange(VERSIONS_TEMPLATE, HttpMethod.POST, new HttpEntity<Object>(jiraReleaseVersion, httpHeaders),
JiraReleaseVersion.class, parameters).getBody();
try {
operations.exchange(VERSIONS_TEMPLATE, HttpMethod.POST, new HttpEntity<Object>(jiraReleaseVersion, httpHeaders),
JiraReleaseVersion.class, parameters).getBody();
} catch (HttpStatusCodeException e) {
System.out.println(e.getResponseBodyAsString());
}
}
/*
@@ -359,6 +369,57 @@ class Jira implements JiraConnector {
return ticket;
}
/*
* (non-Javadoc)
* @see org.springframework.data.release.jira.IssueTracker#startReleaseTicketProgress(org.springframework.data.release.model.ModuleIteration)
*/
@Override
public Ticket startReleaseTicketProgress(ModuleIteration module) {
Ticket ticket = getReleaseTicketFor(module);
startProgress(ticket);
return ticket;
}
private void startProgress(Ticket ticket) {
Assert.notNull(ticket, "Ticket must not be null.");
HttpHeaders httpHeaders = newUserScopedHttpHeaders();
Map<String, Object> parameters = newUrlTemplateVariables();
parameters.put("ticketId", ticket.getId());
JiraIssue currentIssue = getJiraIssue(ticket.getId())
.orElseThrow(() -> new IllegalStateException(String.format("Ticket %s does not exist", ticket.getId())));
if (isInProgress(currentIssue.getFields())) {
return;
}
JiraIssueUpdate editMeta = JiraIssueUpdate.create().transition(IN_PROGRESS_TRANSITION);
logger.log("Ticket", "Start progress of %s", ticket);
try {
operations.exchange(TRANSITION_TEMPLATE, HttpMethod.POST, new HttpEntity<Object>(editMeta, httpHeaders),
String.class, parameters).getBody();
} catch (HttpClientErrorException e) {
logger.warn("Ticket", "Start progress of %s failed with status ", ticket, e.getStatusCode());
}
}
private static boolean isInProgress(Fields fields) {
if (fields.getStatus() == null) {
return false;
}
StatusCategory statusCategory = fields.getStatus().getStatusCategory();
return statusCategory != null && statusCategory.getKey().equals(IN_PROGRESS_STATUS_CATEGORY);
}
/*
* (non-Javadoc)
* @see org.springframework.data.release.jira.JiraConnector#verifyBeforeRelease(org.springframework.data.release.model.Train, org.springframework.data.release.model.Iteration)

View File

@@ -1,6 +1,23 @@
/*
* Copyright 2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.release.issues.jira;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import java.io.IOException;
@@ -21,13 +38,11 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
* @author Mark Paluch
*/
@Value
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class JiraIssueUpdate {
private final Map<String, Object> update;
private JiraIssueUpdate(Map<String, Object> update) {
this.update = update;
}
private final Map<String, Object> transition;
/**
* Create an empty {@link JiraIssueUpdate}.
@@ -35,7 +50,7 @@ class JiraIssueUpdate {
* @return
*/
public static JiraIssueUpdate create() {
return new JiraIssueUpdate(Collections.emptyMap());
return new JiraIssueUpdate(Collections.emptyMap(), Collections.emptyMap());
}
/**
@@ -51,7 +66,21 @@ class JiraIssueUpdate {
Map<String, Object> update = new LinkedHashMap<>(this.update);
update.put("assignee", new AssignTo(userId));
return new JiraIssueUpdate(update);
return new JiraIssueUpdate(update, this.transition);
}
/**
* Assign the issue to {@code userId}.
*
* @param transitionId Jira transition Id
* @return
*/
public JiraIssueUpdate transition(int transitionId) {
Map<String, Object> transition = new LinkedHashMap<>(this.transition);
transition.put("id", transitionId);
return new JiraIssueUpdate(this.update, transition);
}
/**