aboutsummaryrefslogtreecommitdiff
path: root/src/main
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/main
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/main')
-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
3 files changed, 23 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) {
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>