aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorNicholas Blair <nicholas.blair@gmail.com>2017-02-18 16:13:33 -0600
committerNicholas Blair <nicholas.blair@gmail.com>2017-02-18 16:13:33 -0600
commit83260d55784677708a6ab083b06c289ad528099f (patch)
tree8734e6d3a49fc9e8dc96e53b9000d2858d89ba85 /src/main
parent96e6cb666be9cce3f923e3eed39e5e08293c31c5 (diff)
downloadbbprb-83260d55784677708a6ab083b06c289ad528099f.tar.gz
fix: can't have 2 @DataBoundConstructors
Refactor to move default value for commentTrigger to config.jelly. Handle special case in BitbucketBuildRepository where trigger field is null within unit tests (since BitbucketBuildTrigger can't be mocked or initialized in the test).
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java29
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java11
-rw-r--r--src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly2
3 files changed, 11 insertions, 31 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java
index 10d6c98..81b5603 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java
@@ -28,11 +28,6 @@ import static com.cloudbees.plugins.credentials.CredentialsMatchers.instanceOf;
* Created by nishio
*/
public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> {
- /**
- * Default value for {@link #getCommentTrigger()}.
- */
- public static final String DEFAULT_COMMENT_TRIGGER = "test this please";
-
private static final Logger logger = Logger.getLogger(BitbucketBuildTrigger.class.getName());
private final String projectPath;
private final String cron;
@@ -55,30 +50,6 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> {
@Extension
public static final BitbucketBuildTriggerDescriptor descriptor = new BitbucketBuildTriggerDescriptor();
- /**
- * Sets {@link #getCommentTrigger()} to {@link #DEFAULT_COMMENT_TRIGGER}.
- */
- @DataBoundConstructor
- public BitbucketBuildTrigger(
- String projectPath,
- String cron,
- String credentialsId,
- String username,
- String password,
- String repositoryOwner,
- String repositoryName,
- String branchesFilter,
- boolean branchesFilterBySCMIncludes,
- String ciKey,
- String ciName,
- String ciSkipPhrases,
- boolean checkDestinationCommit,
- boolean approveIfSuccess
- ) throws ANTLRException {
- this(projectPath, cron, credentialsId, username, password, repositoryOwner, repositoryName,
- branchesFilter, branchesFilterBySCMIncludes, ciKey, ciName, ciSkipPhrases,
- checkDestinationCommit, approveIfSuccess, DEFAULT_COMMENT_TRIGGER);
- }
@DataBoundConstructor
public BitbucketBuildTrigger(
String projectPath,
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
index ee11e75..01da88e 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
@@ -38,6 +38,10 @@ public class BitbucketRepository {
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;
@@ -182,7 +186,12 @@ public class BitbucketRepository {
}
private boolean isTTPComment(String content) {
- return content.toLowerCase().contains(trigger.getCommentTrigger().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 0992564..5f7c37c 100644
--- a/src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly
+++ b/src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly
@@ -39,6 +39,6 @@
<f:checkbox />
</f:entry>
<f:entry title="Comment phrase to trigger build" field="commentTrigger">
- <f:textbox />
+ <f:textbox default="test this please"/>
</f:entry>
</j:jelly>