getPullRequests(UriTemplate template)
}
AbstractBitbucketEndpoint endpointConfig = BitbucketEndpointConfiguration.get().findEndpoint(baseURL);
- if (endpointConfig instanceof BitbucketServerEndpoint && ((BitbucketServerEndpoint)endpointConfig).isCallCanMerge()) {
+ if (endpointConfig instanceof BitbucketServerEndpoint) {
+ final BitbucketServerEndpoint endpoint = (BitbucketServerEndpoint) endpointConfig;
+ if (!endpoint.isCallCanMerge() && !endpoint.isCallChanges()) {
+ return pullRequests;
+ }
+
// This is required for Bitbucket Server to update the refs/pull-requests/* references
// See https://community.atlassian.com/t5/Bitbucket-questions/Change-pull-request-refs-after-Commit-instead-of-after-Approval/qaq-p/194702#M6829
for (BitbucketServerPullRequest pullRequest : pullRequests) {
- pullRequest.setCanMerge(getPullRequestCanMergeById(Integer.parseInt(pullRequest.getId())));
+ if (endpoint.isCallCanMerge()) {
+ pullRequest.setCanMerge(getPullRequestCanMergeById(pullRequest.getId()));
+ }
+ if (endpoint.isCallChanges()) {
+ callPullRequestChangesById(pullRequest.getId());
+ }
}
}
@@ -383,7 +394,17 @@ private void setupClosureForPRBranch(BitbucketServerPullRequest pr) {
}
}
- private boolean getPullRequestCanMergeById(@NonNull Integer id) throws IOException {
+ private void callPullRequestChangesById(@NonNull String id) throws IOException {
+ String url = UriTemplate
+ .fromTemplate(API_PULL_REQUEST_CHANGES_PATH)
+ .set("owner", getUserCentricOwner())
+ .set("repo", repositoryName)
+ .set("id", id).set("limit", 1)
+ .expand();
+ getRequest(url);
+ }
+
+ private boolean getPullRequestCanMergeById(@NonNull String id) throws IOException {
String url = UriTemplate
.fromTemplate(API_PULL_REQUEST_MERGE_PATH)
.set("owner", getUserCentricOwner())
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketServerEndpoint/config-detail.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketServerEndpoint/config-detail.jelly
index 33bfb039a..c02283363 100644
--- a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketServerEndpoint/config-detail.jelly
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketServerEndpoint/config-detail.jelly
@@ -10,4 +10,7 @@
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketServerEndpoint/help-callChanges.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketServerEndpoint/help-callChanges.html
new file mode 100644
index 000000000..85610251c
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketServerEndpoint/help-callChanges.html
@@ -0,0 +1,3 @@
+
+ Always call the can changes api on pull requests to ensure the source code references are up to date (since BitBucket Server v7).
+
diff --git a/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketClientMockUtils.java b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketClientMockUtils.java
index a48243e84..e371d3218 100644
--- a/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketClientMockUtils.java
+++ b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketClientMockUtils.java
@@ -200,7 +200,7 @@ private static BitbucketPullRequestValue getPullRequest() {
pr.setDestination(new BitbucketPullRequestValueDestination(repository, branch, commit));
pr.setId("23");
- pr.setAuthor(new BitbucketPullRequestValue.Author("amuniz"));
+ pr.setAuthor(new BitbucketPullRequestValue.Author());
pr.setLinks(new BitbucketPullRequestValue.Links("https://bitbucket.org/amuniz/test-repos/pull-requests/23"));
return pr;
}
diff --git a/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest.java b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest.java
index 9a3c4c31d..9b3213dec 100644
--- a/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest.java
+++ b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest.java
@@ -69,7 +69,8 @@ public void createPayloadOrigin() throws Exception {
assertThat(event.getPullRequest(), notNullValue());
assertThat(event.getPullRequest().getTitle(), is("README.md edited online with Bitbucket"));
- assertThat(event.getPullRequest().getAuthorLogin(), is("stephenc"));
+ assertThat(event.getPullRequest().getAuthorIdentifier(), is("123456:dead-beef"));
+ assertThat(event.getPullRequest().getAuthorLogin(), is("Stephen Connolly"));
assertThat(event.getPullRequest().getLink(),
is("https://bitbucket.org/cloudbeers/temp/pull-requests/1"));
@@ -134,7 +135,8 @@ public void createPayloadFork() throws Exception {
assertThat(event.getPullRequest(), notNullValue());
assertThat(event.getPullRequest().getTitle(), is("Forking for PR"));
- assertThat(event.getPullRequest().getAuthorLogin(), is("stephenc"));
+ assertThat(event.getPullRequest().getAuthorIdentifier(), is("123456:dead-beef"));
+ assertThat(event.getPullRequest().getAuthorLogin(), is("Stephen Connolly"));
assertThat(event.getPullRequest().getLink(),
is("https://bitbucket.org/cloudbeers/temp/pull-requests/3"));
@@ -198,7 +200,8 @@ public void updatePayload_newCommit() throws Exception {
assertThat(event.getPullRequest(), notNullValue());
assertThat(event.getPullRequest().getTitle(), is("Forking for PR"));
- assertThat(event.getPullRequest().getAuthorLogin(), is("stephenc"));
+ assertThat(event.getPullRequest().getAuthorIdentifier(), is("123456:dead-beef"));
+ assertThat(event.getPullRequest().getAuthorLogin(), is("Stephen Connolly"));
assertThat(event.getPullRequest().getLink(),
is("https://bitbucket.org/cloudbeers/temp/pull-requests/3"));
@@ -262,7 +265,8 @@ public void updatePayload_newDestination() throws Exception {
assertThat(event.getPullRequest(), notNullValue());
assertThat(event.getPullRequest().getTitle(), is("Forking for PR"));
- assertThat(event.getPullRequest().getAuthorLogin(), is("stephenc"));
+ assertThat(event.getPullRequest().getAuthorIdentifier(), is("123456:dead-beef"));
+ assertThat(event.getPullRequest().getAuthorLogin(), is("Stephen Connolly"));
assertThat(event.getPullRequest().getLink(),
is("https://bitbucket.org/cloudbeers/temp/pull-requests/3"));
@@ -326,7 +330,8 @@ public void updatePayload_newDestinationCommit() throws Exception {
assertThat(event.getPullRequest(), notNullValue());
assertThat(event.getPullRequest().getTitle(), is("Forking for PR"));
- assertThat(event.getPullRequest().getAuthorLogin(), is("stephenc"));
+ assertThat(event.getPullRequest().getAuthorIdentifier(), is("123456:dead-beef"));
+ assertThat(event.getPullRequest().getAuthorLogin(), is("Stephen Connolly"));
assertThat(event.getPullRequest().getLink(),
is("https://bitbucket.org/cloudbeers/temp/pull-requests/3"));
@@ -390,7 +395,8 @@ public void rejectedPayload() throws Exception {
assertThat(event.getPullRequest(), notNullValue());
assertThat(event.getPullRequest().getTitle(), is("Forking for PR"));
- assertThat(event.getPullRequest().getAuthorLogin(), is("stephenc"));
+ assertThat(event.getPullRequest().getAuthorIdentifier(), is("123456:dead-beef"));
+ assertThat(event.getPullRequest().getAuthorLogin(), is("Stephen Connolly"));
assertThat(event.getPullRequest().getLink(),
is("https://bitbucket.org/cloudbeers/temp/pull-requests/3"));
@@ -455,7 +461,8 @@ public void fulfilledPayload() throws Exception {
assertThat(event.getPullRequest(), notNullValue());
assertThat(event.getPullRequest().getTitle(), is("README.md edited online with Bitbucket"));
- assertThat(event.getPullRequest().getAuthorLogin(), is("stephenc"));
+ assertThat(event.getPullRequest().getAuthorIdentifier(), is("123456:dead-beef"));
+ assertThat(event.getPullRequest().getAuthorLogin(), is("Stephen Connolly"));
assertThat(event.getPullRequest().getLink(),
is("https://bitbucket.org/cloudbeers/temp/pull-requests/2"));
diff --git a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/createPayloadFork.json b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/createPayloadFork.json
index c8a7add41..bf7728ea5 100644
--- a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/createPayloadFork.json
+++ b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/createPayloadFork.json
@@ -106,8 +106,9 @@
"reason": "",
"updated_on": "2017-03-06T11:52:20.120024+00:00",
"author": {
- "username": "stephenc",
- "display_name": "Stephen Connolly",
+ "account_id": "123456:dead-beef",
+ "nickname": "Stephen Connolly",
+ "display_name": "Stephen Q. Connolly",
"type": "user",
"uuid": "{f70f195e-ade1-4961-9f89-547541377b80}",
"links": {
diff --git a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/createPayloadOrigin.json b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/createPayloadOrigin.json
index 16ff31413..7a37ff0eb 100644
--- a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/createPayloadOrigin.json
+++ b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/createPayloadOrigin.json
@@ -35,8 +35,9 @@
}
},
"author": {
- "username": "stephenc",
- "display_name": "Stephen Connolly",
+ "account_id": "123456:dead-beef",
+ "nickname": "Stephen Connolly",
+ "display_name": "Stephen Q. Connolly",
"type": "user",
"uuid": "{f70f195e-ade1-4961-9f89-547541377b80}",
"links": {
diff --git a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/fulfilledPayload.json b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/fulfilledPayload.json
index acedd12f2..a07f921bf 100644
--- a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/fulfilledPayload.json
+++ b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/fulfilledPayload.json
@@ -129,8 +129,9 @@
"reason": "",
"updated_on": "2017-03-06T10:41:59.551194+00:00",
"author": {
- "username": "stephenc",
- "display_name": "Stephen Connolly",
+ "account_id": "123456:dead-beef",
+ "nickname": "Stephen Connolly",
+ "display_name": "Stephen Q. Connolly",
"type": "user",
"uuid": "{f70f195e-ade1-4961-9f89-547541377b80}",
"links": {
diff --git a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/rejectedPayload.json b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/rejectedPayload.json
index b39962ca9..55f07e6ab 100644
--- a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/rejectedPayload.json
+++ b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/rejectedPayload.json
@@ -122,8 +122,9 @@
"reason": "",
"updated_on": "2017-03-06T12:05:11.484201+00:00",
"author": {
- "username": "stephenc",
- "display_name": "Stephen Connolly",
+ "account_id": "123456:dead-beef",
+ "nickname": "Stephen Connolly",
+ "display_name": "Stephen Q. Connolly",
"type": "user",
"uuid": "{f70f195e-ade1-4961-9f89-547541377b80}",
"links": {
diff --git a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newCommit.json b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newCommit.json
index bdc47125c..3cd26cd85 100644
--- a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newCommit.json
+++ b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newCommit.json
@@ -35,8 +35,9 @@
}
},
"author": {
- "username": "stephenc",
- "display_name": "Stephen Connolly",
+ "account_id": "123456:dead-beef",
+ "nickname": "Stephen Connolly",
+ "display_name": "Stephen Q. Connolly",
"type": "user",
"uuid": "{f70f195e-ade1-4961-9f89-547541377b80}",
"links": {
diff --git a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newDestination.json b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newDestination.json
index 35ccaff35..4efe17223 100644
--- a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newDestination.json
+++ b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newDestination.json
@@ -106,8 +106,9 @@
"reason": "",
"updated_on": "2017-03-06T11:59:39.916949+00:00",
"author": {
- "username": "stephenc",
- "display_name": "Stephen Connolly",
+ "account_id": "123456:dead-beef",
+ "nickname": "Stephen Connolly",
+ "display_name": "Stephen Q. Connolly",
"type": "user",
"uuid": "{f70f195e-ade1-4961-9f89-547541377b80}",
"links": {
diff --git a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newDestinationCommit.json b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newDestinationCommit.json
index de4258491..73b8041cd 100644
--- a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newDestinationCommit.json
+++ b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEventTest/updatePayload_newDestinationCommit.json
@@ -106,8 +106,9 @@
"reason": "",
"updated_on": "2017-03-06T12:02:59.640844+00:00",
"author": {
- "username": "stephenc",
- "display_name": "Stephen Connolly",
+ "account_id": "123456:dead-beef",
+ "nickname": "Stephen Connolly",
+ "display_name": "Stephen Q. Connolly",
"type": "user",
"uuid": "{f70f195e-ade1-4961-9f89-547541377b80}",
"links": {