You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2019/07/24 16:30:01 UTC
[sling-org-apache-sling-committer-cli] branch master updated:
SLING-8599 - The CLI tool reports an incorrect number of fixed JIRA issues
when the same issue is linked to multiple versions
This is an automated email from the ASF dual-hosted git repository.
radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git
The following commit(s) were added to refs/heads/master by this push:
new d7809cf SLING-8599 - The CLI tool reports an incorrect number of fixed JIRA issues when the same issue is linked to multiple versions
d7809cf is described below
commit d7809cfe89222231161714dffeb1f0c6f708fc60
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Wed Jul 24 18:29:46 2019 +0200
SLING-8599 - The CLI tool reports an incorrect number of fixed JIRA issues when the same issue is linked to multiple versions
* fixed issues for multiple releases are collected now in a Set and we
report the size of this set instead of summing up the number of fixed
issues for each release
---
.../java/org/apache/sling/cli/impl/jira/Issue.java | 22 +++++++++++++++++-
.../apache/sling/cli/impl/jira/VersionClient.java | 27 ++++++++++++++++++++++
.../cli/impl/release/PrepareVoteEmailCommand.java | 13 +++++++++--
src/main/resources/templates/release.email | 2 +-
.../impl/release/PrepareVoteEmailCommandTest.java | 13 +++++++++--
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/sling/cli/impl/jira/Issue.java b/src/main/java/org/apache/sling/cli/impl/jira/Issue.java
index 425f5e3..1fb3c6c 100644
--- a/src/main/java/org/apache/sling/cli/impl/jira/Issue.java
+++ b/src/main/java/org/apache/sling/cli/impl/jira/Issue.java
@@ -37,7 +37,27 @@ public class Issue {
static class Fields {
private String summary;
}
-
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (obj instanceof Issue) {
+ Issue other = (Issue) obj;
+ return id == other.id;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
@Override
public String toString() {
return getClass().getSimpleName() + "[" + key + " : " + getSummary() + " ]";
diff --git a/src/main/java/org/apache/sling/cli/impl/jira/VersionClient.java b/src/main/java/org/apache/sling/cli/impl/jira/VersionClient.java
index 98778e6..642761b 100644
--- a/src/main/java/org/apache/sling/cli/impl/jira/VersionClient.java
+++ b/src/main/java/org/apache/sling/cli/impl/jira/VersionClient.java
@@ -192,6 +192,33 @@ public class VersionClient {
}
}
+ public List<Issue> findFixedIssues(Release release) throws IOException {
+ try {
+ HttpGet get = newGet("search");
+ URIBuilder builder = new URIBuilder(get.getURI());
+ builder.addParameter("jql", "project = "+ PROJECT_KEY+" AND resolution = Fixed AND fixVersion = \"" + release.getName() + "\"");
+ builder.addParameter("fields", "summary");
+ get.setURI(builder.build());
+
+ try ( CloseableHttpClient client = httpClientFactory.newClient() ) {
+ try (CloseableHttpResponse response = client.execute(get)) {
+ try (InputStream content = response.getEntity().getContent();
+ InputStreamReader reader = new InputStreamReader(content)) {
+
+ if (response.getStatusLine().getStatusCode() != 200) {
+ throw newException(response, reader);
+ }
+
+ Gson gson = new Gson();
+ return gson.fromJson(reader, IssueResponse.class).getIssues();
+ }
+ }
+ }
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
private IOException newException(CloseableHttpResponse response, InputStreamReader reader) {
StringBuilder message = new StringBuilder();
diff --git a/src/main/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommand.java b/src/main/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommand.java
index 6a416c6..17185c1 100644
--- a/src/main/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommand.java
+++ b/src/main/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommand.java
@@ -18,7 +18,9 @@ package org.apache.sling.cli.impl.release;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
import javax.mail.internet.InternetAddress;
@@ -28,6 +30,7 @@ import org.apache.sling.cli.impl.Command;
import org.apache.sling.cli.impl.DateProvider;
import org.apache.sling.cli.impl.InputOption;
import org.apache.sling.cli.impl.UserInput;
+import org.apache.sling.cli.impl.jira.Issue;
import org.apache.sling.cli.impl.jira.Version;
import org.apache.sling.cli.impl.jira.VersionClient;
import org.apache.sling.cli.impl.mail.Mailer;
@@ -117,7 +120,12 @@ public class PrepareVoteEmailCommand implements Command {
.map(Release::getFullName)
.collect(Collectors.joining(", "));
- int fixedIssueCounts = versions.stream().mapToInt(Version::getIssuesFixedCount).sum();
+ Set<Issue> fixedIssues = new HashSet<>();
+ for (Release release : releases) {
+ fixedIssues.addAll(versionClient.findFixedIssues(release));
+ }
+ int fixedIssuesCount = fixedIssues.size();
+ String issueOrIssues = fixedIssuesCount > 1 ? "issues" : "issue";
String releaseOrReleases = versions.size() > 1 ?
"these releases" : "this release";
@@ -133,7 +141,8 @@ public class PrepareVoteEmailCommand implements Command {
.replace("##RELEASE_ID##", String.valueOf(repositoryId))
.replace("##RELEASE_OR_RELEASES##", releaseOrReleases)
.replace("##RELEASE_JIRA_LINKS##", releaseJiraLinks)
- .replace("##FIXED_ISSUES_COUNT##", String.valueOf(fixedIssueCounts))
+ .replace("##FIXED_ISSUES_COUNT##", String.valueOf(fixedIssuesCount))
+ .replace("##ISSUE_OR_ISSUES##", issueOrIssues)
.replace("##USER_NAME##", currentMember.getName());
switch (reusableCLIOptions.executionMode) {
case DRY_RUN:
diff --git a/src/main/resources/templates/release.email b/src/main/resources/templates/release.email
index 235d9fa..2d8f5f8 100644
--- a/src/main/resources/templates/release.email
+++ b/src/main/resources/templates/release.email
@@ -6,7 +6,7 @@ Subject: [VOTE] Release ##RELEASE_NAME##
Hi,
-We solved ##FIXED_ISSUES_COUNT## issue(s) in ##RELEASE_OR_RELEASES##:
+We solved ##FIXED_ISSUES_COUNT## ##ISSUE_OR_ISSUES## in ##RELEASE_OR_RELEASES##:
##RELEASE_JIRA_LINKS##
Staging repository:
diff --git a/src/test/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommandTest.java b/src/test/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommandTest.java
index 728cd98..0daf5ce 100644
--- a/src/test/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommandTest.java
+++ b/src/test/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommandTest.java
@@ -19,10 +19,13 @@
package org.apache.sling.cli.impl.release;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.sling.cli.impl.Command;
import org.apache.sling.cli.impl.DateProvider;
import org.apache.sling.cli.impl.ExecutionMode;
+import org.apache.sling.cli.impl.jira.Issue;
import org.apache.sling.cli.impl.jira.Version;
import org.apache.sling.cli.impl.jira.VersionClient;
import org.apache.sling.cli.impl.mail.Mailer;
@@ -77,7 +80,7 @@ public class PrepareVoteEmailCommandTest {
"\n" +
"Hi,\n" +
"\n" +
- "We solved 42 issue(s) in this release:\n" +
+ "We solved 42 issues in this release:\n" +
"https://issues.apache.org/jira/browse/SLING/fixforversion/1\n" +
"\n" +
"Staging repository:\n" +
@@ -115,7 +118,13 @@ public class PrepareVoteEmailCommandTest {
when(version.getName()).thenReturn("CLI Test 1.0.0");
when(version.getId()).thenReturn(1);
when(version.getIssuesFixedCount()).thenReturn(42);
- when(versionClient.find(Release.fromString("CLI Test 1.0.0").get(0))).thenReturn(version);
+ Release release = Release.fromString("CLI Test 1.0.0").get(0);
+ List<Issue> fixedIssues = new ArrayList<>();
+ for (int i = 0; i < 42; i++) {
+ fixedIssues.add(mock(Issue.class));
+ }
+ when(versionClient.findFixedIssues(release)).thenReturn(fixedIssues);
+ when(versionClient.find(release)).thenReturn(version);
DateProvider dateProvider = mock(DateProvider.class);
when(dateProvider.getCurrentDateForEmailHeader()).thenReturn("Thu, 1 Jan 1970 01:00:00 +0100");