Skip to content

Commit

Permalink
Merge pull request #44 from nekoimi/dev
Browse files Browse the repository at this point in the history
fix: 修复新版jenkins机器人配置测试失效的问题
  • Loading branch information
nekoimi authored Aug 7, 2024
2 parents 69dfce9 + d0ec089 commit 97e6f32
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 45 deletions.
4 changes: 0 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@
<artifactId>token-macro</artifactId>
<version>2.15</version>
</dependency>
<dependency>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>stapler</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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, "<img src='" + rootUrl + "/images/16x16/accept.png'>" + "<span style='padding-left:4px;color:#52c41a;font-weight:bold;'>测试成功</span>");
return FormValidation.respond(FormValidation.Kind.OK, "<span style='padding-left:4px;color:#52c41a;font-weight:bold;'>测试成功</span>");

Check warning on line 131 in src/main/java/io/jenkins/plugins/wxwork/WXWorkRobotProperty.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 131 is not covered by tests
} else {
return FormValidation.error(robotResponse.errorMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" >

<f:section title="${%robotPropertyTitle}">
<f:block>
<j:scope>
<j:set var="robotPropertyList" value="${instance.getRobotPropertyList()}"/>
<j:set var="robotPropertyDescriptor" value="${descriptor.getWXWorkRobotPropertyDescriptor()}"/>
<f:repeatable
header="${%robotProperty}"
field="robotPropertyList"
varStatus="item"
items="robotPropertyList">
<st:include page="config.jelly" class="${robotPropertyDescriptor.clazz}"/>
<div style="text-align: right; margin-top: 8px;">
<f:repeatableDeleteButton/>
</div>
</f:repeatable>
</j:scope>
</f:block>

<div id="wxwork-robot-config-box">

<f:block>
<j:scope>
<j:set var="robotPropertyList" value="${instance.getRobotPropertyList()}"/>
<j:set var="robotPropertyDescriptor" value="${descriptor.getWXWorkRobotPropertyDescriptor()}"/>
<f:repeatable
header="${%robotProperty}"
field="robotPropertyList"
varStatus="item"
items="robotPropertyList">
<st:include page="config.jelly" class="${robotPropertyDescriptor.clazz}"/>
<div style="text-align: right; margin-top: 8px;">
<f:repeatableDeleteButton/>
</div>
</f:repeatable>
</j:scope>
</f:block>

</div>

</f:section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,55 @@
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] + "&amp;"
}
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
let infoBox = loadingBox.nextSibling
// 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)
}
</script>
</st:once>

<div class="wxwork-robot-config" style="width: 100%;">

<f:entry title="${%robotUniqueID}" field="id">
<f:textbox/>
<f:textbox name="id"/>
</f:entry>
<f:entry title="${%robotName}" field="name">
<f:textbox/>
<f:textbox name="name"/>
</f:entry>
<f:entry title="${%robotWebhook}" field="webhook">
<f:textbox/>
<f:textbox name="webhook"/>
</f:entry>

<f:block>
Expand Down

0 comments on commit 97e6f32

Please sign in to comment.