8000 [FIXES JENKINS-24690] Administrative monitor to show hook registering… · github-cloud/github-plugin@bda9cc0 · GitHub
[go: up one dir, main page]

Skip to content

Commit bda9cc0

Browse files
committed
[FIXES JENKINS-24690] Administrative monitor to show hook registering problems
1 parent a244a4a commit bda9cc0

File tree

28 files changed

+1120
-8
lines changed

28 files changed

+1120
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ target
88
*.ipr
99
*.iws
1010
.idea/
11+
12+
# autogenerated resources
13+
src/main/webapp/css/*

pom.xml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<parent>
@@ -234,6 +235,22 @@
234235
</configuration>
235236
</plugin>
236237

238+
<plugin>
239+
<groupId>nl.geodienstencentrum.maven</groupId>
240+
<artifactId>sass-maven-plugin</artifactId>
241+
<version>2.14</version>
242+
<executions>
243+
<execution>
244+
<goals>
245+
<goal>update-stylesheets</goal>
246+
</goals>
247+
<configuration>
248+
<destination>${basedir}/src/main/webapp/css</destination>
249+
</configuration>
250+
</execution>
251+
</executions>
252+
</plugin>
253+
237254
<plugin>
238255
<artifactId>maven-checkstyle-plugin</artifactId>
239256
<version>2.16</version>
@@ -259,7 +276,7 @@
259276
</suppressionsLocation>
260277
</configuration>
261278
</plugin>
262-
279+
263280
<plugin>
264281
<groupId>org.codehaus.mojo</groupId>
265282
<artifactId>findbugs-maven-plugin</artifactId>
@@ -277,7 +294,7 @@
277294
</goals>
278295
</execution>
279296
</executions>
280-
</plugin>
297+
</plugin>
281298
</plugins>
282299
</build>
283300
</project>

src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cloudbees.jenkins;
22

33
import com.google.common.base.Charsets;
4+
import com.google.common.base.Preconditions;
45
import hudson.Extension;
56
import hudson.Util;
67
import hudson.XmlFile;
@@ -12,6 +13,7 @@
1213
import hudson.model.Project;
1314
import hudson.triggers.Trigger;
1415
import hudson.triggers.TriggerDescriptor;
16+
import hudson.util.FormValidation;
1517
import hudson.util.SequentialExecutionQueue;
1618
import hudson.util.StreamTaskListener;
1719
import jenkins.model.Jenkins;
@@ -20,13 +22,16 @@
2022
import jenkins.triggers.SCMTriggerItem.SCMTriggerItems;
2123
import org.apache.commons.jelly.XMLOutput;
2224
import org.jenkinsci.plugins.github.GitHubPlugin;
25+
import org.jenkinsci.plugins.github.admin.GitHubHookRegisterProblemMonitor;
2326
import org.jenkinsci.plugins.github.config.GitHubPluginConfig;
2427
import org.jenkinsci.plugins.github.internal.GHPluginConfigException;
2528
import org.jenkinsci.plugins.github.migration.Migrator;
29+
import org.kohsuke.stapler.AncestorInPath;
2630
import org.kohsuke.stapler.DataBoundConstructor;
2731
import org.slf4j.Logger;
2832
import org.slf4j.LoggerFactory;
2933

34+
import javax.inject.Inject;
3035
import java.io.File;
3136
import java.io.IOException;
3237
import java.io.PrintStream;
@@ -40,6 +45,7 @@
4045
import java.util.Set;
4146

4247
import static org.apache.commons.lang3.StringUtils.isEmpty;
48+
import static org.jenkinsci.plugins.github.Messages.github_trigger_check_method_warning_details;
4349
import static org.jenkinsci.plugins.github.util.JobInfoHelpers.asParameterizedJobMixIn;
4450

4551
/**
@@ -226,6 +232,9 @@ public static class DescriptorImpl extends TriggerDescriptor {
226232

227233
private transient List<Credential> credentials;
228234

235+
@Inject
236+
private transient GitHubHookRegisterProblemMonitor monitor;
237+
229238
@Override
230239
public boolean isApplicable(Item item) {
231240
return item instanceof Job && SCMTriggerItems.asSCMTriggerItem(item) != null
@@ -323,6 +332,33 @@ public static DescriptorImpl get() {
323332
public static boolean allowsHookUrlOverride() {
324333
return ALLOW_HOOKURL_OVERRIDE;
325334
}
335+
336+
/**
337+
* Checks that repo defined in this job is not in administrative monitor as failed to be registered.
338+
* If that so, shows warning with some instructions
339+
*
340+
* @param job - to check against. Should be not null and have at least one repo defined
341+
*
342+
* @return warning or empty string
343+
* @since TODO
344+
*/
345+
@SuppressWarnings("unused")
346+
public FormValidation doCheckHookRegistered(@AncestorInPath Job<?, ?> job) {
347+
Preconditions.checkNotNull(job, "Job can't be null if wants to check hook in monitor");
348+
349+
Collection<GitHubRepositoryName> repos = GitHubRepositoryNameContributor.parseAssociatedNames(job);
350+
351+
for (GitHubRepositoryName repo : repos) {
352+
if (monitor.isProblemWith(repo)) {
353+
return FormValidation.warning(
354+
github_trigger_check_method_warning_details(
355+
repo.getUserName(), repo.getRepositoryName(), repo.getHost()
356+
));
357+
}
358+
}
359+
360+
return FormValidation.ok();
361+
}
326362
}
327363

328364
/**
Lines changed: 46 additions & 0 deletions
< 6D3F td data-grid-cell-id="diff-b1b012ad97a3e7fae680e69fda6136db6a75c1fa301b2824be799bd737364a85-empty-4-2" data-line-anchor="diff-b1b012ad97a3e7fae680e69fda6136db6a75c1fa301b2824be799bd737364a85R4" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionLine-bgColor, var(--diffBlob-addition-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">+
import org.kohsuke.stapler.AnnotationHandler;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.jenkinsci.plugins.github.admin;
2+
3+
import com.cloudbees.jenkins.GitHubRepositoryName;
4
5+
import org.kohsuke.stapler.InjectedParameter;
6+
import org.kohsuke.stapler.StaplerRequest;
7+
import org.slf4j.Logger;
8+
9+
import java.lang.annotation.Documented;
10+
import java.lang.annotation.Retention;
11+
import java.lang.annotation.Target;
12+
13+
import static java.lang.annotation.ElementType.PARAMETER;
14+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
15+
import static org.apache.commons.lang3.Validate.notNull;
16+
import static org.slf4j.LoggerFactory.getLogger;
17+
18+
/**
19+
* InjectedParameter annotation to use on WebMethod parameters.
20+
* Converts form submission to {@link GitHubRepositoryName}
21+
*
22+
* @author lanwen (Merkushev Kirill)
23+
* @see <a href=https://wiki.jenkins-ci.org/display/JENKINS/Web+Method>Web Method</a>
24+
* @since TODO
25+
*/
26+
@Retention(RUNTIME)
27+
@Target(PARAMETER)
28+
@Documented
29+
@InjectedParameter(GHRepoName.PayloadHandler.class)
30+
public @interface GHRepoName {
31+
class PayloadHandler extends AnnotationHandler<GHRepoName> {
32+
private static final Logger LOGGER = getLogger(PayloadHandler.class);
33+
34+
/**
35+
* @param param name of param in form and name of the argument in web-method
36+
*
37+
* @return {@link GitHubRepositoryName} extracted from request or null on any problem
38+
*/
39+
@Override
40+
public GitHubRepositoryName parse(StaplerRequest req, GHRepoName a, Class type, String param) {
41+
String repo = notNull(req, "Why StaplerRequest is null?").getParameter(param);
42+
LOGGER.trace("Repo url in method {}", repo);
43+
return GitHubRepositoryName.create(repo);
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)
0