aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Damovsky <martin.damovsky@gmail.com>2017-02-23 18:17:08 +0100
committerGitHub <noreply@github.com>2017-02-23 18:17:08 +0100
commit4d049eda8513cdf1c12285d1785d73498ab63d66 (patch)
treeb8b33f76cf674bd0875fd32745934d2054c42ee0 /src
parent67e38c42109c9ed95462d1dd47404c6c102d3854 (diff)
parent4c5edc0144af81056f96eceadb864ac93809b22f (diff)
downloadbbprb-4d049eda8513cdf1c12285d1785d73498ab63d66.tar.gz
Merge pull request #45 from nblair/parameterize-comment-build-trigger
Parameterize comment phrase to trigger a build
Diffstat (limited to 'src')
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java11
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java12
-rw-r--r--src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly3
-rw-r--r--src/test/java/BitbucketBuildFilterTest.java6
-rw-r--r--src/test/java/BitbucketBuildRepositoryTest.java8
5 files changed, 31 insertions, 9 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java
index 40bc215..6b03e44 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java
@@ -51,6 +51,7 @@ public class BitbucketBuildTrigger extends Trigger<Job<?, ?>> {
private final boolean checkDestinationCommit;
private final boolean approveIfSuccess;
private final boolean cancelOutdatedJobs;
+ private final String commentTrigger;
transient private BitbucketPullRequestsBuilder bitbucketPullRequestsBuilder;
@@ -73,7 +74,8 @@ public class BitbucketBuildTrigger extends Trigger<Job<?, ?>> {
String ciSkipPhrases,
boolean checkDestinationCommit,
boolean approveIfSuccess,
- boolean cancelOutdatedJobs
+ boolean cancelOutdatedJobs,
+ String commentTrigger
) throws ANTLRException {
super(cron);
this.projectPath = projectPath;
@@ -91,6 +93,7 @@ public class BitbucketBuildTrigger extends Trigger<Job<?, ?>> {
this.checkDestinationCommit = checkDestinationCommit;
this.approveIfSuccess = approveIfSuccess;
this.cancelOutdatedJobs = cancelOutdatedJobs;
+ this.commentTrigger = commentTrigger;
}
public String getProjectPath() {
@@ -152,6 +155,12 @@ public class BitbucketBuildTrigger extends Trigger<Job<?, ?>> {
public boolean getCancelOutdatedJobs() {
return cancelOutdatedJobs;
}
+ /**
+ * @return a phrase that when entered in a comment will trigger a new build
+ */
+ public String getCommentTrigger() {
+ return commentTrigger;
+ }
@Override
public void start(Job<?, ?> project, boolean newInstance) {
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
index 570a852..02d11c5 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
@@ -35,10 +35,13 @@ import static com.cloudbees.plugins.credentials.CredentialsMatchers.instanceOf;
public class BitbucketRepository {
private static final Logger logger = Logger.getLogger(BitbucketRepository.class.getName());
private static final String BUILD_DESCRIPTION = "%s: %s into %s";
- private static final String BUILD_REQUEST_MARKER = "test this please";
private static final String BUILD_REQUEST_DONE_MARKER = "ttp build flag";
private static final String BUILD_REQUEST_MARKER_TAG_SINGLE_RX = "\\#[\\w\\-\\d]+";
private static final String BUILD_REQUEST_MARKER_TAGS_RX = "\\[bid\\:\\s?(.*)\\]";
+ /**
+ * Default value for comment trigger.
+ */
+ public static final String DEFAULT_COMMENT_TRIGGER = "test this please";
private String projectPath;
private BitbucketPullRequestsBuilder builder;
@@ -192,7 +195,12 @@ public class BitbucketRepository {
}
private boolean isTTPComment(String content) {
- return content.toLowerCase().contains(BUILD_REQUEST_MARKER.toLowerCase());
+ // special case: in unit tests, trigger is null and can't be mocked
+ String commentTrigger = DEFAULT_COMMENT_TRIGGER;
+ if(trigger != null && StringUtils.isNotBlank(trigger.getCommentTrigger())) {
+ commentTrigger = trigger.getCommentTrigger();
+ }
+ return content.toLowerCase().contains(commentTrigger);
}
private boolean isTTPCommentBuildTags(String content) {
diff --git a/src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly b/src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly
index f79c601..1d7c4e4 100644
--- a/src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly
+++ b/src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly
@@ -42,4 +42,7 @@
<f:entry title="Cancel outdated jobs?" field="cancelOutdatedJobs">
<f:checkbox default="false"/>
</f:entry>
+ <f:entry title="Comment phrase to trigger build" field="commentTrigger">
+ <f:textbox default="test this please"/>
+ </f:entry>
</j:jelly>
diff --git a/src/test/java/BitbucketBuildFilterTest.java b/src/test/java/BitbucketBuildFilterTest.java
index 21b4a01..ad9892c 100644
--- a/src/test/java/BitbucketBuildFilterTest.java
+++ b/src/test/java/BitbucketBuildFilterTest.java
@@ -1,5 +1,7 @@
+import antlr.ANTLRException;
import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketBuildFilter;
+import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketBuildTrigger;
import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketCause;
import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketPullRequestsBuilder;
import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketRepository;
@@ -194,8 +196,8 @@ public class BitbucketBuildFilterTest {
@Test
@WithoutJenkins
- public void filterPRComments() {
- BitbucketPullRequestsBuilder builder = EasyMock.createMock(BitbucketPullRequestsBuilder.class);
+ public void filterPRComments() throws ANTLRException {
+ BitbucketPullRequestsBuilder builder = EasyMock.createMock(BitbucketPullRequestsBuilder.class);
EasyMock.expect(builder.getTrigger()).andReturn(null).anyTimes();
EasyMock.replay(builder);
diff --git a/src/test/java/BitbucketBuildRepositoryTest.java b/src/test/java/BitbucketBuildRepositoryTest.java
index 148e504..f076c4d 100644
--- a/src/test/java/BitbucketBuildRepositoryTest.java
+++ b/src/test/java/BitbucketBuildRepositoryTest.java
@@ -119,7 +119,7 @@ public class BitbucketBuildRepositoryTest {
"", "", "",
true,
true,
- false
+ false, BitbucketRepository.DEFAULT_COMMENT_TRIGGER
);
BitbucketPullRequestsBuilder builder = EasyMock.createMock(BitbucketPullRequestsBuilder.class);
@@ -150,7 +150,7 @@ public class BitbucketBuildRepositoryTest {
"", "", "",
true,
true,
- false
+ false, BitbucketRepository.DEFAULT_COMMENT_TRIGGER
);
BitbucketPullRequestsBuilder builder = EasyMock.createMock(BitbucketPullRequestsBuilder.class);
@@ -205,7 +205,7 @@ public class BitbucketBuildRepositoryTest {
"jenkins", "Jenkins", "",
true,
true,
- false
+ false, BitbucketRepository.DEFAULT_COMMENT_TRIGGER
);
BitbucketPullRequestsBuilder builder = EasyMock.createMock(BitbucketPullRequestsBuilder.class);
@@ -252,7 +252,7 @@ public class BitbucketBuildRepositoryTest {
"jenkins-too-long-ci-key", "Jenkins", "",
true,
true,
- false
+ false, BitbucketRepository.DEFAULT_COMMENT_TRIGGER
);
final MessageDigest MD5 = MessageDigest.getInstance("MD5");