Skip to content

Commit

Permalink
Merge branch 'master' into keymux-master
Browse files Browse the repository at this point in the history
  • Loading branch information
henry committed Sep 13, 2018
2 parents 576fa78 + 4e86ed4 commit a5b009e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
### Updates

* Feature: Enable commentFilePath in the DSL (#514)
### -> 1.41.0

* Fix for stale ghprbCommentBody values ([#504][#504])
* Improve "Build triggered/started" messages ([#607][#607])
* Avoid posting a comment for empty comment files ([#662][#662])
* Use ssl validation for webhook ([#663][#663])

[#504]: https://github.com/jenkinsci/ghprb-plugin/pull/504
[#607]: https://github.com/jenkinsci/ghprb-plugin/pull/607
[#662]: https://github.com/jenkinsci/ghprb-plugin/pull/662
[#663]: https://github.com/jenkinsci/ghprb-plugin/pull/663

#### -> 1.40.0

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<artifactId>ghprb</artifactId>
<name>GitHub Pull Request Builder</name>
<version>1.41.0-SNAPSHOT</version>
<version>1.42.1-SNAPSHOT</version>
<packaging>hpi</packaging>

<url>https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin</url>
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/org/jenkinsci/plugins/ghprb/GhprbGitHubAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import hudson.util.Secret;
import jenkins.model.Jenkins;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
Expand All @@ -32,11 +33,11 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.verb.POST;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -57,7 +58,7 @@ public class GhprbGitHubAuth extends AbstractDescribableImpl<GhprbGitHubAuth> {

private static final int SHA1_PREFIX_LENGTH = 5;

static final int INITIAL_CAPACITY = 3;
private static final int INITIAL_CAPACITY = 3;

private final String serverAPIUrl;

Expand Down Expand Up @@ -241,16 +242,15 @@ public String getDisplayName() {
* @param serverAPIUrl the github api server url.
* @param credentialsId the credentialsId from the credentials plugin
* @return list box model.
* @throws URISyntaxException If the url is bad
*/
public ListBoxModel doFillCredentialsIdItems(
@AncestorInPath Item context,
@QueryParameter String serverAPIUrl,
@QueryParameter String credentialsId
) throws URISyntaxException {
) {
List<DomainRequirement> domainRequirements = URIRequirementBuilder.fromUri(serverAPIUrl).build();

List<CredentialsMatcher> matchers = new ArrayList<CredentialsMatcher>(INITIAL_CAPACITY);
List<CredentialsMatcher> matchers = new ArrayList<>(INITIAL_CAPACITY);
if (!StringUtils.isEmpty(credentialsId)) {
matchers.add(0, CredentialsMatchers.withId(credentialsId));
}
Expand All @@ -273,14 +273,16 @@ public ListBoxModel doFillCredentialsIdItems(
);
}


@POST
public FormValidation doCreateApiToken(
@QueryParameter("serverAPIUrl") final String serverAPIUrl,
@QueryParameter("credentialsId") final String credentialsId,
@QueryParameter("username") final String username,
@QueryParameter("password") final String password) {
try {

Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);

GitHubBuilder builder = new GitHubBuilder()
.withEndpoint(serverAPIUrl)
.withConnector(new HttpConnectorWithJenkinsProxy());
Expand Down Expand Up @@ -326,10 +328,14 @@ public FormValidation doCheckServerAPIUrl(@QueryParameter String value) {
return FormValidation.warning("GitHub API URI is \"https://api.github.com\". GitHub Enterprise API URL ends with \"/api/v3\"");
}

@POST
public FormValidation doCheckRepoAccess(
@QueryParameter("serverAPIUrl") final String serverAPIUrl,
@QueryParameter("credentialsId") final String credentialsId,
@QueryParameter("repo") final String repo) {

Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);

try {
GitHubBuilder builder = getBuilder(null, serverAPIUrl, credentialsId);
if (builder == null) {
Expand All @@ -339,7 +345,7 @@ public FormValidation doCheckRepoAccess(
GHRepository repository = gh.getRepository(repo);
StringBuilder sb = new StringBuilder();
sb.append("User has access to: ");
List<String> permissions = new ArrayList<String>(INITIAL_CAPACITY);
List<String> permissions = new ArrayList<>(INITIAL_CAPACITY);
if (repository.hasAdminAccess()) {
permissions.add("Admin");
}
Expand All @@ -357,9 +363,13 @@ public FormValidation doCheckRepoAccess(
}
}

@POST
public FormValidation doTestGithubAccess(
@QueryParameter("serverAPIUrl") final String serverAPIUrl,
@QueryParameter("credentialsId") final String credentialsId) {

Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);

try {
GitHubBuilder builder = getBuilder(null, serverAPIUrl, credentialsId);
if (builder == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public boolean createHook() {
Map<String, String> config = new HashMap<String, String>();
String secret = getSecret();
config.put("url", new URL(getHookUrl()).toExternalForm());
config.put("insecure_ssl", "1");
config.put("insecure_ssl", "0");
if (!StringUtils.isEmpty(secret)) {
config.put("secret", secret);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.jenkinsci.plugins.ghprb.jobdsl;

import javaposse.jobdsl.dsl.Context;

class GhprbCancelBuildsOnUpdateContext implements Context {
private Boolean overrideGlobal;

public Boolean getOverrideGlobal() {
return overrideGlobal;
}

/**
* sets the overrideGlobal value
*/
public void overrideGlobal(Boolean overrideGlobal) {
this.overrideGlobal = overrideGlobal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javaposse.jobdsl.dsl.Context;
import javaposse.jobdsl.plugin.ContextExtensionPoint;
import org.jenkinsci.plugins.ghprb.extensions.GhprbExtension;
import org.jenkinsci.plugins.ghprb.extensions.build.GhprbCancelBuildsOnUpdate;
import org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildStatus;
import org.jenkinsci.plugins.ghprb.extensions.comments.GhprbCommentFile;
import org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus;
Expand Down Expand Up @@ -51,6 +52,16 @@ void commentFilePath(Runnable closure) {
extensions.add(new GhprbCommentFile(context.getCommentFilePath()));
}

/**
* Overrides global settings for cancelling builds when a PR was updated
*/
void cancelBuildsOnUpdate(Runnable closure) {
GhprbCancelBuildsOnUpdateContext context = new GhprbCancelBuildsOnUpdateContext();
ContextExtensionPoint.executeInContext(closure, context);

extensions.add(new GhprbCancelBuildsOnUpdate(context.getOverrideGlobal()));
}

public List<GhprbExtension> getExtensions() {
return extensions;
}
Expand Down

0 comments on commit a5b009e

Please sign in to comment.