Skip to content

Commit db6cb22

Browse files
committed
fix: jenkins 移除 prototype 导致机器人配置测试功能报错
close #223
1 parent dd1c491 commit db6cb22

File tree

2 files changed

+98
-140
lines changed

2 files changed

+98
-140
lines changed

pom.xml

+5-25
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
<parent>
66
<groupId>org.jenkins-ci.plugins</groupId>
77
<artifactId>plugin</artifactId>
8-
<version>4.48</version>
9-
<relativePath />
8+
<version>4.75</version>
109
</parent>
1110
<groupId>io.jenkins.plugins</groupId>
1211
<artifactId>dingding-notifications</artifactId>
1312
<version>2.7.1-SNAPSHOT</version>
1413
<packaging>hpi</packaging>
1514
<properties>
16-
<jenkins.version>2.387.1</jenkins.version>
15+
<jenkins.version>2.432</jenkins.version>
1716
<hpi.compatibleSinceVersion>2.0.0</hpi.compatibleSinceVersion>
1817
</properties>
1918

@@ -63,42 +62,23 @@
6362
<dependency>
6463
<groupId>org.projectlombok</groupId>
6564
<artifactId>lombok</artifactId>
66-
<version>1.18.28</version>
65+
<version>1.18.30</version>
6766
<scope>provided</scope>
6867
</dependency>
6968
</dependencies>
7069

71-
<dependencyManagement>
72-
<dependencies>
73-
<dependency>
74-
<groupId>io.jenkins.tools.bom</groupId>
75-
<artifactId>bom-2.319.x</artifactId>
76-
<version>1654.vcb_69d035fa_20</version>
77-
<type>pom</type>
78-
</dependency>
79-
</dependencies>
80-
</dependencyManagement>
81-
8270
<repositories>
8371
<repository>
84-
<id>aliyun-public</id>
85-
<url>https://maven.aliyun.com/repository/public</url>
86-
</repository>
87-
<repository>
88-
<id>repo.jenkins-ci.org</id>
72+
<id>jenkins-ci</id>
8973
<url>https://repo.jenkins-ci.org/public</url>
9074
</repository>
9175
</repositories>
9276

9377
<pluginRepositories>
9478
<pluginRepository>
95-
<id>repo.jenkins-ci.org</id>
79+
<id>jenkins-ci</id>
9680
<url>https://repo.jenkins-ci.org/public</url>
9781
</pluginRepository>
98-
<pluginRepository>
99-
<id>aliyun-public</id>
100-
<url>https://maven.aliyun.com/repository/public</url>
101-
</pluginRepository>
10282
</pluginRepositories>
10383

10484
</project>
+93-115
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,95 @@
11
(function ($) {
2-
if (!$) {
3-
throw new Error('jQuery 插件加载失败将无法校验机器人配置,但不影响正常使用')
4-
}
5-
6-
$(function () {
7-
$(document).on('click', '.robot-config-validate-btn', validateRobotConfig)
8-
})
9-
10-
function applyErrorMessage(elt, rsp) {
11-
if (rsp.status == 200) {
12-
elt.innerHTML = rsp.responseText;
13-
} else {
14-
var id = 'valerr' + (iota++);
15-
elt.innerHTML = '<a href="" onclick="document.getElementById(\'' + id
16-
+ '\').style.display=\'block\';return false">ERROR</a><div id="'
17-
+ id + '" style="display:none">' + rsp.responseText + '</div>';
18-
var error = document.getElementById('error-description'); // cf. oops.jelly
19-
if (error) {
20-
var div = document.getElementById(id);
21-
while (div.firstElementChild) {
22-
div.removeChild(div.firstElementChild);
23-
}
24-
div.appendChild(error);
25-
}
26-
}
27-
Behaviour.applySubtree(elt);
28-
}
29-
30-
function validateRobotConfig() {
31-
var $btn = $(this)
32-
33-
var checkUrl = $btn.attr('data-validate-button-descriptor-url') +
34-
"/" +
35-
$btn.attr('data-validate-button-method')
36-
37-
var $robot = $btn.parents('.robot-config-container')
38-
var $msg = $robot.find('.robot-config-validate-msg')
39-
40-
var startRequest = function () {
41-
$msg.empty()
42-
}
43-
44-
var completeRequest = function (res) {
45-
applyErrorMessage($msg.get(0), res)
46-
layoutUpdateCallback.call()
47-
48-
var s = res.getResponseHeader("script")
49-
50-
try {
51-
eval(s)
52-
} catch (e) {
53-
applyErrorMessage(
54-
$msg.get(0),
55-
"failed to evaluate " +
56-
s +
57-
"\n" +
58-
e.message
59-
)
60-
}
61-
}
62-
63-
startRequest()
64-
65-
new Ajax.Request(checkUrl, {
66-
parameters: getParameters($robot),
67-
onComplete: function (res) {
68-
setTimeout(function () {
69-
completeRequest(res)
70-
}, 300)
71-
}
72-
})
73-
}
74-
75-
function getParameters($robot) {
76-
/**
77-
* 代理信息
78-
*/
79-
var $proxy = $('#proxyConfigContainer')
80-
var proxyConfig = {
81-
type: $proxy.find('select[name="type"]').val(),
82-
host: $proxy.find('input[name="host"]').val(),
83-
port: $proxy.find('input[name="port"]').val()
84-
}
85-
86-
/**
87-
* 机器人配置
88-
*/
89-
var id = $robot.find('input[name="id"]').val()
90-
var name = $robot.find('input[name="name"]').val()
91-
var webhook = $robot.find('input[name="webhook"]').val()
92-
// 安全策略
93-
var securityPolicyConfigs = $.map(
94-
$robot.find('.security-config-container'),
95-
function (t) {
96-
return {
97-
type: $(t).find('input[name=type]').val(),
98-
value: $(t).find('input[name=value]').val()
99-
}
100-
})
101-
102-
var toJSON = Array.prototype.toJSON
103-
Array.prototype.toJSON = undefined
104-
105-
var result = {
106-
id: id,
107-
name: name,
108-
webhook: webhook,
109-
securityPolicyConfigs: JSON.stringify(securityPolicyConfigs),
110-
proxy: JSON.stringify(proxyConfig)
111-
}
112-
113-
Array.prototype.toJSON = toJSON
114-
115-
return result
116-
}
2+
if (!$) {
3+
throw new Error('jQuery 插件加载失败将无法校验机器人配置,但不影响正常使用')
4+
}
5+
6+
$(function () {
7+
$(document).on('click', '.robot-config-validate-btn', validateRobotConfig)
8+
})
9+
10+
function applyErrorMessage(elt, rsp) {
11+
if (rsp.status == 200) {
12+
elt.innerHTML = rsp.responseText
13+
} else {
14+
var id = 'valerr' + (iota++)
15+
elt.innerHTML = '<a href="" onclick="document.getElementById(\'' + id
16+
+ '\').style.display=\'block\';return false">ERROR</a><div id="'
17+
+ id + '" style="display:none">' + rsp.responseText + '</div>'
18+
var error = document.getElementById('error-description') // cf. oops.jelly
19+
if (error) {
20+
var div = document.getElementById(id)
21+
while (div.firstElementChild) {
22+
div.removeChild(div.firstElementChild)
23+
}
24+
div.appendChild(error)
25+
}
26+
}
27+
Behaviour.applySubtree(elt)
28+
}
29+
30+
async function validateRobotConfig() {
31+
var $btn = $(this)
32+
33+
var checkUrl = $btn.attr('data-validate-button-descriptor-url') +
34+
'/' +
35+
$btn.attr('data-validate-button-method')
36+
37+
var $robot = $btn.parents('.robot-config-container')
38+
var $msg = $robot.find('.robot-config-validate-msg')
39+
40+
$msg.empty()
41+
42+
var url = new URL(checkUrl, window.location.origin)
43+
getParameters($robot).forEach(function (v, k) {
44+
url.searchParams.set(k, v)
45+
})
46+
47+
var res = await fetch(url, {
48+
method: 'GET'
49+
})
50+
51+
var resText = await res.text()
52+
applyErrorMessage($msg.get(0), {
53+
status: res.status,
54+
responseText: resText
55+
})
56+
}
57+
58+
function getParameters($robot) {
59+
/**
60+
* 代理信息
61+
*/
62+
var $proxy = $('#proxyConfigContainer')
63+
var proxyConfig = {
64+
type: $proxy.find('select[name="type"]').val(),
65+
host: $proxy.find('input[name="host"]').val(),
66+
port: $proxy.find('input[name="port"]').val()
67+
}
68+
69+
/**
70+
* 机器人配置
71+
*/
72+
var id = $robot.find('input[name="id"]').val()
73+
var name = $robot.find('input[name="name"]').val()
74+
var webhook = $robot.find('input[name="webhook"]').val()
75+
// 安全策略
76+
var securityPolicyConfigs = $.map(
77+
$robot.find('.security-config-container'),
78+
function (t) {
79+
return {
80+
type: $(t).find('input[name=type]').val(),
81+
value: $(t).find('input[name=value]').val()
82+
}
83+
})
84+
85+
var params = new URLSearchParams()
86+
87+
params.set('id', id)
88+
params.set('name', name)
89+
params.set('webhook', webhook)
90+
params.set('securityPolicyConfigs', JSON.stringify(securityPolicyConfigs))
91+
params.set('proxy', JSON.stringify(proxyConfig))
92+
93+
return params
94+
}
11795
})(jQuery3 || jQuery)

0 commit comments

Comments
 (0)