Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #77 from lanwen/JENKINS-30207_fix
Browse files Browse the repository at this point in the history
[FIXES JENKINS-30207] Don't run cleaner if github plugin not manage hooks
  • Loading branch information
KostyaSha committed Aug 30, 2015
2 parents 8791c2a + fe0c542 commit 80c8396
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/cloudbees/jenkins/Cleaner.java
Expand Up @@ -55,6 +55,10 @@ public long getRecurrencePeriod() {
*/
@Override
protected void doRun() throws Exception {
if (!GitHubPlugin.configuration().isManageHooks()) {
return;
}

URL url = GitHubPlugin.configuration().getHookUrl();

List<AbstractProject> jobs = Jenkins.getInstance().getAllItems(AbstractProject.class);
Expand Down
Expand Up @@ -14,6 +14,7 @@
import org.apache.commons.codec.binary.Base64;
import org.jenkinsci.main.modules.instance_identity.InstanceIdentity;
import org.jenkinsci.plugins.github.GitHubPlugin;
import org.jenkinsci.plugins.github.Messages;
import org.jenkinsci.plugins.github.internal.GHPluginConfigException;
import org.jenkinsci.plugins.github.migration.Migrator;
import org.kohsuke.github.GitHub;
Expand All @@ -34,6 +35,7 @@

import static com.google.common.base.Charsets.UTF_8;
import static java.lang.String.format;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.jenkinsci.plugins.github.config.GitHubServerConfig.allowedToManageHooks;
import static org.jenkinsci.plugins.github.config.GitHubServerConfig.loginToGithub;
import static org.jenkinsci.plugins.github.util.FluentIterableWrapper.from;
Expand Down Expand Up @@ -103,13 +105,17 @@ public void setOverrideHookUrl(boolean overrideHookUrl) {

public URL getHookUrl() throws GHPluginConfigException {
try {
String jenkinsUrl = Jenkins.getInstance().getRootUrl();

if (isEmpty(jenkinsUrl)) {
throw new GHPluginConfigException(Messages.global_config_url_is_empty());
}

return hookUrl != null
? hookUrl
: new URL(Jenkins.getInstance().getRootUrl() + GitHubWebHook.get().getUrlName() + '/');
: new URL(jenkinsUrl + GitHubWebHook.get().getUrlName() + '/');
} catch (MalformedURLException e) {
throw new GHPluginConfigException(
"Mailformed GH hook url in global configuration (%s)", e.getMessage()
);
throw new GHPluginConfigException(Messages.global_config_hook_url_is_mailformed(e.getMessage()));
}
}

Expand Down
@@ -0,0 +1,2 @@
global.config.url.is.empty=Jenkins URL is empty. Set explicitly Jenkins URL in global configuration or in GitHub plugin configuration to manage hooks.
global.config.hook.url.is.mailformed=Mailformed GH hook url in global configuration ({0})

0 comments on commit 80c8396

Please sign in to comment.