-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (39 loc) · 1013 Bytes
/
index.js
File metadata and controls
41 lines (39 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const ViewAPI = require('./src/ViewAPI');
const JobAPI = require('./src/JobAPI');
const BuildAPI = require('./src/BuildAPI');
const PluginAPI = require('./src/PluginAPI');
const QueueAPI = require('./src/QueueAPI');
const { asyncRequest } = require('./src/utils');
class JenkinsAPI {
constructor(origin, authorization = {}) {
this.origin = origin;
this.authorization = authorization;
this.jobAPI = new JobAPI();
this.viewAPI = new ViewAPI();
this.buildAPI = new BuildAPI();
this.pluginAPI = new PluginAPI();
this.queueAPI = new QueueAPI();
}
list() {
return {
path: '/api/json'
}
}
async request(info) {
info.url = `${this.origin}${info.path}`;
info.auth = this.authorization;
delete info.path;
let res = null;
try {
res = await asyncRequest(info);
} catch (e) {
// TCP链接失败等错误、404等
res = {
status: 'failed',
message: e
}
}
return res
}
}
module.exports = JenkinsAPI;