-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from pascal-hofmann/configurable-minimum-permi…
…ssions Add configurable minimum permissions for triggers
- Loading branch information
Showing
13 changed files
with
112 additions
and
87 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
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/adobe/jenkins/github_pr_comment_build/TriggerBranchProperty.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,44 @@ | ||
package com.adobe.jenkins.github_pr_comment_build; | ||
|
||
import hudson.model.Job; | ||
import hudson.model.Run; | ||
import jenkins.branch.BranchProperty; | ||
import jenkins.branch.JobDecorator; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
/** | ||
* Common parts of TriggerPR*BranchProperty classes | ||
*/ | ||
abstract public class TriggerBranchProperty extends BranchProperty { | ||
protected boolean allowUntrusted; | ||
protected String minimumPermissions; | ||
|
||
@Deprecated | ||
public boolean isAllowUntrusted() { | ||
return allowUntrusted; | ||
} | ||
|
||
@DataBoundSetter | ||
@Deprecated | ||
public void setAllowUntrusted(boolean allowUntrusted) { | ||
this.allowUntrusted = allowUntrusted; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setMinimumPermissions(String minimumPermissions) { | ||
this.minimumPermissions = minimumPermissions; | ||
} | ||
|
||
public String getMinimumPermissions() { | ||
if (minimumPermissions == null || minimumPermissions.isEmpty()) { | ||
return this.allowUntrusted ? "NONE" : "WRITE"; | ||
} | ||
return minimumPermissions; | ||
} | ||
|
||
@Override | ||
public <P extends Job<P, B>, B extends Run<P, B>> JobDecorator<P, B> jobDecorator(Class<P> clazz) { | ||
return null; | ||
} | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
...n/java/com/adobe/jenkins/github_pr_comment_build/TriggerBranchPropertyDescriptorImpl.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,28 @@ | ||
package com.adobe.jenkins.github_pr_comment_build; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.util.ListBoxModel; | ||
import jenkins.branch.BranchPropertyDescriptor; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
import org.kohsuke.github.GHPermissionType; | ||
|
||
abstract public class TriggerBranchPropertyDescriptorImpl extends BranchPropertyDescriptor { | ||
|
||
/** | ||
* Populates the minimum permissions options. | ||
* | ||
* @return the minimum permissions options. | ||
*/ | ||
@NonNull | ||
@Restricted(NoExternalUse.class) | ||
@SuppressWarnings("unused") // stapler | ||
public ListBoxModel doFillMinimumPermissionsItems() { | ||
ListBoxModel result = new ListBoxModel(); | ||
result.add("Only users with admin permission", String.valueOf(GHPermissionType.ADMIN)); | ||
result.add("Only users that can push to the repository", String.valueOf(GHPermissionType.WRITE)); | ||
result.add("Allow untrusted users to trigger the build", String.valueOf(GHPermissionType.NONE)); | ||
return result; | ||
} | ||
|
||
} |
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
30 changes: 4 additions & 26 deletions
30
src/main/java/com/adobe/jenkins/github_pr_comment_build/TriggerPRReviewBranchProperty.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 |
---|---|---|
@@ -1,47 +1,25 @@ | ||
package com.adobe.jenkins.github_pr_comment_build; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Job; | ||
import hudson.model.Run; | ||
import jenkins.branch.BranchProperty; | ||
import jenkins.branch.BranchPropertyDescriptor; | ||
import jenkins.branch.JobDecorator; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
/** | ||
* Allows a GitHub pull request update to trigger an immediate build. | ||
*/ | ||
public class TriggerPRReviewBranchProperty extends BranchProperty { | ||
private boolean allowUntrusted; | ||
public class TriggerPRReviewBranchProperty extends TriggerBranchProperty { | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
@DataBoundConstructor | ||
public TriggerPRReviewBranchProperty() { } | ||
|
||
public boolean isAllowUntrusted() { | ||
return allowUntrusted; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setAllowUntrusted(boolean allowUntrusted) { | ||
this.allowUntrusted = allowUntrusted; | ||
} | ||
|
||
@Override | ||
public <P extends Job<P, B>, B extends Run<P, B>> JobDecorator<P, B> jobDecorator(Class<P> clazz) { | ||
return null; | ||
} | ||
public TriggerPRReviewBranchProperty() {} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends BranchPropertyDescriptor { | ||
public static class DescriptorImpl extends TriggerBranchPropertyDescriptorImpl { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.TriggerPRReviewBranchProperty_trigger_on_pull_request_review(); | ||
} | ||
|
||
} | ||
} | ||
} |
28 changes: 3 additions & 25 deletions
28
src/main/java/com/adobe/jenkins/github_pr_comment_build/TriggerPRUpdateBranchProperty.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 |
---|---|---|
@@ -1,47 +1,25 @@ | ||
package com.adobe.jenkins.github_pr_comment_build; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Job; | ||
import hudson.model.Run; | ||
import jenkins.branch.BranchProperty; | ||
import jenkins.branch.BranchPropertyDescriptor; | ||
import jenkins.branch.JobDecorator; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
/** | ||
* Allows a GitHub pull request update to trigger an immediate build. | ||
*/ | ||
public class TriggerPRUpdateBranchProperty extends BranchProperty { | ||
private boolean allowUntrusted; | ||
public class TriggerPRUpdateBranchProperty extends TriggerBranchProperty { | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
@DataBoundConstructor | ||
public TriggerPRUpdateBranchProperty() { } | ||
|
||
public boolean isAllowUntrusted() { | ||
return allowUntrusted; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setAllowUntrusted(boolean allowUntrusted) { | ||
this.allowUntrusted = allowUntrusted; | ||
} | ||
|
||
@Override | ||
public <P extends Job<P, B>, B extends Run<P, B>> JobDecorator<P, B> jobDecorator(Class<P> clazz) { | ||
return null; | ||
} | ||
public TriggerPRUpdateBranchProperty() {} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends BranchPropertyDescriptor { | ||
public static class DescriptorImpl extends TriggerBranchPropertyDescriptorImpl { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.TriggerPRUpdateBranchProperty_trigger_on_pull_request_update(); | ||
} | ||
|
||
} | ||
} |
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
...dobe/jenkins/github_pr_comment_build/TriggerPRCommentBranchProperty/help-commentBody.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> | ||
The comment body to trigger a new build for a PR job when it is received. This is compiled as a | ||
case insensitive regular expression, so use ".*" to trigger a build on any comment whatsoever. | ||
case-insensitive regular expression, so use ".*" to trigger a build on any comment whatsoever. | ||
</div> |
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