diff --git a/pom.xml b/pom.xml index d224ab8..b417799 100644 --- a/pom.xml +++ b/pom.xml @@ -69,10 +69,6 @@ token-macro 2.15 - - org.kohsuke.stapler - stapler - org.jenkins-ci.plugins.workflow workflow-step-api diff --git a/src/main/java/io/jenkins/plugins/wxwork/WXWorkRobotProperty.java b/src/main/java/io/jenkins/plugins/wxwork/WXWorkRobotProperty.java index da2c655..9294abb 100644 --- a/src/main/java/io/jenkins/plugins/wxwork/WXWorkRobotProperty.java +++ b/src/main/java/io/jenkins/plugins/wxwork/WXWorkRobotProperty.java @@ -17,7 +17,6 @@ import lombok.ToString; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; -import org.kohsuke.stapler.verb.POST; import java.util.Objects; @@ -121,7 +120,6 @@ public FormValidation doCheckWebhook(@QueryParameter String webhook) { * @param name 机器人名称 * @param webhook 机器人webhook */ - @POST public FormValidation doTest(@QueryParameter("id") String id, @QueryParameter("name") String name, @QueryParameter("webhook") String webhook) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); RobotProperty property = new WXWorkRobotProperty(id, name, webhook); @@ -130,8 +128,7 @@ public FormValidation doTest(@QueryParameter("id") String id, @QueryParameter("n if (Objects.nonNull(robotResponse)) { if (robotResponse.isOk()) { // ok - String rootUrl = Jenkins.get().getRootUrl(); - return FormValidation.respond(FormValidation.Kind.OK, "" + "测试成功"); + return FormValidation.respond(FormValidation.Kind.OK, "测试成功"); } else { return FormValidation.error(robotResponse.errorMessage()); } diff --git a/src/main/resources/io/jenkins/plugins/wxwork/WXWorkGlobalConfig/config.jelly b/src/main/resources/io/jenkins/plugins/wxwork/WXWorkGlobalConfig/config.jelly index 60d9db7..1a341b6 100644 --- a/src/main/resources/io/jenkins/plugins/wxwork/WXWorkGlobalConfig/config.jelly +++ b/src/main/resources/io/jenkins/plugins/wxwork/WXWorkGlobalConfig/config.jelly @@ -3,22 +3,27 @@ xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" > - - - - - - -
- -
-
-
-
+ +
+ + + + + + + +
+ +
+
+
+
+ +
diff --git a/src/main/resources/io/jenkins/plugins/wxwork/WXWorkRobotProperty/config.jelly b/src/main/resources/io/jenkins/plugins/wxwork/WXWorkRobotProperty/config.jelly index add09e9..8d16626 100644 --- a/src/main/resources/io/jenkins/plugins/wxwork/WXWorkRobotProperty/config.jelly +++ b/src/main/resources/io/jenkins/plugins/wxwork/WXWorkRobotProperty/config.jelly @@ -11,16 +11,23 @@ const closeWxWorkPluginSettingLoading = el => { el.style.display = "none" } - const findWxWorkPluginProperty = el => { - let id = findPreviousFormItem(el, 'id').value; - let name = findPreviousFormItem(el, 'name').value; - let webhook = findPreviousFormItem(el, 'webhook').value; + const findWxWorkPluginTestQuery = (el) => { + let id = el.querySelector('input[name="id"]').value; + let name = el.querySelector('input[name="name"]').value; + let webhook = el.querySelector('input[name="webhook"]').value; - return { + let dict = { id: id, name: name, webhook: webhook } + + let qs = "?" + for (let k in dict) { + qs += k + "=" + dict[k] + "&" + } + return qs } - const sendWxWorkPluginRobotTest = el => { + const sendWxWorkPluginRobotTest = async (el) => { + let $robotBox = el.closest('.wxwork-robot-config') let url = el.getAttribute("data-request-url") let method = el.getAttribute("data-request-method") let loadingBox = el.nextSibling @@ -28,19 +35,17 @@ // send ajax request with requestUrl let requestUrl = url + "/" + method showWxWorkPluginSettingLoading(loadingBox) - new Ajax.Request(requestUrl, { - parameters: findWxWorkPluginProperty(el), onComplete: function (response) { - closeWxWorkPluginSettingLoading(loadingBox) - applyErrorMessage(infoBox, response); - try { - layoutUpdateCallback.call(); - let headerScript = response.getResponseHeader("script"); - geval(headerScript); - } catch (e) { - applyErrorMessage(infoBox, "failed to evaluate " + s + "\n" + e.message); - } - } + // send request + let res = await fetch(requestUrl + findWxWorkPluginTestQuery($robotBox), { + method: 'GET' }) + let resText = await res.text() + if (res.status === 200) { + infoBox.innerHTML = resText + } else { + infoBox.innerHTML = "测试异常!" + } + closeWxWorkPluginSettingLoading(loadingBox) } @@ -48,13 +53,13 @@
- + - + - +