8000 [JENKINS-60738] Fix global configuration submission from UI · jenkinsci/github-plugin@cfaa0c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit cfaa0c4

Browse files
committed
[JENKINS-60738] Fix global configuration submission from UI
1 parent 80dd71b commit cfaa0c4

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.common.base.Function;
55
import com.google.common.base.Predicate;
66
import com.google.common.base.Predicates;
7+
import hudson.BulkChange;
78
import hudson.Extension;
89
import hudson.Util;
910
import hudson.XmlFile;
@@ -190,17 +191,36 @@ protected XmlFile getConfigFile() {
190191

191192
@Override
192193
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
193-
hookSecretConfigs = null; // form binding might omit empty lists
194194
try {
195-
req.bindJSON(this, json);
195+
BulkChange bc = new BulkChange(this);
196+
try {
197+
if (json.has("configs")) {
198+
setConfigs(req.bindJSONToList(GitHubServerConfig.class, json.getJSONObject("configs")));
199+
} else {
200+
setConfigs(Collections.emptyList());
201+
}
202+
if (json.has("hookSecretConfigs")) {
203+
setHookSecretConfigs(req.bindJSONToList(HookSecretConfig.class,
204+
json.getJSONObject("hookSecretConfigs")));
205+
} else {
206+
setHookSecretConfigs(Collections.emptyList());
207+
}
208+
if (json.optBoolean("isOverrideHookUrl", false) && (json.has("hookUrl"))) {
209+
setHookUrl(json.optString("hookUrl"));
210+
} else {
211+
setHookUrl(null);
212+
}
213+
req.bindJSON(this, json);
214+
clearRedundantCaches(configs);
215+
} finally {
216+
bc.commit();
217+
}
196218
} catch (Exception e) {
197219
LOGGER.debug("Problem while submitting form for GitHub Plugin ({})", e.getMessage(), e);
198220
LOGGER.trace("GH form data: {}", json.toString());
199221
throw new FormException(
200222
format("Malformed GitHub Plugin configuration (%s)", e.getMessage()), e, "github-configuration");
201223
}
202-
save();
203-
clearRedundantCaches(configs);
204224
return true;
205225
}
206226

src/main/resources/org/jenkinsci/plugins/github/config/GitHubPluginConfig/config.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ f.section(title: descriptor.displayName) {
2727
f.entry(title: _("Override Hook URL")) {
2828
g.blockWrapper {
2929
f.optionalBlock(title: _("Specify another hook URL for GitHub configuration"),
30+
name: "isOverrideHookUrl",
3031
inline: true,
3132
checked: instance.isOverrideHookUrl()) {
3233
f.entry(field: "hookUrl") {
33-
f.textbox(checkMethod: "post")
34+
f.textbox(checkMethod: "post", name: "hookUrl")
3435
}
3536
}
3637
}

src/test/java/com/cloudbees/jenkins/GlobalConfigSubmitTest.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.gargoylesoftware.htmlunit.html.HtmlForm;
44
import com.gargoylesoftware.htmlunit.html.HtmlPage;
55
import org.jenkinsci.plugins.github.GitHubPlugin;
6-
import org.junit.Ignore;
76
import org.junit.Rule;
87
import org.junit.Test;
98
import org.jvnet.hudson.test.JenkinsRule;
@@ -14,17 +13,18 @@
1413

1514
import static org.hamcrest.MatcherAssert.assertThat;
1615
import static org.hamcrest.Matchers.equalTo;
16+
import static org.hamcrest.Matchers.startsWith;
1717

1818
/**
1919
* Test Class for {@link GitHubPushTrigger}.
2020
*
2121
* @author Seiji Sogabe
2222
*/
23-
@Ignore("Have troubles with memory consumption")
23+
//@Ignore("Have troubles with memory consumption")
2424
public class GlobalConfigSubmitTest {
2525

26-
public static final String OVERRIDE_HOOK_URL_CHECKBOX = "_.isOverrideHookUrl";
27-
public static final String HOOK_URL_INPUT = "_.hookUrl";
26+
public static final String OVERRIDE_HOOK_URL_CHECKBOX = "isOverrideHookUrl";
27+
public static final String HOOK_URL_INPUT = "hookUrl";
2828

2929
private static final String WEBHOOK_URL = "http://jenkinsci.example.com/jenkins/github-webhook/";
3030

@@ -43,7 +43,7 @@ public void shouldSetHookUrl() throws Exception {
4343
}
4444

4545
@Test
46-
public void shouldNotSetHookUrl() throws Exception {
46+
public void shouldResetHookUrlIfNotChecked() throws Exception {
4747
GitHubPlugin.configuration().setHookUrl(WEBHOOK_URL);
4848

4949
HtmlForm form = globalConfig();
@@ -52,20 +52,7 @@ public void shouldNotSetHookUrl() throws Exception {
5252
form.getInputByName(HOOK_URL_INPUT).setValueAttribute("http://foo");
5353
jenkins.submit(form);
5454

55-
assertThat(GitHubPlugin.configuration().getHookUrl(), equalTo(new URL(WEBHOOK_URL)));
56-
}
57-
58-
@Test
59-
public void shouldNotOverrideAPreviousHookUrlIfNotChecked() throws Exception {
60-
GitHubPlugin.configuration().setHookUrl(WEBHOOK_URL);
61-
62-
HtmlForm form = globalConfig();
63-
64-
form.getInputByName(OVERRIDE_HOOK_URL_CHECKBOX).setChecked(false);
65-
form.getInputByName(HOOK_URL_INPUT).setValueAttribute("");
66-
jenkins.submit(form);
67-
68-
assertThat(GitHubPlugin.configuration().getHookUrl(), equalTo(new URL(WEBHOOK_URL)));
55+
assertThat(GitHubPlugin.configuration().getHookUrl().toString(), startsWith(jenkins.jenkins.getRootUrl()));
6956
}
7057

7158
public HtmlForm globalConfig() throws IOException, SAXException {

0 commit comments

Comments
 (0)
0