Skip to content

Commit c550632

Browse files
rhysdmhegazy
authored andcommitted
Add 'jenkins' module (DefinitelyTyped#14047)
* Add 'jenkins' module * jenkins: Prefer any to Object * jenkins: Remove duplicates * jenkins: Forgot adding tslint.json * jenkins: improve Function types and underlying value type of promises * jenkins: fix header and extra overloads * jenkins: Add test for promisified APIs * jenkins: Enable strict null checks
1 parent b422c43 commit c550632

File tree

4 files changed

+369
-0
lines changed

4 files changed

+369
-0
lines changed

jenkins/index.d.ts

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// Type definitions for jenkins 0.20
2+
// Project: https://github.com/silas/node-jenkins
3+
// Definitions by: rhysd <https://rhysd.github.io>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
/// <reference types="node" />
7+
8+
declare namespace create {
9+
interface JenkinsAPI {
10+
info(callback: (err: Error, data: any) => void): void;
11+
build: {
12+
get(name: string, n: number, callback: (err: Error, data: any) => void): void;
13+
log(name: string, callback: (err: Error, data: any) => void): void;
14+
log(name: string, n: number, callback: (err: Error, data: any) => void): void;
15+
log(name: string, n: number, start: number, callback: (err: Error, data: any) => void): void;
16+
log(name: string, n: number, start: number, type: 'text' | 'html', callback: (err: Error, data: any) => void): void;
17+
log(name: string, n: number, start: number, type: 'text' | 'html', meta: boolean, callback: (err: Error, data: any) => void): void;
18+
logStream(name: string, n: number, type?: 'text' | 'html', delay?: number): NodeJS.ReadableStream;
19+
stop(name: string, n: number, callback: (err: Error) => void): void;
20+
};
21+
job: {
22+
build(name: string | JobBuildOptions, callback: (err: Error, data: any) => void): void;
23+
build(name: string, parameters: any, callback: (err: Error, data: any) => void): void;
24+
build(name: string, parameters: any, token: string, callback: (err: Error, data: any) => void): void;
25+
config(name: string, callback: (err: Error, data: any) => void): void;
26+
config(name: string, xml: string, callback: (err: Error, data: any) => void): void;
27+
copy(name: string, from: string, callback: (err: Error) => void): void;
28+
create(name: string, xml: string, callback: (err: Error) => void): void;
29+
destroy(name: string, callback: (err: Error) => void): void;
30+
disable(name: string, callback: (err: Error) => void): void;
31+
enable(name: string, callback: (err: Error) => void): void;
32+
exists(name: string, callback: (err: Error, exists: boolean) => void): void;
33+
get(name: string, callback: (err: Error, data: any) => void): void;
34+
list(callback: (err: Error, data: any) => void): void;
35+
};
36+
node: {
37+
config(name: string, callback: (err: Error, data: any) => void): void;
38+
create(name: string, callback: (err: Error) => void): void;
39+
destroy(name: string, callback: (err: Error) => void): void;
40+
disconnect(name: string, callback: (err: Error) => void): void;
41+
disconnect(name: string, message: string, callback: (err: Error) => void): void;
42+
disable(name: string, callback: (err: Error) => void): void;
43+
disable(name: string, message: string, callback: (err: Error) => void): void;
44+
enable(name: string, callback: (err: Error) => void): void;
45+
exists(name: string, callback: (err: Error, data: boolean) => void): void;
46+
get(name: string, callback: (err: Error, data: any) => void): void;
47+
list(callback: (err: Error, data: any) => void): void;
48+
list(full: boolean, callback: (err: Error, data: any) => void): void;
49+
};
50+
queue: {
51+
list(callback: (err: Error, data: any) => void): void;
52+
item(n: number, callback: (err: Error, data: any) => void): void;
53+
cancel(n: number, callback: (err: Error) => void): void;
54+
};
55+
view: {
56+
config(name: string, callback: (err: Error, data: any) => void): void;
57+
config(name: string, xml: string, callback: (err: Error, data: any) => void): void;
58+
create(name: string, type: 'list' | 'my', callback: (err: Error) => void): void;
59+
destroy(name: string, callback: (err: Error) => void): void;
60+
exists(name: string, callback: (err: Error, exists: boolean) => void): void;
61+
get(name: string, callback: (err: Error, data: any) => void): void;
62+
list(callback: (err: Error, data: any) => void): void;
63+
add(name: string, job: string, callback: (err: Error) => void): void;
64+
remove(name: string, job: string, callback: (err: Error) => void): void;
65+
};
66+
}
67+
68+
export interface JenkinsPromisifiedAPI {
69+
info(): Promise<any>;
70+
build: {
71+
get(name: string, n: number): Promise<any>;
72+
log(name: string, n: number, start?: number, type?: 'text' | 'html', meta?: boolean): Promise<any>;
73+
logStream(name: string, n: number, type?: 'text' | 'html', delay?: number): Promise<any>;
74+
stop(name: string, n: number): Promise<void>;
75+
};
76+
job: {
77+
build(name: string, parameters?: any, token?: string): Promise<any>;
78+
build(opts: JobBuildOptions): Promise<any>;
79+
config(name: string, xml?: string): Promise<any>;
80+
copy(name: string, from: string): Promise<void>;
81+
create(name: string, xml: string): Promise<void>;
82+
destroy(name: string): Promise<void>;
83+
disable(name: string): Promise<void>;
84+
enable(name: string): Promise<void>;
85+
exists(name: string): Promise<boolean>;
86+
get(name: string): Promise<any>;
87+
list(): Promise<any>;
88+
};
89+
node: {
90+
config(name: string): Promise<any>;
91+
create(name: string): Promise<void>;
92+
destroy(name: string): Promise<void>;
93+
disconnect(name: string, message?: string): Promise<void>;
94+
disable(name: string, message?: string): Promise<void>;
95+
enable(name: string): Promise<void>;
96+
exists(name: string): Promise<boolean>;
97+
get(name: string): Promise<any>;
98+
list(full?: boolean): Promise<any>;
99+
};
100+
queue: {
101+
list(): Promise<any>;
102+
item(n: number): Promise<any>;
103+
cancel(n: number): Promise<void>;
104+
};
105+
view: {
106+
config(name: string, xml?: string): Promise<any>;
107+
create(name: string, type: 'list' | 'my'): Promise<void>;
108+
destroy(name: string): Promise<void>;
109+
exists(name: string): Promise<boolean>;
110+
get(name: string): Promise<any>;
111+
list(): Promise<any>;
112+
add(name: string, job: string): Promise<void>;
113+
remove(name: string, job: string): Promise<void>;
114+
};
115+
}
116+
117+
interface JobBuildOptions {
118+
name: string;
119+
parameters?: any;
120+
token?: string;
121+
}
122+
123+
interface JenkinsClientOptions {
124+
baseUrl?: string;
125+
crumbIssuer?: boolean;
126+
headers?: any;
127+
promisify?: boolean | ((...args: any[]) => any);
128+
}
129+
}
130+
131+
declare function create(opts?: {
132+
baseUrl?: string;
133+
crumbIssuer?: boolean;
134+
headers?: any;
135+
promisify?: false;
136+
}): create.JenkinsAPI;
137+
declare function create(opts: {
138+
baseUrl?: string;
139+
crumbIssuer?: boolean;
140+
headers?: any;
141+
promisify: true;
142+
}): create.JenkinsPromisifiedAPI;
143+
export = create;

jenkins/jenkins-tests.ts

+205
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
import * as J from 'jenkins';
2+
3+
const jenkins = J({ baseUrl: 'http://user:pass@localhost:8080', crumbIssuer: true });
4+
5+
jenkins.info(function(err, data) {
6+
if (err) throw err;
7+
8+
console.log('info', data);
9+
});
10+
11+
jenkins.build.get('example', 1, function(err, data) {
12+
if (err) throw err;
13+
14+
console.log('build', data);
15+
});
16+
17+
jenkins.build.log('example', 1, function(err, data) {
18+
if (err) throw err;
19+
20+
console.log('log', data);
21+
});
22+
23+
var log = jenkins.build.logStream('example', 1);
24+
25+
log.on('data', function(text: string) {
26+
process.stdout.write(text);
27+
});
28+
29+
log.on('error', function(err: Error) {
30+
console.log('error', err);
31+
});
32+
33+
log.on('end', function() {
34+
console.log('end');
35+
});
36+
37+
jenkins.build.stop('example', 1, function(err) {
38+
if (err) throw err;
39+
});
40+
41+
jenkins.job.build('example', function(err, data) {
42+
if (err) throw err;
43+
44+
console.log('queue item number', data);
45+
});
46+
47+
jenkins.job.build({ name: 'example', parameters: { name: 'value' } }, function(err) {
48+
if (err) throw err;
49+
});
50+
51+
jenkins.job.config('example', function(err, data) {
52+
if (err) throw err;
53+
54+
console.log('xml', data);
55+
});
56+
57+
jenkins.job.config('example', '<xml></xml>', function(err) {
58+
if (err) throw err;
59+
});
60+
61+
jenkins.job.copy('fromJob', 'example', function(err) {
62+
if (err) throw err;
63+
});
64+
65+
jenkins.job.create('example', '<xml></xml>', function(err) {
66+
if (err) throw err;
67+
});
68+
69+
jenkins.job.destroy('example', function(err) {
70+
if (err) throw err;
71+
});
72+
73+
jenkins.job.disable('example', function(err) {
74+
if (err) throw err;
75+
});
76+
77+
jenkins.job.enable('example', function(err) {
78+
if (err) throw err;
79+
});
80+
81+
jenkins.job.exists('example', function(err, exists) {
82+
if (err) throw err;
83+
84+
console.log('exists', exists);
85+
});
86+
87+
jenkins.job.get('example', function(err, data) {
88+
if (err) throw err;
89+
90+
console.log('job', data);
91+
});
92+
93+
jenkins.job.list(function(err, data) {
94+
if (err) throw err;
95+
96+
console.log('jobs', data);
97+
});
98+
99+
jenkins.node.config('example', function(err, data) {
100+
if (err) throw err;
101+
102+
console.log('xml', data);
103+
});
104+
105+
jenkins.node.create('slave', function(err) {
106+
if (err) throw err;
107+
});
108+
109+
jenkins.node.destroy('slave', function(err) {
110+
if (err) throw err;
111+
});
112+
113+
jenkins.node.disconnect('slave', 'no longer used', function(err) {
114+
if (err) throw err;
115+
});
116+
117+
jenkins.node.disable('slave', 'network failure', function(err) {
118+
if (err) throw err;
119+
});
120+
121+
jenkins.node.enable('slave', function(err) {
122+
if (err) throw err;
123+
});
124+
125+
jenkins.node.exists('slave', function(err, exists) {
126+
if (err) throw err;
127+
128+
console.log('exists', exists);
129+
});
130+
131+
jenkins.node.get('slave', function(err, data) {
132+
if (err) throw err;
133+
134+
console.log('node', data);
135+
});
136+
137+
jenkins.node.list(function(err, data) {
138+
if (err) throw err;
139+
140+
console.log('nodes', data);
141+
});
142+
143+
jenkins.queue.list(function(err, data) {
144+
if (err) throw err;
145+
146+
console.log('queues', data);
147+
});
148+
149+
jenkins.queue.item(130, function(err, data) {
150+
if (err) throw err;
151+
152+
console.log('item', data);
153+
});
154+
155+
jenkins.queue.cancel(23, function(err) {
156+
if (err) throw err;
157+
});
158+
159+
jenkins.view.config('example', function(err, data) {
160+
if (err) throw err;
161+
162+
console.log('xml', data);
163+
});
164+
165+
jenkins.view.config('example', '<xml></xml>', function(err) {
166+
if (err) throw err;
167+
});
168+
169+
jenkins.view.create('example', 'list', function(err) {
170+
if (err) throw err;
171+
});
172+
173+
jenkins.view.destroy('example', function(err) {
174+
if (err) throw err;
175+
});
176+
177+
jenkins.view.exists('example', function(err, exists) {
178+
if (err) throw err;
179+
180+
console.log('exists', exists);
181+
});
182+
183+
jenkins.view.get('example', function(err, data) {
184+
if (err) throw err;
185+
186+
console.log('view', data);
187+
});
188+
189+
jenkins.view.list(function(err, data) {
190+
if (err) throw err;
191+
192+
console.log('views', data);
193+
});
194+
195+
jenkins.view.add('example', 'jobExample', function(err) {
196+
if (err) throw err;
197+
});
198+
199+
jenkins.view.remove('example', 'jobExample', function(err) {
200+
if (err) throw err;
201+
});
202+
203+
const jenkins2 = J({ baseUrl: 'http://user:pass@localhost:8080', crumbIssuer: true, promisify: true });
204+
jenkins2.info().then(info => console.log(info));
205+
jenkins2.job.exists('example').then(exists => { var b: boolean = exists; });

jenkins/tsconfig.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"noImplicitAny": true,
6+
"noImplicitThis": true,
7+
"strictNullChecks": true,
8+
"baseUrl": "../",
9+
"typeRoots": [
10+
"../"
11+
],
12+
"types": [],
13+
"noEmit": true,
14+
"forceConsistentCasingInFileNames": true
15+
},
16+
"files": [
17+
"index.d.ts",
18+
"jenkins-tests.ts"
19+
]
20+
}

jenkins/tslint.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "../tslint.json" }

0 commit comments

Comments
 (0)