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/08/26 16:34:52 UTC
[sling-org-apache-sling-committer-cli] 01/02: SLING-8661 - Moving
Jira issues to next version fails with 405 status code
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git
commit 4bc0019292b6f091ac44811191ae40ee913ceed4
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Mon Aug 26 18:20:20 2019 +0200
SLING-8661 - Moving Jira issues to next version fails with 405 status code
Fixed multiple issues:
- use an HTTP context with authentication enabled
- use PUT instead of POST
- actually send the request body
---
.../apache/sling/cli/impl/jira/VersionClient.java | 26 ++++++++++++++--------
1 file changed, 17 insertions(+), 9 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 642761b..b62599e 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
@@ -30,6 +30,7 @@ import java.util.function.Predicate;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -164,6 +165,13 @@ public class VersionClient {
return post;
}
+ private HttpPut newPut(String suffix) {
+ HttpPut put = new HttpPut(jiraUrlPrefix + suffix);
+ put.addHeader("Content-Type", CONTENT_TYPE_JSON);
+ put.addHeader("Accept", CONTENT_TYPE_JSON);
+ return put;
+ }
+
public List<Issue> findUnresolvedIssues(Release release) throws IOException {
try {
@@ -332,17 +340,18 @@ public class VersionClient {
IssueUpdate update = new IssueUpdate();
update.recordAdd("fixVersions", newVersion.getName());
update.recordRemove("fixVersions", oldVersion.getName());
+ Gson gson = new Gson();
+ gson.toJson(update, w);
- HttpPost post = newPost("issue/" + issue.getKey());
- post.setEntity(new StringEntity(w.toString(), StandardCharsets.UTF_8));
+ HttpPut put = newPut("issue/" + issue.getKey());
+ put.setEntity(new StringEntity(w.toString(), StandardCharsets.UTF_8));
try (CloseableHttpClient client = httpClientFactory.newClient()) {
- try (CloseableHttpResponse response = client.execute(post)) {
- try (InputStream content = response.getEntity().getContent();
- InputStreamReader reader = new InputStreamReader(content)) {
-
- if (response.getStatusLine().getStatusCode() != 204) {
- throw newException(response, reader);
+ try (CloseableHttpResponse response = client.execute(put, httpClientFactory.newPreemptiveAuthenticationContext())) {
+ if (response.getStatusLine().getStatusCode() != 204) {
+ try (InputStream content = response.getEntity().getContent();
+ InputStreamReader reader = new InputStreamReader(content)) {
+ throw newException(response, reader);
}
}
}
@@ -350,6 +359,5 @@ public class VersionClient {
} catch (IOException e) {
throw new RuntimeException(e);
}
- // '{"update":{"fixVersions":[{"add":{"name":"6.5 L19"}},{"remove":{"name":"6.5 L17"}}]}}'
}
}