Skip to content

Commit

Permalink
[FIXES JENKINS-24690] Administrative monitor to show hook registering…
Browse files Browse the repository at this point in the history
… problems
  • Loading branch information
lanwen committed Jan 26, 2016
1 parent a244a4a commit bda9cc0
Show file tree
Hide file tree
Showing 28 changed files with 1,120 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,6 @@ target
*.ipr
*.iws
.idea/

# autogenerated resources
src/main/webapp/css/*
23 changes: 20 additions & 3 deletions pom.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -234,6 +235,22 @@
</configuration>
</plugin>

<plugin>
<groupId>nl.geodienstencentrum.maven</groupId>
<artifactId>sass-maven-plugin</artifactId>
<version>2.14</version>
<executions>
<execution>
<goals>
<goal>update-stylesheets</goal>
</goals>
<configuration>
<destination>${basedir}/src/main/webapp/css</destination>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.16</version>
Expand All @@ -259,7 +276,7 @@
</suppressionsLocation>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
Expand All @@ -277,7 +294,7 @@
</goals>
</execution>
</executions>
</plugin>
</plugin>
</plugins>
</build>
</project>
36 changes: 36 additions & 0 deletions src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java
@@ -1,6 +1,7 @@
package com.cloudbees.jenkins;

import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import hudson.Extension;
import hudson.Util;
import hudson.XmlFile;
Expand All @@ -12,6 +13,7 @@
import hudson.model.Project;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
import hudson.util.FormValidation;
import hudson.util.SequentialExecutionQueue;
import hudson.util.StreamTaskListener;
import jenkins.model.Jenkins;
Expand All @@ -20,13 +22,16 @@
import jenkins.triggers.SCMTriggerItem.SCMTriggerItems;
import org.apache.commons.jelly.XMLOutput;
import org.jenkinsci.plugins.github.GitHubPlugin;
import org.jenkinsci.plugins.github.admin.GitHubHookRegisterProblemMonitor;
import org.jenkinsci.plugins.github.config.GitHubPluginConfig;
import org.jenkinsci.plugins.github.internal.GHPluginConfigException;
import org.jenkinsci.plugins.github.migration.Migrator;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
Expand All @@ -40,6 +45,7 @@
import java.util.Set;

import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.jenkinsci.plugins.github.Messages.github_trigger_check_method_warning_details;
import static org.jenkinsci.plugins.github.util.JobInfoHelpers.asParameterizedJobMixIn;

/**
Expand Down Expand Up @@ -226,6 +232,9 @@ public static class DescriptorImpl extends TriggerDescriptor {

private transient List<Credential> credentials;

@Inject
private transient GitHubHookRegisterProblemMonitor monitor;

@Override
public boolean isApplicable(Item item) {
return item instanceof Job && SCMTriggerItems.asSCMTriggerItem(item) != null
Expand Down Expand Up @@ -323,6 +332,33 @@ public static DescriptorImpl get() {
public static boolean allowsHookUrlOverride() {
return ALLOW_HOOKURL_OVERRIDE;
}

/**
* Checks that repo defined in this job is not in administrative monitor as failed to be registered.
* If that so, shows warning with some instructions
*
* @param job - to check against. Should be not null and have at least one repo defined
*
* @return warning or empty string
* @since TODO
*/
@SuppressWarnings("unused")
public FormValidation doCheckHookRegistered(@AncestorInPath Job<?, ?> job) {
Preconditions.checkNotNull(job, "Job can't be null if wants to check hook in monitor");

Collection<GitHubRepositoryName> repos = GitHubRepositoryNameContributor.parseAssociatedNames(job);

for (GitHubRepositoryName repo : repos) {
if (monitor.isProblemWith(repo)) {
return FormValidation.warning(
github_trigger_check_method_warning_details(
repo.getUserName(), repo.getRepositoryName(), repo.getHost()
));
}
}

return FormValidation.ok();
}
}

/**
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/org/jenkinsci/plugins/github/admin/GHRepoName.java
@@ -0,0 +1,46 @@
package org.jenkinsci.plugins.github.admin;

import com.cloudbees.jenkins.GitHubRepositoryName;
import org.kohsuke.stapler.AnnotationHandler;
import org.kohsuke.stapler.InjectedParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.slf4j.Logger;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.apache.commons.lang3.Validate.notNull;
import static org.slf4j.LoggerFactory.getLogger;

/**
* InjectedParameter annotation to use on WebMethod parameters.
* Converts form submission to {@link GitHubRepositoryName}
*
* @author lanwen (Merkushev Kirill)
* @see <a href=https://wiki.jenkins-ci.org/display/JENKINS/Web+Method>Web Method</a>
* @since TODO
*/
@Retention(RUNTIME)
@Target(PARAMETER)
@Documented
@InjectedParameter(GHRepoName.PayloadHandler.class)
public @interface GHRepoName {
class PayloadHandler extends AnnotationHandler<GHRepoName> {
private static final Logger LOGGER = getLogger(PayloadHandler.class);

/**
* @param param name of param in form and name of the argument in web-method
*
* @return {@link GitHubRepositoryName} extracted from request or null on any problem
*/
@Override
public GitHubRepositoryName parse(StaplerRequest req, GHRepoName a, Class type, String param) {
String repo = notNull(req, "Why StaplerRequest is null?").getParameter(param);
LOGGER.trace("Repo url in method {}", repo);
return GitHubRepositoryName.create(repo);
}
}
}

0 comments on commit bda9cc0

Please sign in to comment.