From d0ec0890830e466cec8b03c5bef9ba4645bb5aa7 Mon Sep 17 00:00:00 2001 From: nekoimi Date: Wed, 7 Aug 2024 22:43:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=B0=E7=89=88jenk?= =?UTF-8?q?ins=E6=9C=BA=E5=99=A8=E4=BA=BA=E9=85=8D=E7=BD=AE=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 -- .../plugins/wxwork/WXWorkRobotProperty.java | 5 +- .../wxwork/WXWorkGlobalConfig/config.jelly | 37 ++++++++------- .../wxwork/WXWorkRobotProperty/config.jelly | 47 ++++++++++--------- 4 files changed, 48 insertions(+), 45 deletions(-) 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 @@
- + - + - +