Skip to content

Commit fe0c542

Browse files
committed
throw config exception on empty jenkins root url
1 parent e4f7c8e commit fe0c542

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/main/java/org/jenkinsci/plugins/github/config/GitHubPluginConfig.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.apache.commons.codec.binary.Base64;
1515
import org.jenkinsci.main.modules.instance_identity.InstanceIdentity;
1616
import org.jenkinsci.plugins.github.GitHubPlugin;
17+
import org.jenkinsci.plugins.github.Messages;
1718
import org.jenkinsci.plugins.github.internal.GHPluginConfigException;
1819
import org.jenkinsci.plugins.github.migration.Migrator;
1920
import org.kohsuke.github.GitHub;
@@ -34,6 +35,7 @@
3435

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

104106
public URL getHookUrl() throws GHPluginConfigException {
105107
try {
108+
String jenkinsUrl = Jenkins.getInstance().getRootUrl();
109+
110+
if (isEmpty(jenkinsUrl)) {
111+
throw new GHPluginConfigException(Messages.global_config_url_is_empty());
112+
}
113+
106114
return hookUrl != null
107115
? hookUrl
108-
: new URL(Jenkins.getInstance().getRootUrl() + GitHubWebHook.get().getUrlName() + '/');
116+
: new URL(jenkinsUrl + GitHubWebHook.get().getUrlName() + '/');
109117
} catch (MalformedURLException e) {
110-
throw new GHPluginConfigException(
111-
"Mailformed GH hook url in global configuration (%s)", e.getMessage()
112-
);
118+
throw new GHPluginConfigException(Messages.global_config_hook_url_is_mailformed(e.getMessage()));
113119
}
114120
}
115121

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global.config.url.is.empty=Jenkins URL is empty. Set explicitly Jenkins URL in global configuration or in GitHub plugin configuration to manage hooks.
2+
global.config.hook.url.is.mailformed=Mailformed GH hook url in global configuration ({0})

0 commit comments

Comments
 (0)