aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
diff options
context:
space:
mode:
authorBlayne Chard <blacha@aviarc.com>2014-05-13 16:37:58 +1200
committerBlayne Chard <blacha@aviarc.com>2014-05-14 17:10:56 +1200
commitbe3e57315173936cd23c135b6c9eb86e73d1700e (patch)
tree6a306ae1904a80d0a7d33b845d57d2b42b28b833 /src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
parent68bf998f6ebf61dcd5b2d9aad765369aeabf714f (diff)
downloadbbprb-be3e57315173936cd23c135b6c9eb86e73d1700e.tar.gz
adding bitbucket pull request hash into BuildStart and BuildFinish messages, so when a pull request is updated a new build will be made.
Diffstat (limited to 'src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java')
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
index 4889dcf..362a65a 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
@@ -4,9 +4,7 @@ import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket.Bitbuck
import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket.BitbucketPullRequestComment;
import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket.BitbucketPullRequestResponseValue;
import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket.BitbucketPullRequestResponseValueRepository;
-import jenkins.model.Jenkins;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -18,9 +16,12 @@ import java.util.logging.Logger;
*/
public class BitbucketRepository {
private static final Logger logger = Logger.getLogger(BitbucketRepository.class.getName());
- public static final String BUILD_START_MARKER = "[BuildStart]";
- public static final String BUILD_FINISH_MARKER = "[BuildFinished]";
+ public static final String BUILD_START_MARKER = "[Build:%s Start]";
+ public static final String BUILD_FINISH_MARKER = "[Build:%s Finished]";
public static final String BUILD_REQUEST_MARKER = "test this please";
+
+ public static final String BUILD_SUCCESS_COMMENT = " Test PASSED.\n\t";
+ public static final String BUILD_FAILURE_COMMENT = " Test FAILED.\n\t";
private String projectPath;
private BitbucketPullRequestsBuilder builder;
private BitbucketBuildTrigger trigger;
@@ -54,7 +55,8 @@ public class BitbucketRepository {
public void postBuildStartCommentTo(Collection<BitbucketPullRequestResponseValue> pullRequests) {
for(BitbucketPullRequestResponseValue pullRequest : pullRequests) {
- String comment = BUILD_START_MARKER;
+ String commit = pullRequest.getSource().getCommit().getHash();
+ String comment = String.format(BUILD_START_MARKER, commit);
comment += " Build Triggered. Waiting to hear about " + pullRequest.getSource().getRepository().getFullName();
this.client.postPullRequestComment(pullRequest.getId(), comment);
}
@@ -70,17 +72,19 @@ public class BitbucketRepository {
pullRequest.getId(),
pullRequest.getDestination().getRepository().getOwnerName(),
pullRequest.getDestination().getRepository().getRepositoryName(),
- pullRequest.getTitle());
+ pullRequest.getTitle(),
+ pullRequest.getSource().getCommit().getHash());
this.builder.getTrigger().startJob(cause);
}
}
- public void postFinishedComment(String pullRequestId, boolean success, String buildUrl) {
- String comment = BUILD_FINISH_MARKER;
+ public void postFinishedComment(String pullRequestId, String commit, boolean success, String buildUrl) {
+
+ String comment = String.format(BUILD_FINISH_MARKER, commit);
if (success) {
- comment += " Test PASSed. Refer to this link for build results.";
+ comment += BUILD_SUCCESS_COMMENT;
} else {
- comment += " Test FAILed. Refer to this link for build results.";
+ comment += BUILD_FAILURE_COMMENT;
}
comment += buildUrl;
this.client.postPullRequestComment(pullRequestId, comment);
@@ -92,11 +96,15 @@ public class BitbucketRepository {
if (isSkipBuild(pullRequest.getTitle())) {
return false;
}
+
+ String commit = pullRequest.getSource().getCommit().getHash();
BitbucketPullRequestResponseValueRepository destination = pullRequest.getDestination();
String owner = destination.getRepository().getOwnerName();
String repositoryName = destination.getRepository().getRepositoryName();
String id = pullRequest.getId();
List<BitbucketPullRequestComment> comments = client.getPullRequestComments(owner, repositoryName, id);
+ String searchString = String.format(BUILD_START_MARKER, commit).toLowerCase();
+
if (comments != null) {
Collections.sort(comments);
Collections.reverse(comments);
@@ -106,7 +114,7 @@ public class BitbucketRepository {
continue;
}
content = content.toLowerCase();
- if (content.contains(BUILD_START_MARKER.toLowerCase())) {
+ if (content.contains(searchString)) {
shouldBuild = false;
break;
}