diff options
author | atsushi <atsushi@ageet.com> | 2015-03-30 21:09:17 +0900 |
---|---|---|
committer | atsushi <atsushi@ageet.com> | 2015-03-30 21:35:53 +0900 |
commit | 71d825e6bc644fec1e3782cfae7778c5208354fd (patch) | |
tree | 2b01a4cf7cfc1e76768e765ed84f1a52aa177d9a /src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket | |
parent | 7feceb28cb89a27f35f62f47368cf38b2026eb00 (diff) | |
download | bbprb-71d825e6bc644fec1e3782cfae7778c5208354fd.tar.gz |
Implement approve if build success
Diffstat (limited to 'src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket')
2 files changed, 45 insertions, 0 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketApiClient.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketApiClient.java index b6d3155..71fc861 100644..100755 --- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketApiClient.java +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketApiClient.java @@ -80,6 +80,22 @@ public class BitbucketApiClient { return null; } + public void deletePullRequestApproval(String pullRequestId) { + String path = V2_API_BASE_URL + this.owner + "/" + this.repositoryName + "/pullrequests/" + pullRequestId + "/approve"; + deleteRequest(path); + } + + public BitbucketPullRequestApproval postPullRequestApproval(String pullRequestId) { + String path = V2_API_BASE_URL + this.owner + "/" + this.repositoryName + "/pullrequests/" + pullRequestId + "/approve"; + try { + String response = postRequest(path, new NameValuePair[]{}); + return parseApprovalJson(response); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + private HttpClient getHttpClient() { HttpClient client = new HttpClient(); if (Jenkins.getInstance() != null) { @@ -175,5 +191,14 @@ public class BitbucketApiClient { BitbucketPullRequestComment.class); return parsedResponse; } + + private BitbucketPullRequestApproval parseApprovalJson(String response) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + BitbucketPullRequestApproval parsedResponse; + parsedResponse = mapper.readValue( + response, + BitbucketPullRequestApproval.class); + return parsedResponse; + } } diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketPullRequestApproval.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketPullRequestApproval.java new file mode 100755 index 0000000..a7fe813 --- /dev/null +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketPullRequestApproval.java @@ -0,0 +1,20 @@ +package bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket; + +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.codehaus.jackson.annotate.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class BitbucketPullRequestApproval { + private String role; + private Boolean approved; + + @JsonProperty("role") + public String getRole() { + return role; + } + + @JsonProperty("approved") + public Boolean getApproved() { + return approved; + } +} |