diff options
Diffstat (limited to 'src')
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"); |