From 83260d55784677708a6ab083b06c289ad528099f Mon Sep 17 00:00:00 2001 From: Nicholas Blair Date: Sat, 18 Feb 2017 16:13:33 -0600 Subject: 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). --- .../BitbucketBuildTrigger.java | 29 ---------------------- .../BitbucketRepository.java | 11 +++++++- .../BitbucketBuildTrigger/config.jelly | 2 +- 3 files changed, 11 insertions(+), 31 deletions(-) (limited to 'src/main') 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> { - /** - * 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> { @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 @@ - + -- cgit v1.2.3