aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pom.xml2
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java25
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BuildState.java2
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/Pullrequest.java2
-rw-r--r--src/test/java/BitbucketBuildRepositoryTest.java84
5 files changed, 106 insertions, 9 deletions
diff --git a/pom.xml b/pom.xml
index 7b9840d..f204feb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
<artifactId>bitbucket-pullrequest-builder</artifactId>
<name>Bitbucket Pullrequest Builder Plugin</name>
- <version>1.4.25-SNAPSHOT</version>
+ <version>1.4.26-SNAPSHOT</version>
<description>This Jenkins plugin builds pull requests from Bitbucket.org and will report the test results.</description>
<packaging>hpi</packaging>
<url>https://wiki.jenkins-ci.org/display/JENKINS/Bitbucket+pullrequest+builder+plugin</url>
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
index 2bf320b..3b0a314 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
@@ -291,17 +291,34 @@ public class BitbucketRepository {
}
private boolean isFilteredBuild(Pullrequest pullRequest) {
+
+ final String pullRequestId = pullRequest.getId();
+ final String pullRequestTitle = pullRequest.getTitle();
+ final String destinationRepoName = pullRequest.getDestination().getRepository().getRepositoryName();
+
+ // pullRequest.getDestination().getCommit() may return null for pull requests with merge conflicts
+ // * see: https://github.com/nishio-dens/bitbucket-pullrequest-builder-plugin/issues/119
+ // * see: https://github.com/nishio-dens/bitbucket-pullrequest-builder-plugin/issues/98
+ final String destinationCommitHash;
+ if (pullRequest.getDestination().getCommit() == null) {
+ logger.log(Level.INFO, "Pull request #{0} ''{1}'' in repo ''{2}'' has a null value for destination commit.",
+ new Object[]{pullRequestId, pullRequestTitle, destinationRepoName});
+ destinationCommitHash = null;
+ } else {
+ destinationCommitHash = pullRequest.getDestination().getCommit().getHash();
+ }
+
BitbucketCause cause = new BitbucketCause(
pullRequest.getSource().getBranch().getName(),
pullRequest.getDestination().getBranch().getName(),
pullRequest.getSource().getRepository().getOwnerName(),
pullRequest.getSource().getRepository().getRepositoryName(),
- pullRequest.getId(),
+ pullRequestId,
pullRequest.getDestination().getRepository().getOwnerName(),
- pullRequest.getDestination().getRepository().getRepositoryName(),
- pullRequest.getTitle(),
+ destinationRepoName,
+ pullRequestTitle,
pullRequest.getSource().getCommit().getHash(),
- pullRequest.getDestination().getCommit().getHash(),
+ destinationCommitHash,
pullRequest.getAuthor().getCombinedUsername()
);
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BuildState.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BuildState.java
index e5c15ef..a3ef1f1 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BuildState.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BuildState.java
@@ -3,7 +3,7 @@ package bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket;
/**
* Valid build states for a pull request
*
- * @see https://confluence.atlassian.com/bitbucket/buildstatus-resource-779295267.html
+ * @see "https://confluence.atlassian.com/bitbucket/buildstatus-resource-779295267.html"
*/
public enum BuildState {
FAILED, INPROGRESS, SUCCESSFUL
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/Pullrequest.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/Pullrequest.java
index 7ccad7d..b69805e 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/Pullrequest.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/Pullrequest.java
@@ -11,7 +11,7 @@ import org.codehaus.jackson.annotate.JsonProperty;
* POJOs representing the pull-requests extracted from the
* JSON response of the Bitbucket API V2.
*
- * @see https://confluence.atlassian.com/bitbucket/pullrequests-resource-423626332.html#pullrequestsResource-GETaspecificpullrequest
+ * @see "https://confluence.atlassian.com/bitbucket/pullrequests-resource-423626332.html#pullrequestsResource-GETaspecificpullrequest"
*/
@JsonIgnoreProperties(ignoreUnknown = true)
diff --git a/src/test/java/BitbucketBuildRepositoryTest.java b/src/test/java/BitbucketBuildRepositoryTest.java
index 6f04608..42694a3 100644
--- a/src/test/java/BitbucketBuildRepositoryTest.java
+++ b/src/test/java/BitbucketBuildRepositoryTest.java
@@ -6,6 +6,7 @@ import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketPullRequ
import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketRepository;
import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket.ApiClient;
+import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket.Pullrequest;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.CredentialsStore;
@@ -18,8 +19,10 @@ import com.google.common.collect.Collections2;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import java.util.logging.Logger;
import org.easymock.*;
import org.junit.Test;
@@ -29,7 +32,6 @@ import org.junit.Assert;
import org.jvnet.hudson.test.JenkinsRule;
import jenkins.model.Jenkins;
-import org.jvnet.hudson.test.WithoutJenkins;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.httpclient.Credentials;
@@ -106,7 +108,7 @@ public class BitbucketBuildRepositoryTest {
@Rule
public JenkinsRule jRule = new JenkinsRule();
-
+
@Test
public void repositorySimpleUserPasswordTest() throws Exception {
BitbucketBuildTrigger trigger = new BitbucketBuildTrigger(
@@ -271,4 +273,82 @@ public class BitbucketBuildRepositoryTest {
assertFalse(buildStatusKey.startsWith("jenkins-"));
assertEquals((new SHA1HasherFunction(SHA1)).apply("jenkins-too-long-ci-key" + "-" + builder.getProjectId()), buildStatusKey);
}
+
+ @Test
+ public void getTargetPullRequestsWithNullDestinationCommit() throws Exception {
+ // arrange
+
+ // setup mock BitbucketBuildTrigger
+ final BitbucketBuildTrigger trigger = EasyMock.createMock(BitbucketBuildTrigger.class);
+ EasyMock.expect(trigger.getCiSkipPhrases()).andReturn("");
+ EasyMock.expect(trigger.getBranchesFilterBySCMIncludes()).andReturn(false);
+ EasyMock.expect(trigger.getBranchesFilter()).andReturn("");
+ EasyMock.replay(trigger);
+
+ // setup mock BitbucketPullRequestsBuilder
+ final BitbucketPullRequestsBuilder builder = EasyMock.createMock(BitbucketPullRequestsBuilder.class);
+ EasyMock.expect(builder.getTrigger()).andReturn(trigger).anyTimes();
+ EasyMock.expect(builder.getProjectId()).andReturn("").anyTimes();
+ EasyMock.replay(builder);
+
+ // setup PRs to return from mock ApiClient
+ final Pullrequest pullRequest = new Pullrequest();
+
+ final Pullrequest.Repository sourceRepo = new Pullrequest.Repository();
+ sourceRepo.setFullName("Owner/Name");
+
+ final Pullrequest.Repository destRepo = new Pullrequest.Repository();
+ destRepo.setFullName("Owner/Name");
+
+ final Pullrequest.Branch sourceBranch = new Pullrequest.Branch();
+ sourceBranch.setName("Name");
+
+ final Pullrequest.Branch destBranch = new Pullrequest.Branch();
+ destBranch.setName("Name");
+
+ final Pullrequest.Commit sourceCommit = new Pullrequest.Commit();
+ sourceCommit.setHash("Hash");
+
+ final Pullrequest.Commit destCommit = null; // the crux of the test
+
+ final Pullrequest.Revision sourceRevision = new Pullrequest.Revision();
+ sourceRevision.setBranch(sourceBranch);
+ sourceRevision.setRepository(sourceRepo);
+ sourceRevision.setCommit(sourceCommit);
+
+ final Pullrequest.Revision destRevision = new Pullrequest.Revision();
+ destRevision.setBranch(destBranch);
+ destRevision.setRepository(destRepo);
+ destRevision.setCommit(destCommit);
+
+ final Pullrequest.Author author = new Pullrequest.Author();
+ author.setDisplayName("DisplayName");
+ author.setUsername("Username");
+
+ pullRequest.setSource(sourceRevision);
+ pullRequest.setDestination(destRevision);
+ pullRequest.setId("Id");
+ pullRequest.setTitle("Title");
+ pullRequest.setState("OPEN");
+ pullRequest.setAutohor(author);
+
+ final List<Pullrequest> pullRequests = new ArrayList<>(Arrays.asList(pullRequest));
+
+ // setup mock ApiClient
+ final ApiClient client = EasyMock.createNiceMock(ApiClient.class);
+ EasyMock.expect(client.getPullRequests()).andReturn(pullRequests);
+ EasyMock.replay(client);
+
+ // setup SUT
+ final BitbucketRepository repo = new BitbucketRepository("", builder);
+
+ // act
+ repo.init(client);
+
+ // assert
+ Collection<Pullrequest> targetPullRequests = repo.getTargetPullRequests();
+
+ assertEquals(pullRequests.size(), targetPullRequests.size());
+ assertEquals(pullRequest, targetPullRequests.iterator().next());
+ }
}