-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the "pr:comment:added" bitbucket server event (#122)
fix 121 Co-authored-by: rabadin <rvbadin@gmail.com>
- Loading branch information
Showing
19 changed files
with
699 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ullrequest/cause/pullrequest/server/BitBucketPPRPullRequestServerCommentCreatedCause.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/******************************************************************************* | ||
* The MIT License | ||
* | ||
* Copyright (C) 2020, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
******************************************************************************/ | ||
|
||
|
||
package io.jenkins.plugins.bitbucketpushandpullrequest.cause.pullrequest.server; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import io.jenkins.plugins.bitbucketpushandpullrequest.action.BitBucketPPRAction; | ||
|
||
|
||
public class BitBucketPPRPullRequestServerCommentCreatedCause extends BitBucketPPRPullRequestServerCause { | ||
public BitBucketPPRPullRequestServerCommentCreatedCause(File pollingLog, BitBucketPPRAction bitbucketAction) | ||
throws IOException { | ||
super(pollingLog, bitbucketAction); | ||
} | ||
|
||
@Override | ||
public String getShortDescription() { | ||
String pusher = bitbucketAction.getUser() != null ? bitbucketAction.getUser() : ""; | ||
return "Started by user " + pusher + ": Bitbucket PPR: comment created for pull request"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...st/filter/pullrequest/server/BitBucketPPRPullRequestServerCommentCreatedActionFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/******************************************************************************* | ||
* The MIT License | ||
* | ||
* Copyright (C) 2020, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
******************************************************************************/ | ||
|
||
package io.jenkins.plugins.bitbucketpushandpullrequest.filter.pullrequest.server; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
import hudson.EnvVars; | ||
import hudson.Extension; | ||
import io.jenkins.plugins.bitbucketpushandpullrequest.action.BitBucketPPRAction; | ||
import io.jenkins.plugins.bitbucketpushandpullrequest.cause.BitBucketPPRTriggerCause; | ||
import io.jenkins.plugins.bitbucketpushandpullrequest.cause.pullrequest.server.BitBucketPPRPullRequestServerCommentCreatedCause; | ||
import io.jenkins.plugins.bitbucketpushandpullrequest.util.BitBucketPPRUtils; | ||
|
||
public class BitBucketPPRPullRequestServerCommentCreatedActionFilter | ||
extends BitBucketPPRPullRequestServerActionFilter { | ||
|
||
public String allowedBranches; | ||
public String commentFilter; | ||
|
||
@DataBoundConstructor | ||
public BitBucketPPRPullRequestServerCommentCreatedActionFilter() {} | ||
|
||
@DataBoundSetter | ||
public void setAllowedBranches(String allowedBranches) { | ||
if (allowedBranches == null) { | ||
this.allowedBranches = ""; | ||
} else { | ||
this.allowedBranches = allowedBranches; | ||
} | ||
} | ||
|
||
@DataBoundSetter | ||
public void setCommentFilter(String commentFilter) { | ||
if (commentFilter == null) { | ||
this.commentFilter = ""; | ||
} else { | ||
this.commentFilter = commentFilter; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { | ||
return matches(allowedBranches, bitbucketAction.getTargetBranch(), null) && | ||
hasInComment(bitbucketAction.getServerComment(), null); | ||
} | ||
|
||
@Override | ||
public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction) | ||
throws IOException { | ||
return new BitBucketPPRPullRequestServerCommentCreatedCause(pollingLog, pullRequestAction); | ||
} | ||
|
||
@Override | ||
public boolean shouldSendApprove() { | ||
return false; | ||
} | ||
|
||
public boolean hasInComment(String comment, EnvVars vars) { | ||
return BitBucketPPRUtils.matchWithRegex(comment, commentFilter, vars); | ||
} | ||
|
||
@Extension | ||
public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestServerActionDescriptor { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Comment Created"; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BitBucketPPRPullRequestServerCommentCreatedActionFilter [getDescriptor()=" + getDescriptor() | ||
+ ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" | ||
+ super.toString() + "]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lter/pullrequest/cloud/BitBucketPPRPullRequestCommentCreatedActionFilter/help-filter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<div> | ||
<p>Specify a java regex filter on the text's comment. If left blank, all comments will be examined for changes and built.</p> | ||
<p>Specify a java regex filter on the comment's text. If left blank, all comments will be examined for changes and built.</p> | ||
<p>For more infos about regex in java, consult the official java documentation</p> | ||
</div> |
2 changes: 1 addition & 1 deletion
2
...lter/pullrequest/cloud/BitBucketPPRPullRequestCommentUpdatedActionFilter/help-filter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<div> | ||
<p>Specify a java regex filter on the text's comment. If left blank, all comments will be examined for changes and built.</p> | ||
<p>Specify a java regex filter on the comment's text. If left blank, all comments will be examined for changes and built.</p> | ||
<p>For more infos about regex in java, consult the official java documentation</p> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
...r/pullrequest/server/BitBucketPPRPullRequestServerCommentCreatedActionFilter/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form"> | ||
<f:entry title="Allowed Branches" field="allowed"> | ||
<f:textbox field="allowedBranches" /> | ||
</f:entry> | ||
<f:entry title="Filter Comment" field="filter"> | ||
<f:textbox field="commentFilter" /> | ||
</f:entry> | ||
</j:jelly> |
Oops, something went wrong.