diff options
Diffstat (limited to 'src/main/java')
2 files changed, 20 insertions, 3 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) { |