You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2019/04/24 10:48:48 UTC
[sling-org-apache-sling-committer-cli] 38/42: SLING-8337 - Create
sub-command to manage the Jira update when promoting a release
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch feature/SLING-8337
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git
commit eeb567eb906f6afdbf11082f02a326a6dd23f524
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Apr 23 16:22:03 2019 +0300
SLING-8337 - Create sub-command to manage the Jira update when promoting a release
Simplify the VersionClient
---
.../apache/sling/cli/impl/jira/VersionClient.java | 62 ++++++++--------------
1 file changed, 23 insertions(+), 39 deletions(-)
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 0c11c3c..39419a9 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
@@ -24,7 +24,6 @@ import java.io.StringWriter;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Optional;
-import java.util.function.Function;
import java.util.function.Predicate;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -119,12 +118,6 @@ public class VersionClient {
return version;
}
- private boolean isFollowingVersion(Release base, Release candidate) {
- return base.getComponent().equals(candidate.getComponent())
- && new org.osgi.framework.Version(base.getVersion())
- .compareTo(new org.osgi.framework.Version(candidate.getVersion())) > 0;
- }
-
public void create(String versionName) throws IOException {
StringWriter w = new StringWriter();
try ( JsonWriter jw = new Gson().newJsonWriter(w) ) {
@@ -161,19 +154,6 @@ public class VersionClient {
private Optional<Version> findVersion(Predicate<Version> matcher, CloseableHttpClient client) throws IOException {
- return doWithJiraVersions(client, reader -> {
- Gson gson = new Gson();
- Type collectionType = TypeToken.getParameterized(List.class, Version.class).getType();
- List<Version> versions = gson.fromJson(reader, collectionType);
- return versions.stream()
- .filter( v -> v.getName().length() > 1) // avoid old '3' release
- .filter(matcher)
- .sorted(VersionClient::compare)
- .findFirst();
- });
- }
-
- protected <T> T doWithJiraVersions(CloseableHttpClient client, Function<InputStreamReader, T> parserCallback) throws IOException {
HttpGet get = newGet("project/SLING/versions");
try (CloseableHttpResponse response = client.execute(get)) {
try (InputStream content = response.getEntity().getContent();
@@ -181,12 +161,25 @@ public class VersionClient {
if (response.getStatusLine().getStatusCode() != 200)
throw new IOException("Status line : " + response.getStatusLine());
- return parserCallback.apply(reader);
+ Gson gson = new Gson();
+ Type collectionType = TypeToken.getParameterized(List.class, Version.class).getType();
+ List<Version> versions = gson.fromJson(reader, collectionType);
+ return versions.stream()
+ .filter( v -> v.getName().length() > 1) // avoid old '3' release
+ .filter(matcher)
+ .sorted(VersionClient::compare)
+ .findFirst();
}
}
}
+
+ private HttpGet newGet(String suffix) {
+ HttpGet get = new HttpGet(jiraUrlPrefix + suffix);
+ get.addHeader("Accept", CONTENT_TYPE_JSON);
+ return get;
+ }
- protected <T> T doWithRelatedIssueCounts(CloseableHttpClient client, Version version, Function<InputStreamReader, T> parserCallback) throws IOException {
+ private void populateRelatedIssuesCount(CloseableHttpClient client, Version version) throws IOException {
HttpGet get = newGet("version/" + version.getId() +"/relatedIssueCounts");
try (CloseableHttpResponse response = client.execute(get)) {
@@ -194,27 +187,18 @@ public class VersionClient {
InputStreamReader reader = new InputStreamReader(content)) {
if (response.getStatusLine().getStatusCode() != 200)
throw new IOException("Status line : " + response.getStatusLine());
- return parserCallback.apply(reader);
+ Gson gson = new Gson();
+ VersionRelatedIssuesCount issuesCount = gson.fromJson(reader, VersionRelatedIssuesCount.class);
+
+ version.setRelatedIssuesCount(issuesCount.getIssuesFixedCount());
}
}
}
-
- private HttpGet newGet(String suffix) {
- HttpGet get = new HttpGet(jiraUrlPrefix + suffix);
- get.addHeader("Accept", CONTENT_TYPE_JSON);
- return get;
- }
-
- private void populateRelatedIssuesCount(CloseableHttpClient client, Version version) throws IOException {
-
- doWithRelatedIssueCounts(client, version, reader -> {
- Gson gson = new Gson();
- VersionRelatedIssuesCount issuesCount = gson.fromJson(reader, VersionRelatedIssuesCount.class);
-
- version.setRelatedIssuesCount(issuesCount.getIssuesFixedCount());
- return null;
- });
+ private boolean isFollowingVersion(Release base, Release candidate) {
+ return base.getComponent().equals(candidate.getComponent())
+ && new org.osgi.framework.Version(base.getVersion())
+ .compareTo(new org.osgi.framework.Version(candidate.getVersion())) > 0;
}
private static int compare(Version v1, Version v2) {