aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java
diff options
context:
space:
mode:
authorMaxim Epishchev <epishev@garant.ru>2016-01-26 19:06:59 +0300
committerMaxim Epishchev <epishev@garant.ru>2016-01-26 19:06:59 +0300
commit96ab7a75f14d9990f3c8f1255f9790c496a64473 (patch)
tree439700ff0d73f9040723e7a5db43eb533c1237cd /src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java
parent91a85604177f7df2eb204c9e82564142dbe328f8 (diff)
downloadbbprb-96ab7a75f14d9990f3c8f1255f9790c496a64473.tar.gz
Bugfixes issue for continuously rebuilding PR
If available TTP (aka "test this please") comment Jenkins PR builder continuously rebuilding PR. Now Jenkins post specific build comment. If you want to rebuild already rebuilded PR, post new TTP comment.
Diffstat (limited to 'src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java')
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java
index 18ca86f..e635f65 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java
@@ -16,6 +16,9 @@ import java.util.logging.Logger;
import jenkins.model.Jenkins;
import hudson.ProxyConfiguration;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.commons.httpclient.util.EncodingUtil;
/**
* Created by nishio
@@ -56,15 +59,27 @@ public class ApiClient {
}
return Collections.EMPTY_LIST;
}
+
+ public String getName() {
+ return this.name;
+ }
+
+ private String computeAPIKey(String keyExPart) {
+ return String.format(COMPUTED_KEY_FORMAT, this.key, keyExPart);
+ }
+
+ public String buildStatusKey(String bsKey) {
+ return this.computeAPIKey(bsKey);
+ }
public boolean hasBuildStatus(String owner, String repositoryName, String revision, String keyEx) {
- String url = v2(owner, repositoryName, "/commit/" + revision + "/statuses/build/" + String.format(COMPUTED_KEY_FORMAT, this.key, keyEx));
+ String url = v2(owner, repositoryName, "/commit/" + revision + "/statuses/build/" + this.computeAPIKey(keyEx));
return get(url).contains("\"state\"");
}
public void setBuildStatus(String owner, String repositoryName, String revision, BuildState state, String buildUrl, String comment, String keyEx) {
String url = v2(owner, repositoryName, "/commit/" + revision + "/statuses/build");
- String computedKey = String.format(COMPUTED_KEY_FORMAT, this.key, keyEx);
+ String computedKey = this.computeAPIKey(keyEx);
NameValuePair[] data = new NameValuePair[]{
new NameValuePair("description", comment),
new NameValuePair("key", computedKey),
@@ -81,8 +96,15 @@ public class ApiClient {
delete(v2("/pullrequests/" + pullRequestId + "/approve"));
}
- public void deleteComment(String pullRequestId, String commentId) {
- delete(v1("/pullrequests/" + pullRequestId + "/comments/" + commentId + "/"));
+ public void deletePullRequestComment(String pullRequestId, String commentId) {
+ delete(v1("/pullrequests/" + pullRequestId + "/comments/" + commentId));
+ }
+
+ public void updatePullRequestComment(String pullRequestId, String content, String commentId) {
+ NameValuePair[] data = new NameValuePair[] {
+ new NameValuePair("content", content),
+ };
+ put(v1("/pullrequests/" + pullRequestId + "/comments/" + commentId), data);
}
public Pullrequest.Participant postPullRequestApproval(String pullRequestId) {
@@ -94,6 +116,19 @@ public class ApiClient {
}
return null;
}
+
+ public Pullrequest.Comment postPullRequestComment(String pullRequestId, String content) {
+ NameValuePair[] data = new NameValuePair[] {
+ new NameValuePair("content", content),
+ };
+ try {
+ return parse(post(v1("/pullrequests/" + pullRequestId + "/comments"), data), new TypeReference<Pullrequest.Comment>() {});
+ } catch(Exception e) {
+ logger.log(Level.WARNING, "Invalid pull request comment response.", e);
+ e.printStackTrace();
+ }
+ return null;
+ }
private HttpClient getHttpClient() {
HttpClient client = new HttpClient();
@@ -142,6 +177,13 @@ public class ApiClient {
private void delete(String path) {
send(new DeleteMethod(path));
}
+
+ private void put(String path, NameValuePair[] data) {
+ PutMethod req = new PutMethod(path);
+ req.setRequestBody(EncodingUtil.formUrlEncode(data, "utf-8"));
+ req.getParams().setContentCharset("utf-8");
+ send(req);
+ }
private String send(HttpMethodBase req) {
HttpClient client = getHttpClient();