zentao-api 0.1.0 → 0.2.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +221 -131
- package/dist/browser/zentao-api.global.js +2 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +1 -0
- package/dist/client/index.d.ts +39 -0
- package/dist/client/index.js +172 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +7 -8
- package/dist/misc/browser-global.d.ts +1 -0
- package/dist/misc/browser-global.js +8 -0
- package/dist/misc/environment.d.ts +8 -0
- package/dist/misc/environment.js +124 -0
- package/dist/misc/errors.d.ts +30 -0
- package/dist/misc/errors.js +40 -0
- package/dist/misc/global-options.d.ts +5 -0
- package/dist/misc/global-options.js +9 -0
- package/dist/modules/generated.d.ts +8 -0
- package/dist/modules/generated.js +4226 -0
- package/dist/modules/registry.d.ts +22 -0
- package/dist/modules/registry.js +142 -0
- package/dist/modules/resolve.d.ts +7 -0
- package/dist/modules/resolve.js +206 -0
- package/dist/profiles/index.d.ts +14 -0
- package/dist/profiles/index.js +205 -0
- package/dist/request/index.d.ts +7 -0
- package/dist/request/index.js +65 -0
- package/dist/types/index.d.ts +296 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +26 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +4 -0
- package/package.json +52 -76
- package/dist/types.d.ts +0 -70
- package/dist/utils.d.ts +0 -93
- package/dist/zentao-api.cjs.development.js +0 -3619
- package/dist/zentao-api.cjs.development.js.map +0 -1
- package/dist/zentao-api.cjs.production.min.js +0 -2
- package/dist/zentao-api.cjs.production.min.js.map +0 -1
- package/dist/zentao-api.esm.js +0 -3611
- package/dist/zentao-api.esm.js.map +0 -1
- package/dist/zentao-config.d.ts +0 -93
- package/dist/zentao-request-builder.d.ts +0 -120
- package/dist/zentao.d.ts +0 -175
- package/dist/zentao12.d.ts +0 -676
- package/src/index.ts +0 -5
- package/src/types.ts +0 -88
- package/src/utils.ts +0 -216
- package/src/zentao-config.ts +0 -150
- package/src/zentao-request-builder.ts +0 -227
- package/src/zentao.ts +0 -596
- package/src/zentao12.ts +0 -1272
package/src/zentao12.ts
DELETED
|
@@ -1,1272 +0,0 @@
|
|
|
1
|
-
import md5 from 'md5';
|
|
2
|
-
import {ZentaoApiResult} from './types';
|
|
3
|
-
import {formatDate} from './utils';
|
|
4
|
-
import Zentao from './zentao';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 禅道 API 请求类
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```js
|
|
11
|
-
* import {ZentaoApi} from 'zentao-api';
|
|
12
|
-
* const zentao = new ZentaoApi({
|
|
13
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
14
|
-
* });
|
|
15
|
-
* // TODO: 使用 zentao 调用其他 API
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export default class ZentaoApi extends Zentao {
|
|
19
|
-
/**
|
|
20
|
-
* 调用指定名称的 API
|
|
21
|
-
* @param apiName API 名称
|
|
22
|
-
* @param params 请求参数
|
|
23
|
-
* @returns 调用结果
|
|
24
|
-
* @example
|
|
25
|
-
* ```js
|
|
26
|
-
* import {ZentaoApi} from 'zentao-api';
|
|
27
|
-
* const zentao = new ZentaoApi({
|
|
28
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* const res = await zentao.call('getProductList', {status: 'noclosed'});
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
call(
|
|
35
|
-
apiName: Exclude<keyof ZentaoApi, 'call' | keyof Zentao>,
|
|
36
|
-
params?: Record<string, any>
|
|
37
|
-
): Promise<ZentaoApiResult> {
|
|
38
|
-
const func = this[apiName] as (
|
|
39
|
-
params?: Record<string, any>
|
|
40
|
-
) => Promise<ZentaoApiResult>;
|
|
41
|
-
if (!func || typeof func !== 'function') {
|
|
42
|
-
throw new Error(`Api method named "${apiName}" undefined.`);
|
|
43
|
-
}
|
|
44
|
-
return func.call(this, params);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 获取当前已添加部门列表数据
|
|
49
|
-
*
|
|
50
|
-
* @param {{deptID?: number, extraFields?: string[]}} [params] 请求参数,`params.deptID` 用于指定部门ID,`params.extraFields` 指定额外要返回的字段
|
|
51
|
-
* @returns 请求结果
|
|
52
|
-
* @example
|
|
53
|
-
* ```js
|
|
54
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
55
|
-
* const zentao = new ZentaoApi({
|
|
56
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
57
|
-
* });
|
|
58
|
-
* const result = await zentao.getDeptList({deptID: 1, extraFields: 'sons'});
|
|
59
|
-
* if (result.status) {
|
|
60
|
-
* console.log('当前部门的直属下级部门列表', result.result.sons);
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
getDeptList(params?: {
|
|
65
|
-
deptID?: number;
|
|
66
|
-
extraFields?: string[];
|
|
67
|
-
}): Promise<ZentaoApiResult> {
|
|
68
|
-
return this.module('dept', 'browse')
|
|
69
|
-
.withParams([['deptID', params?.deptID ?? 0]])
|
|
70
|
-
.filterFields(
|
|
71
|
-
'title',
|
|
72
|
-
'deptID',
|
|
73
|
-
'parentDepts',
|
|
74
|
-
'sons',
|
|
75
|
-
'tree',
|
|
76
|
-
params?.extraFields
|
|
77
|
-
)
|
|
78
|
-
.get();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 批量添加部门
|
|
83
|
-
*
|
|
84
|
-
* @param params 请求参数,其中 `params.parentDeptID` 为所属上级部门ID,`params.depts` 为新增部门名称列表
|
|
85
|
-
* @returns 请求结果
|
|
86
|
-
* @example
|
|
87
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
88
|
-
* const zentao = new ZentaoApi({
|
|
89
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
90
|
-
* });
|
|
91
|
-
*
|
|
92
|
-
* // 在部门 ID 为 3 的部门下添加两个子部门:开发部、测试部
|
|
93
|
-
* const result = await zentao.addDept({parentDeptID: 3, depts: ['开发部', '测试部']});
|
|
94
|
-
* if (result.status) {
|
|
95
|
-
* console.log('部门添加成功');
|
|
96
|
-
* }
|
|
97
|
-
*/
|
|
98
|
-
async addDept(params: {
|
|
99
|
-
parentDeptID?: number;
|
|
100
|
-
depts: string[];
|
|
101
|
-
}): Promise<ZentaoApiResult> {
|
|
102
|
-
const res = await this.request('dept', 'manageChild', {
|
|
103
|
-
name: 'addDept',
|
|
104
|
-
method: 'POST',
|
|
105
|
-
data: {parentDeptID: params.parentDeptID ?? 0, depts: params.depts},
|
|
106
|
-
resultConvertor: (_remoteData, result) => {
|
|
107
|
-
if (!result.status && result.result.includes('reload')) {
|
|
108
|
-
result.status = 1;
|
|
109
|
-
result.msg = 'success';
|
|
110
|
-
result.result = null;
|
|
111
|
-
}
|
|
112
|
-
return result;
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
return res;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* 获取用户列表,可以指定用户所属部门
|
|
120
|
-
*
|
|
121
|
-
* @param {{deptID?: number, orderBy?: string, recTotal?: number, recPerPage?: number, pageID?: number, extraFields?: string[]}} [params] 请求参数,`params.deptID` 用于指定部门ID(如果不指定则获取所有用户数据),`params.extraFields` 指定额外要返回的字段,其他字段指定分页信息
|
|
122
|
-
* @returns 请求结果
|
|
123
|
-
* @example
|
|
124
|
-
* ```js
|
|
125
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
126
|
-
* const zentao = new ZentaoApi({
|
|
127
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
128
|
-
* });
|
|
129
|
-
* const result = await zentao.getUserList({deptID: 1});
|
|
130
|
-
* if (result.status) {
|
|
131
|
-
* console.log('当前部门的用户列表数据为', result.result.users);
|
|
132
|
-
* }
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
async getUserList(params?: {
|
|
136
|
-
deptID?: number;
|
|
137
|
-
orderBy?: string;
|
|
138
|
-
recTotal?: number;
|
|
139
|
-
recPerPage?: number;
|
|
140
|
-
pageID?: number;
|
|
141
|
-
extraFields?: string[];
|
|
142
|
-
}): Promise<ZentaoApiResult> {
|
|
143
|
-
const res = await this.request('company', 'browse', {
|
|
144
|
-
name: 'getUserList',
|
|
145
|
-
params: [
|
|
146
|
-
['param', params?.deptID ?? 0],
|
|
147
|
-
['type', 'bydept'],
|
|
148
|
-
['orderBy', params?.orderBy ?? 'id'],
|
|
149
|
-
['recTotal', params?.recTotal ?? 0],
|
|
150
|
-
['recPerPage', params?.recPerPage ?? 20],
|
|
151
|
-
['pageID', params?.pageID ?? 1],
|
|
152
|
-
],
|
|
153
|
-
fields: ['title', 'users', ...(params?.extraFields ?? [])],
|
|
154
|
-
});
|
|
155
|
-
return res;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* 添加用户时如果需要为新用 户分配部门、职位、权限,请求该方法即可返回相关可用数据
|
|
160
|
-
*
|
|
161
|
-
* @param {{extraFields?: string[]}} [params] 请求参数,`params.extraFields` 指定额外要返回的字段
|
|
162
|
-
* @returns 请求结果
|
|
163
|
-
* @example
|
|
164
|
-
* ```js
|
|
165
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
166
|
-
* const zentao = new ZentaoApi({
|
|
167
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
168
|
-
* });
|
|
169
|
-
* const result = await zentao.getUserCreateParams();
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
async getUserCreateParams(params?: {
|
|
173
|
-
extraFields?: string[];
|
|
174
|
-
}): Promise<ZentaoApiResult> {
|
|
175
|
-
const res = await this.request('user', 'create', {
|
|
176
|
-
name: 'getUserCreateParams',
|
|
177
|
-
fields: [
|
|
178
|
-
'title',
|
|
179
|
-
'depts',
|
|
180
|
-
'groupList',
|
|
181
|
-
'roleGroup',
|
|
182
|
-
...(params?.extraFields ?? []),
|
|
183
|
-
],
|
|
184
|
-
});
|
|
185
|
-
return res;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* 向系统添加一个用户
|
|
190
|
-
* @param params 用户信息参数
|
|
191
|
-
* @returns
|
|
192
|
-
* @example
|
|
193
|
-
* ```js
|
|
194
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
195
|
-
* const zentao = new ZentaoApi({
|
|
196
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
197
|
-
* });
|
|
198
|
-
* const result = await zentao.addUser({
|
|
199
|
-
* account: 'Jack10', // 必填参数 用户名
|
|
200
|
-
* password: '123456', // 必填参数 密码
|
|
201
|
-
* realname: 'Jack10', // 必填参数 真实姓名
|
|
202
|
-
* dept: 1, // 选填参数 所属部门【部门ID】
|
|
203
|
-
* join: '2019-11-11', // 选填参数 入职日期【格式:2019-11-19】
|
|
204
|
-
* role: 'dev', // 选填参数 职位【权限标识,例如:'dev','qd'】
|
|
205
|
-
* group: 2, // 选填参数 权限分组【分组ID】
|
|
206
|
-
* email: 'jack@gmail.com', // 选填参数 邮箱
|
|
207
|
-
* commiter: 'Jack10', // 选填参数 源代码账号
|
|
208
|
-
* gender: 'm', // 选填参数 性别【m:男|f:女】
|
|
209
|
-
* });
|
|
210
|
-
* if (result.status) {
|
|
211
|
-
* console.log('用户创建成功');
|
|
212
|
-
* }
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
async addUser(params: {
|
|
216
|
-
account: string;
|
|
217
|
-
password: string;
|
|
218
|
-
realname: string;
|
|
219
|
-
dept?: number;
|
|
220
|
-
join?: string;
|
|
221
|
-
role?: string;
|
|
222
|
-
group?: number;
|
|
223
|
-
email?: string;
|
|
224
|
-
commiter?: string;
|
|
225
|
-
gender?: 'm' | 'f';
|
|
226
|
-
}): Promise<ZentaoApiResult> {
|
|
227
|
-
// Get the random number required for encryption.
|
|
228
|
-
const paramsRes = await this.getUserCreateParams({
|
|
229
|
-
extraFields: ['rand'],
|
|
230
|
-
});
|
|
231
|
-
const rand = paramsRes.result.rand;
|
|
232
|
-
|
|
233
|
-
const password = md5(`${params.password}${rand}`);
|
|
234
|
-
const data: Record<string, any> = {
|
|
235
|
-
dept: params.dept ?? 0,
|
|
236
|
-
account: params.account,
|
|
237
|
-
password1: password,
|
|
238
|
-
password2: password,
|
|
239
|
-
realname: params.realname,
|
|
240
|
-
join: params.join,
|
|
241
|
-
role: params.role,
|
|
242
|
-
group: params.group,
|
|
243
|
-
email: params.email,
|
|
244
|
-
commiter: params.commiter,
|
|
245
|
-
passwordStrength: 1,
|
|
246
|
-
verifyPassword: md5(`${md5(this.password)}${rand}`),
|
|
247
|
-
};
|
|
248
|
-
if (params.gender) {
|
|
249
|
-
data.gender = params.gender;
|
|
250
|
-
}
|
|
251
|
-
const res = await this.request('user', 'create', {
|
|
252
|
-
name: 'addUser',
|
|
253
|
-
method: 'POST',
|
|
254
|
-
data,
|
|
255
|
-
resultConvertor: (_remoteData, result) => {
|
|
256
|
-
if (!result.status && result.result.includes('reload')) {
|
|
257
|
-
result.status = 1;
|
|
258
|
-
result.msg = 'success';
|
|
259
|
-
result.result = null;
|
|
260
|
-
}
|
|
261
|
-
return result;
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
return res;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* 获取产品列表
|
|
269
|
-
* @param {{productID?: number, line?: number, status?: 'noclosed'|'closed'|'involved'|'all', orderBy?: string, recTotal?: number, recPerPage?: number, pageID?: number, extraFields?: string[]}} [params] 请求参数,`params.productID` 用于指定所属产品,`params.status` 用于指定产品状态,`params.extraFields` 指定额外要返回的字段,其他字段指定分页信息
|
|
270
|
-
* @returns 请求结果
|
|
271
|
-
* @example
|
|
272
|
-
* ```js
|
|
273
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
274
|
-
* const zentao = new ZentaoApi({
|
|
275
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
276
|
-
* });
|
|
277
|
-
* const result = await zentao.getProductList({status: 'noclosed'});
|
|
278
|
-
* if (result.status) {
|
|
279
|
-
* console.log('产品列表', result.result.products);
|
|
280
|
-
* }
|
|
281
|
-
* ```
|
|
282
|
-
*/
|
|
283
|
-
async getProductList(params?: {
|
|
284
|
-
productID?: number;
|
|
285
|
-
line?: number;
|
|
286
|
-
status?: 'noclosed' | 'closed' | 'involved' | 'all';
|
|
287
|
-
orderBy?: string;
|
|
288
|
-
recTotal?: number;
|
|
289
|
-
recPerPage?: number;
|
|
290
|
-
pageID?: number;
|
|
291
|
-
extraFields?: string[];
|
|
292
|
-
}): Promise<ZentaoApiResult> {
|
|
293
|
-
const res = await this.request('product', 'all', {
|
|
294
|
-
name: 'getProductList',
|
|
295
|
-
params: [
|
|
296
|
-
['productID', params?.productID ?? 0],
|
|
297
|
-
['line', params?.line ?? 0],
|
|
298
|
-
['status', params?.status ?? 'noclosed'],
|
|
299
|
-
['orderBy', params?.orderBy ?? 'order_desc'],
|
|
300
|
-
['recTotal', params?.recTotal ?? 0],
|
|
301
|
-
['recPerPage', params?.recPerPage ?? 10],
|
|
302
|
-
['pageID', params?.pageID ?? 1],
|
|
303
|
-
],
|
|
304
|
-
fields: [
|
|
305
|
-
'title',
|
|
306
|
-
'products',
|
|
307
|
-
'productStats',
|
|
308
|
-
...(params?.extraFields ?? []),
|
|
309
|
-
],
|
|
310
|
-
});
|
|
311
|
-
return res;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* 获取指定的产品信息
|
|
316
|
-
* @param {{productID: number, extraFields?: string[]}} [params] 请求参数,`params.productID` 用于指定产品 ID,params.extraFields` 指定额外要返回的字段,其他字段指定分页信息
|
|
317
|
-
* @returns 请求结果
|
|
318
|
-
* @example
|
|
319
|
-
* ```js
|
|
320
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
321
|
-
* const zentao = new ZentaoApi({
|
|
322
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
323
|
-
* });
|
|
324
|
-
* const result = await zentao.getProduct({productID: 1});
|
|
325
|
-
* if (result.status) {
|
|
326
|
-
* console.log('产品信息为', result.result.product);
|
|
327
|
-
* }
|
|
328
|
-
* ```
|
|
329
|
-
*/
|
|
330
|
-
async getProduct(params: {
|
|
331
|
-
productID: number;
|
|
332
|
-
extraFields?: string[];
|
|
333
|
-
}): Promise<ZentaoApiResult> {
|
|
334
|
-
const res = await this.request('product', 'view', {
|
|
335
|
-
name: 'getProduct',
|
|
336
|
-
params: [['productID', params.productID]],
|
|
337
|
-
fields: [
|
|
338
|
-
'title',
|
|
339
|
-
'products',
|
|
340
|
-
'product',
|
|
341
|
-
'branches',
|
|
342
|
-
'dynamics',
|
|
343
|
-
...(params?.extraFields ?? []),
|
|
344
|
-
],
|
|
345
|
-
});
|
|
346
|
-
return res;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* 获取添加产品时所需要一些数据,例如产品线数据列表、产品负责人数据列表等数据,添加产品时,可以为其绑定这些信息
|
|
351
|
-
*
|
|
352
|
-
* @param {{extraFields?: string[]}} [params] 请求参数,`params.extraFields` 指定额外要返回的字段
|
|
353
|
-
* @returns 请求结果
|
|
354
|
-
* @example
|
|
355
|
-
* ```js
|
|
356
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
357
|
-
* const zentao = new ZentaoApi({
|
|
358
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
359
|
-
* });
|
|
360
|
-
* const result = await zentao.getProductCreateParams();
|
|
361
|
-
* ```
|
|
362
|
-
*/
|
|
363
|
-
async getProductCreateParams(params?: {
|
|
364
|
-
extraFields?: string[];
|
|
365
|
-
}): Promise<ZentaoApiResult> {
|
|
366
|
-
const res = await this.request('product', 'create', {
|
|
367
|
-
name: 'getProductCreateParams',
|
|
368
|
-
fields: [
|
|
369
|
-
'title',
|
|
370
|
-
'products',
|
|
371
|
-
'lines',
|
|
372
|
-
'poUsers',
|
|
373
|
-
'qdUsers',
|
|
374
|
-
'rdUsers',
|
|
375
|
-
'groups',
|
|
376
|
-
...(params?.extraFields ?? []),
|
|
377
|
-
],
|
|
378
|
-
});
|
|
379
|
-
return res;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* 向系统添加一个产品,添加新产品时可以指定相关负责人,设置产品类型和访问权限。注意:假如参数 acl = custom ,可以额外传递参数,例如: 'whitelist' => array(1, 2) ,添加白名单为权限分组列表中 ID
|
|
384
|
-
* @param params 产品信息参数
|
|
385
|
-
* @returns
|
|
386
|
-
* @example
|
|
387
|
-
* ```js
|
|
388
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
389
|
-
* const zentao = new ZentaoApi({
|
|
390
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
391
|
-
* });
|
|
392
|
-
* const result = await zentao.addProduct({
|
|
393
|
-
* name: '登月行动', // 必填参数 产品名称
|
|
394
|
-
* code: 'to_the_moon', // 必填参数 产品代号
|
|
395
|
-
* line: 0, // 选填参数 产品线ID
|
|
396
|
-
* PO: 'admin', // 选填参数 产品负责人账号
|
|
397
|
-
* QD: 'jim', // 选填参数 测试负责人账号
|
|
398
|
-
* RD: 'lilei', // 选填参数 发布负责人账号
|
|
399
|
-
* type: normal', // 选填参数 产品类型【normal正常|branch多分支|platform多平台】
|
|
400
|
-
* desc: '登月行动,刻不容缓', // 选填参数 产品描述
|
|
401
|
-
* acl: 'custom', // 选填参数 访问控制【open默认|private私有|custom白名单】
|
|
402
|
-
* whitelist: [], // 选填参数 白名单,权限分组列表中 ID
|
|
403
|
-
* });
|
|
404
|
-
* if (result.status) {
|
|
405
|
-
* console.log('产品创建成功');
|
|
406
|
-
* }
|
|
407
|
-
* ```
|
|
408
|
-
*/
|
|
409
|
-
async addProduct(params: {
|
|
410
|
-
name: string;
|
|
411
|
-
code: string;
|
|
412
|
-
line?: number;
|
|
413
|
-
PO?: string;
|
|
414
|
-
QD?: string;
|
|
415
|
-
RD?: string;
|
|
416
|
-
type?: 'normal' | 'branch' | 'platform';
|
|
417
|
-
desc?: string;
|
|
418
|
-
acl?: 'open' | 'custom' | 'private';
|
|
419
|
-
whitelist?: number[];
|
|
420
|
-
}): Promise<ZentaoApiResult> {
|
|
421
|
-
const res = await this.request('product', 'create', {
|
|
422
|
-
name: 'addProduct',
|
|
423
|
-
method: 'POST',
|
|
424
|
-
data: {
|
|
425
|
-
name: params.name,
|
|
426
|
-
code: params.code,
|
|
427
|
-
line: params.line ?? 0,
|
|
428
|
-
PO: params.PO,
|
|
429
|
-
QD: params.QD,
|
|
430
|
-
RD: params.RD,
|
|
431
|
-
type: params.type ?? 'normal',
|
|
432
|
-
desc: params.desc,
|
|
433
|
-
acl: params.acl ?? 'open',
|
|
434
|
-
whitelist: params.whitelist,
|
|
435
|
-
},
|
|
436
|
-
});
|
|
437
|
-
return res;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* 获取项目列表
|
|
442
|
-
* @param {{status?: 'undone'|'wait'|'doing'|'suspended'|'closed'|'all', projectID?: number, orderBy?: string, productID?: number, recTotal?: number, recPerPage?: number, pageID?: number, extraFields?: string[]}} [params] 请求参数,`params.productID` 用于指定所属产品,`params.status` 用于指定项目状态,`params.extraFields` 指定额外要返回的字段,其他字段指定分页信息
|
|
443
|
-
* @returns 请求结果
|
|
444
|
-
* @example
|
|
445
|
-
* ```js
|
|
446
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
447
|
-
* const zentao = new ZentaoApi({
|
|
448
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
449
|
-
* });
|
|
450
|
-
* const result = await zentao.getProjectList({status: 'undone'});
|
|
451
|
-
* if (result.status) {
|
|
452
|
-
* console.log('项目列表', result.result.products);
|
|
453
|
-
* }
|
|
454
|
-
* ```
|
|
455
|
-
*/
|
|
456
|
-
async getProjectList(params?: {
|
|
457
|
-
status?: 'undone' | 'wait' | 'doing' | 'suspended' | 'closed' | 'all';
|
|
458
|
-
projectID?: number;
|
|
459
|
-
orderBy?: string;
|
|
460
|
-
productID?: number;
|
|
461
|
-
recTotal?: number;
|
|
462
|
-
recPerPage?: number;
|
|
463
|
-
pageID?: number;
|
|
464
|
-
extraFields?: string[];
|
|
465
|
-
}): Promise<ZentaoApiResult> {
|
|
466
|
-
const res = await this.request('project', 'all', {
|
|
467
|
-
name: 'getProjectList',
|
|
468
|
-
params: [
|
|
469
|
-
['status', params?.status ?? 'undone'],
|
|
470
|
-
['projectID', params?.projectID ?? 0],
|
|
471
|
-
['orderBy', params?.orderBy ?? 'order_desc'],
|
|
472
|
-
['productID', params?.productID ?? 0],
|
|
473
|
-
['recTotal', params?.recTotal ?? 0],
|
|
474
|
-
['recPerPage', params?.recPerPage ?? 10],
|
|
475
|
-
['pageID', params?.pageID ?? 1],
|
|
476
|
-
],
|
|
477
|
-
fields: [
|
|
478
|
-
'title',
|
|
479
|
-
'projects',
|
|
480
|
-
'projectStats',
|
|
481
|
-
'teamMembers',
|
|
482
|
-
'users',
|
|
483
|
-
...(params?.extraFields ?? []),
|
|
484
|
-
],
|
|
485
|
-
});
|
|
486
|
-
return res;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* 获取指定的项目信息
|
|
491
|
-
* @param {{projectID: number, extraFields?: string[]}} [params] 请求参数,`params.projectID` 用于指定项目 ID,params.extraFields` 指定额外要返回的字段,其他字段指定分页信息
|
|
492
|
-
* @returns 请求结果
|
|
493
|
-
* @example
|
|
494
|
-
* ```js
|
|
495
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
496
|
-
* const zentao = new ZentaoApi({
|
|
497
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
498
|
-
* });
|
|
499
|
-
* const result = await zentao.getProject({projectID: 1});
|
|
500
|
-
* if (result.status) {
|
|
501
|
-
* console.log('项目信息为', result.result.project);
|
|
502
|
-
* }
|
|
503
|
-
* ```
|
|
504
|
-
*/
|
|
505
|
-
async getProject(params: {
|
|
506
|
-
projectID: number;
|
|
507
|
-
extraFields?: string[];
|
|
508
|
-
}): Promise<ZentaoApiResult> {
|
|
509
|
-
const res = await this.request('product', 'view', {
|
|
510
|
-
name: 'getProduct',
|
|
511
|
-
params: [['projectID', params.projectID]],
|
|
512
|
-
fields: [
|
|
513
|
-
'title',
|
|
514
|
-
'products',
|
|
515
|
-
'project',
|
|
516
|
-
'teamMembers',
|
|
517
|
-
'dynamics',
|
|
518
|
-
...(params?.extraFields ?? []),
|
|
519
|
-
],
|
|
520
|
-
});
|
|
521
|
-
return res;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* 获取添加项目时所需要一些数据,例如获取正常状态产品列表信息,用于添加项目时为其绑定产品,从而用于项目与产品需求关联。还可获取权限分组列表,用于项目绑定访问控制权限
|
|
526
|
-
*
|
|
527
|
-
* @param {{extraFields?: string[]}} [params] 请求参数,`params.extraFields` 指定额外要返回的字段
|
|
528
|
-
* @returns 请求结果
|
|
529
|
-
* @example
|
|
530
|
-
* ```js
|
|
531
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
532
|
-
* const zentao = new ZentaoApi({
|
|
533
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
534
|
-
* });
|
|
535
|
-
* const result = await zentao.getProjectCreateParams();
|
|
536
|
-
* ```
|
|
537
|
-
*/
|
|
538
|
-
async getProjectCreateParams(params?: {
|
|
539
|
-
extraFields?: string[];
|
|
540
|
-
}): Promise<ZentaoApiResult> {
|
|
541
|
-
const res = await this.request('project', 'create', {
|
|
542
|
-
name: 'getProjectCreateParams',
|
|
543
|
-
fields: [
|
|
544
|
-
'title',
|
|
545
|
-
'projects',
|
|
546
|
-
'groups',
|
|
547
|
-
'allProducts',
|
|
548
|
-
...(params?.extraFields ?? []),
|
|
549
|
-
],
|
|
550
|
-
});
|
|
551
|
-
return res;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* 向系统添加一个项目,添加新项目时可以指定相关负责人,设置产品类型和访问权限
|
|
556
|
-
* @param params 项目信息参数
|
|
557
|
-
* @returns
|
|
558
|
-
* @example
|
|
559
|
-
* ```js
|
|
560
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
561
|
-
* const zentao = new ZentaoApi({
|
|
562
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
563
|
-
* });
|
|
564
|
-
* const result = await zentao.addProject({
|
|
565
|
-
* name: '禅道项目管理开发', // 必填参数 项目名称
|
|
566
|
-
* code: 'zentao', // 必填参数 项目代号
|
|
567
|
-
* begin: '2020-01-01', // 必填参数 起始日期【时间格式:2019-11-20】
|
|
568
|
-
* end: '2020-06-06', // 必填参数 结束日期【时间格式:2019-11-20】
|
|
569
|
-
* days: '100', // 选填参数 可用工作日
|
|
570
|
-
* team: '禅道开发团队', // 选填参数 团队名称
|
|
571
|
-
* type: 'sprint', // 选填参数 项目类型【sprint短期项目|waterfall长期项目|ops运维项目】
|
|
572
|
-
* desc: '专业的研发项目管理软件。', // 选填参数 项目描述
|
|
573
|
-
* acl: 'custom', // 选填参数 访问控制【open默认设置|private私有项目|custom白名单】
|
|
574
|
-
* whitelist: [1, 2], // 选填参数 白名单中的权限分组 ID
|
|
575
|
-
* products: [4, 5], // 选填参数 关联产品 ID
|
|
576
|
-
* plans: [5, 6] // 选填参数 关联产品 ID 所属计划 ID
|
|
577
|
-
* });
|
|
578
|
-
* if (result.status) {
|
|
579
|
-
* console.log('项目创建成功');
|
|
580
|
-
* }
|
|
581
|
-
* ```
|
|
582
|
-
*/
|
|
583
|
-
async addProject(params: {
|
|
584
|
-
name: string;
|
|
585
|
-
code: string;
|
|
586
|
-
begin: string;
|
|
587
|
-
end: string;
|
|
588
|
-
days?: number;
|
|
589
|
-
team?: string;
|
|
590
|
-
type?: 'sprint' | 'waterfall' | 'ops';
|
|
591
|
-
desc?: string;
|
|
592
|
-
acl?: 'open' | 'custom' | 'private';
|
|
593
|
-
whitelist?: number[];
|
|
594
|
-
products?: number[];
|
|
595
|
-
plans?: number[];
|
|
596
|
-
}): Promise<ZentaoApiResult> {
|
|
597
|
-
const res = await this.request('project', 'create', {
|
|
598
|
-
name: 'addProject',
|
|
599
|
-
method: 'POST',
|
|
600
|
-
data: {
|
|
601
|
-
name: params.name,
|
|
602
|
-
code: params.code,
|
|
603
|
-
begin: params.begin,
|
|
604
|
-
end: params.end,
|
|
605
|
-
days: params.days ?? 0,
|
|
606
|
-
team: params.team,
|
|
607
|
-
type: params.type ?? 'sprint',
|
|
608
|
-
desc: params.desc,
|
|
609
|
-
acl: params.acl ?? 'open',
|
|
610
|
-
whitelist: params.whitelist,
|
|
611
|
-
products: params.products ?? [0],
|
|
612
|
-
plans: params.plans ?? [0],
|
|
613
|
-
status: 'wait',
|
|
614
|
-
},
|
|
615
|
-
});
|
|
616
|
-
return res;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
/**
|
|
620
|
-
* 获取项目任务列表
|
|
621
|
-
* @param {{projectID: number, status?: 'unclosed'|'assignedtome'|'myinvolved'|'delayed'|'needconfirm'|'wait'|'doing'|'undone'|'finishedbyme'|'done'|'closed'|'cancel'|'all', param?: number, orderBy?: string, recTotal?: number, recPerPage?: number, pageID?: number, extraFields?: string[]}} [params] 请求参数,`params.projectID` 用于指定所属项目,`params.status` 用于指定任务状态,`params.extraFields` 指定额外要返回的字段,其他字段指定分页信息
|
|
622
|
-
* @returns 请求结果
|
|
623
|
-
* @example
|
|
624
|
-
* ```js
|
|
625
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
626
|
-
* const zentao = new ZentaoApi({
|
|
627
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
628
|
-
* });
|
|
629
|
-
* const result = await zentao.getProjectList({projectID: 1, status: 'undone'});
|
|
630
|
-
* if (result.status) {
|
|
631
|
-
* console.log('任务列表', result.result.tasks);
|
|
632
|
-
* }
|
|
633
|
-
* ```
|
|
634
|
-
*/
|
|
635
|
-
async getTaskList(params: {
|
|
636
|
-
projectID: number;
|
|
637
|
-
status?:
|
|
638
|
-
| 'unclosed'
|
|
639
|
-
| 'assignedtome'
|
|
640
|
-
| 'myinvolved'
|
|
641
|
-
| 'delayed'
|
|
642
|
-
| 'needconfirm'
|
|
643
|
-
| 'wait'
|
|
644
|
-
| 'doing'
|
|
645
|
-
| 'undone'
|
|
646
|
-
| 'finishedbyme'
|
|
647
|
-
| 'done'
|
|
648
|
-
| 'closed'
|
|
649
|
-
| 'cancel'
|
|
650
|
-
| 'all';
|
|
651
|
-
param?: number;
|
|
652
|
-
orderBy?: string;
|
|
653
|
-
recTotal?: number;
|
|
654
|
-
recPerPage?: number;
|
|
655
|
-
pageID?: number;
|
|
656
|
-
extraFields?: string[];
|
|
657
|
-
}): Promise<ZentaoApiResult> {
|
|
658
|
-
const res = await this.request('project', 'task', {
|
|
659
|
-
name: 'getTaskList',
|
|
660
|
-
params: [
|
|
661
|
-
['projectID', params.projectID],
|
|
662
|
-
['status', params?.status ?? 'unclosed'],
|
|
663
|
-
['param', params?.param ?? 0],
|
|
664
|
-
['orderBy', params?.orderBy ?? ''],
|
|
665
|
-
['recTotal', params?.recTotal ?? 0],
|
|
666
|
-
['recPerPage', params?.recPerPage ?? 20],
|
|
667
|
-
['pageID', params?.pageID ?? 1],
|
|
668
|
-
],
|
|
669
|
-
fields: [
|
|
670
|
-
'title',
|
|
671
|
-
'projects',
|
|
672
|
-
'project',
|
|
673
|
-
'products',
|
|
674
|
-
'tasks',
|
|
675
|
-
...(params?.extraFields ?? []),
|
|
676
|
-
],
|
|
677
|
-
});
|
|
678
|
-
return res;
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* 获取指定的任务信息
|
|
683
|
-
* @param {{taskID: number, extraFields?: string[]}} [params] 请求参数,`params.taskID` 用于指定任务 ID,params.extraFields` 指定额外要返回的字段,其他字段指定分页信息
|
|
684
|
-
* @returns 请求结果
|
|
685
|
-
* @example
|
|
686
|
-
* ```js
|
|
687
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
688
|
-
* const zentao = new ZentaoApi({
|
|
689
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
690
|
-
* });
|
|
691
|
-
* const result = await zentao.getTask({taskID: 1});
|
|
692
|
-
* if (result.status) {
|
|
693
|
-
* console.log('任务信息为', result.result.products);
|
|
694
|
-
* }
|
|
695
|
-
* ```
|
|
696
|
-
*/
|
|
697
|
-
async getTask(params: {
|
|
698
|
-
taskID: number;
|
|
699
|
-
extraFields?: string[];
|
|
700
|
-
}): Promise<ZentaoApiResult> {
|
|
701
|
-
const res = await this.request('task', 'view', {
|
|
702
|
-
name: 'getProduct',
|
|
703
|
-
params: [['taskID', params.taskID]],
|
|
704
|
-
fields: [
|
|
705
|
-
'title',
|
|
706
|
-
'task',
|
|
707
|
-
'project',
|
|
708
|
-
'product',
|
|
709
|
-
...(params?.extraFields ?? []),
|
|
710
|
-
],
|
|
711
|
-
});
|
|
712
|
-
return res;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
/**
|
|
716
|
-
* 添加单个任务时,可以先通 过此方法,获取添加任务中所需要的相关信息
|
|
717
|
-
*
|
|
718
|
-
* @param {{extraFields?: string[]}} [params] 请求参数,`params.extraFields` 指定额外要返回的字段
|
|
719
|
-
* @returns 请求结果
|
|
720
|
-
* @example
|
|
721
|
-
* ```js
|
|
722
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
723
|
-
* const zentao = new ZentaoApi({
|
|
724
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
725
|
-
* });
|
|
726
|
-
* const result = await zentao.getTaskCreateParams();
|
|
727
|
-
* ```
|
|
728
|
-
*/
|
|
729
|
-
async getTaskCreateParams(params?: {
|
|
730
|
-
extraFields?: string[];
|
|
731
|
-
}): Promise<ZentaoApiResult> {
|
|
732
|
-
const res = await this.request('task', 'create', {
|
|
733
|
-
name: 'getTaskCreateParams',
|
|
734
|
-
fields: [
|
|
735
|
-
'title',
|
|
736
|
-
'projects',
|
|
737
|
-
'users',
|
|
738
|
-
'stories',
|
|
739
|
-
'moduleOptionMenu',
|
|
740
|
-
'project',
|
|
741
|
-
...(params?.extraFields ?? []),
|
|
742
|
-
],
|
|
743
|
-
});
|
|
744
|
-
return res;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
/**
|
|
748
|
-
* 向系统添加一个任务
|
|
749
|
-
* @param params 任务信息参数
|
|
750
|
-
* @returns
|
|
751
|
-
* @example
|
|
752
|
-
* ```js
|
|
753
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
754
|
-
* const zentao = new ZentaoApi({
|
|
755
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
756
|
-
* });
|
|
757
|
-
* const result = await zentao.addTask({
|
|
758
|
-
* project: 1, // 必填参数 所属项目ID
|
|
759
|
-
* type: 'ui', // 必填参数 任务类型【design设计|devel开发|test测试|study研究|discuss讨论|ui界面|affair事务|misc其他】
|
|
760
|
-
* module: 0, // 选填参数 所属模块ID
|
|
761
|
-
* assignedTo: 'lisa', // 选填参数 指派用户,示例:'assignedTo' => array('zhangsan')
|
|
762
|
-
* color: '', // 选填参数 任务颜色【示例:#ff4e3e】
|
|
763
|
-
* name: '设计界面', // 必填参数 任务名称
|
|
764
|
-
* pri: 2, // 选填参数 优先级【分为 1、2、3、4级】
|
|
765
|
-
* estimate: 1, // 选填参数 预计时间【小时】
|
|
766
|
-
* desc: '设计界面描述', // 选填参数 任务描述
|
|
767
|
-
* estStarted: '2021-01-11', // 选填参数 日程规划开始【格式:2019-11-20】
|
|
768
|
-
* deadline: '2021-11-12', // 选填参数 日程规划结束【格式:2019-11-28】
|
|
769
|
-
* mailto: 'lisa' // 选填参数 抄送用户,示例:'mailto' => array('lisi', 'niuqi', 'zhangsan'), 代表同时抄送给 3 个用户。
|
|
770
|
-
* });
|
|
771
|
-
* if (result.status) {
|
|
772
|
-
* console.log('任务创建成功');
|
|
773
|
-
* }
|
|
774
|
-
* ```
|
|
775
|
-
*/
|
|
776
|
-
async addTask(params: {
|
|
777
|
-
project: number;
|
|
778
|
-
name: string;
|
|
779
|
-
type?:
|
|
780
|
-
| 'design'
|
|
781
|
-
| 'devel'
|
|
782
|
-
| 'test'
|
|
783
|
-
| 'study'
|
|
784
|
-
| 'discuss'
|
|
785
|
-
| 'ui'
|
|
786
|
-
| 'affair'
|
|
787
|
-
| 'misc';
|
|
788
|
-
module?: number;
|
|
789
|
-
color?: string;
|
|
790
|
-
pri?: number;
|
|
791
|
-
estimate?: number;
|
|
792
|
-
desc?: string;
|
|
793
|
-
estStarted?: string;
|
|
794
|
-
deadline?: string;
|
|
795
|
-
assignedTo?: string[];
|
|
796
|
-
mailto?: string[];
|
|
797
|
-
}): Promise<ZentaoApiResult> {
|
|
798
|
-
const res = await this.request('task', 'create', {
|
|
799
|
-
name: 'addTask',
|
|
800
|
-
method: 'POST',
|
|
801
|
-
data: {
|
|
802
|
-
project: params.project,
|
|
803
|
-
type: params.type ?? 'devl',
|
|
804
|
-
name: params.name,
|
|
805
|
-
module: params.module ?? 0,
|
|
806
|
-
color: params.color,
|
|
807
|
-
pri: params.pri ?? 3,
|
|
808
|
-
estimate: params.estimate ?? 0,
|
|
809
|
-
desc: params.desc,
|
|
810
|
-
estStarted: params.estStarted,
|
|
811
|
-
deadline: params.deadline,
|
|
812
|
-
assignedTo: params.assignedTo ?? [''],
|
|
813
|
-
mailto: params.mailto ?? [''],
|
|
814
|
-
},
|
|
815
|
-
});
|
|
816
|
-
return res;
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
/**
|
|
820
|
-
* 获取该任务的所属项目详情、任务详情、任务操作记录,同时获取用于指派完成的用户列表
|
|
821
|
-
*
|
|
822
|
-
* @param {{extraFields?: string[]}} [params] 请求参数,`params.extraFields` 指定额外要返回的字段
|
|
823
|
-
* @returns 请求结果
|
|
824
|
-
* @example
|
|
825
|
-
* ```js
|
|
826
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
827
|
-
* const zentao = new ZentaoApi({
|
|
828
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
829
|
-
* });
|
|
830
|
-
* const result = await zentao.getTaskFinishParams({taskID: 1});
|
|
831
|
-
* ```
|
|
832
|
-
*/
|
|
833
|
-
async getTaskFinishParams(params: {
|
|
834
|
-
taskID: number;
|
|
835
|
-
extraFields?: string[];
|
|
836
|
-
}): Promise<ZentaoApiResult> {
|
|
837
|
-
const res = await this.request('task', 'finish', {
|
|
838
|
-
name: 'getTaskFinishParams',
|
|
839
|
-
params: [['taskID', params.taskID]],
|
|
840
|
-
fields: [
|
|
841
|
-
'title',
|
|
842
|
-
'users',
|
|
843
|
-
'task',
|
|
844
|
-
'project',
|
|
845
|
-
'actions',
|
|
846
|
-
...(params?.extraFields ?? []),
|
|
847
|
-
],
|
|
848
|
-
});
|
|
849
|
-
return res;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
/**
|
|
853
|
-
* 完成一个任务
|
|
854
|
-
* @param params 任务信息参数
|
|
855
|
-
* @returns
|
|
856
|
-
* @example
|
|
857
|
-
* ```js
|
|
858
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
859
|
-
* const zentao = new ZentaoApi({
|
|
860
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
861
|
-
* });
|
|
862
|
-
* const result = await zentao.finishTask({taskID: 1, currentConsumed: 1});
|
|
863
|
-
* if (result.status) {
|
|
864
|
-
* console.log('任务完成');
|
|
865
|
-
* }
|
|
866
|
-
* ```
|
|
867
|
-
*/
|
|
868
|
-
async finishTask(params: {
|
|
869
|
-
taskID: number;
|
|
870
|
-
currentConsumed: number;
|
|
871
|
-
consumed?: number;
|
|
872
|
-
assignedTo?: string;
|
|
873
|
-
finishedDate?: string;
|
|
874
|
-
comment?: string;
|
|
875
|
-
}): Promise<ZentaoApiResult> {
|
|
876
|
-
let consumed = params.consumed;
|
|
877
|
-
if (consumed === undefined) {
|
|
878
|
-
const paramsRes = await this.getTaskFinishParams({
|
|
879
|
-
taskID: params.taskID,
|
|
880
|
-
extraFields: ['task'],
|
|
881
|
-
});
|
|
882
|
-
consumed = paramsRes.result.task.consumed;
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
const res = await this.request('task', 'finish', {
|
|
886
|
-
name: 'finishTask',
|
|
887
|
-
method: 'POST',
|
|
888
|
-
params: [['taskID', params.taskID]],
|
|
889
|
-
data: {
|
|
890
|
-
currentConsumed: params.currentConsumed,
|
|
891
|
-
consumed,
|
|
892
|
-
assignedTo: params.assignedTo,
|
|
893
|
-
finishedDate:
|
|
894
|
-
params.finishedDate ?? formatDate(new Date(), 'yyyy-MM-dd'),
|
|
895
|
-
comment: params.comment,
|
|
896
|
-
status: 'done',
|
|
897
|
-
},
|
|
898
|
-
});
|
|
899
|
-
return res;
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
/**
|
|
903
|
-
* 获取产品 Bug 列表
|
|
904
|
-
* @param {{productID: number, branch?: number, browseType?: 'all'|'unclosed'|'openedbyme'|'assigntome'|'resolvedbyme'|'toclosed'|'unresolved'|'unconfirmed'|'longlifebugs'|'postponedbugs'|'overduebugs'|'needconfirm', param?: number, orderBy?: string, recTotal?: number, recPerPage?: number, pageID?: number, extraFields?: string[]}} [params] 请求参数,`params.productID` 用于指定所属产品,`params.browseType` 用于指定 bug 列表类型,`params.extraFields` 指定额外要返回的字段,其他字段指定分页信息
|
|
905
|
-
* @returns 请求结果
|
|
906
|
-
* @example
|
|
907
|
-
* ```js
|
|
908
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
909
|
-
* const zentao = new ZentaoApi({
|
|
910
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
911
|
-
* });
|
|
912
|
-
* const result = await zentao.getProjectList({projectID: 1, status: 'undone'});
|
|
913
|
-
* if (result.status) {
|
|
914
|
-
* console.log('Bug列表', result.result.bugs);
|
|
915
|
-
* }
|
|
916
|
-
* ```
|
|
917
|
-
*/
|
|
918
|
-
async getBugList(params: {
|
|
919
|
-
productID: number;
|
|
920
|
-
branch?: number;
|
|
921
|
-
browseType?:
|
|
922
|
-
| 'all'
|
|
923
|
-
| 'unclosed'
|
|
924
|
-
| 'openedbyme'
|
|
925
|
-
| 'assigntome'
|
|
926
|
-
| 'resolvedbyme'
|
|
927
|
-
| 'toclosed'
|
|
928
|
-
| 'unresolved'
|
|
929
|
-
| 'unconfirmed'
|
|
930
|
-
| 'longlifebugs'
|
|
931
|
-
| 'postponedbugs'
|
|
932
|
-
| 'overduebugs'
|
|
933
|
-
| 'needconfirm';
|
|
934
|
-
param?: number;
|
|
935
|
-
orderBy?: string;
|
|
936
|
-
recTotal?: number;
|
|
937
|
-
recPerPage?: number;
|
|
938
|
-
pageID?: number;
|
|
939
|
-
extraFields?: string[];
|
|
940
|
-
}): Promise<ZentaoApiResult> {
|
|
941
|
-
const res = await this.request('bug', 'browse', {
|
|
942
|
-
name: 'getTaskList',
|
|
943
|
-
params: [
|
|
944
|
-
['productID', params.productID],
|
|
945
|
-
['branch', params?.branch ?? 0],
|
|
946
|
-
['browseType', params?.browseType ?? 'unclosed'],
|
|
947
|
-
['param', params?.param ?? 0],
|
|
948
|
-
['orderBy', params?.orderBy ?? ''],
|
|
949
|
-
['recTotal', params?.recTotal ?? 0],
|
|
950
|
-
['recPerPage', params?.recPerPage ?? 20],
|
|
951
|
-
['pageID', params?.pageID ?? 1],
|
|
952
|
-
],
|
|
953
|
-
fields: [
|
|
954
|
-
'title',
|
|
955
|
-
'products',
|
|
956
|
-
'productID',
|
|
957
|
-
'productName',
|
|
958
|
-
'product',
|
|
959
|
-
'moduleName',
|
|
960
|
-
'modules',
|
|
961
|
-
'browseType',
|
|
962
|
-
'bugs',
|
|
963
|
-
...(params?.extraFields ?? []),
|
|
964
|
-
],
|
|
965
|
-
});
|
|
966
|
-
return res;
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
/**
|
|
970
|
-
* 获取指定的 Bug 信息
|
|
971
|
-
* @param {{bugID: number, extraFields?: string[]}} [params] 请求参数,`params.bugID` 用于指定Bug ID,params.extraFields` 指定额外要返回的字段,其他字段指定分页信息
|
|
972
|
-
* @returns 请求结果
|
|
973
|
-
* ```js
|
|
974
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
975
|
-
* const zentao = new ZentaoApi({
|
|
976
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
977
|
-
* });
|
|
978
|
-
* const result = await zentao.getBug({bugID: 1});
|
|
979
|
-
* if (result.status) {
|
|
980
|
-
* console.log('Bug 信息为', result.result.bug);
|
|
981
|
-
* }
|
|
982
|
-
* ```
|
|
983
|
-
*/
|
|
984
|
-
async getBug(params: {
|
|
985
|
-
bugID: number;
|
|
986
|
-
extraFields?: string[];
|
|
987
|
-
}): Promise<ZentaoApiResult> {
|
|
988
|
-
const res = await this.request('bug', 'view', {
|
|
989
|
-
name: 'getBug',
|
|
990
|
-
params: [['bugID', params.bugID]],
|
|
991
|
-
fields: [
|
|
992
|
-
'title',
|
|
993
|
-
'bug',
|
|
994
|
-
'productName',
|
|
995
|
-
...(params?.extraFields ?? []),
|
|
996
|
-
],
|
|
997
|
-
});
|
|
998
|
-
return res;
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
/**
|
|
1002
|
-
* 用 于为指定的产品添加 Bug 之前,获取添加 Bug 时可能需要用到的一些相关信息。
|
|
1003
|
-
*
|
|
1004
|
-
* @param {{extraFields?: string[]}} [params] 请求参数,`params.extraFields` 指定额外要返回的字段
|
|
1005
|
-
* @returns 请求结果
|
|
1006
|
-
* @example
|
|
1007
|
-
* ```js
|
|
1008
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
1009
|
-
* const zentao = new ZentaoApi({
|
|
1010
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
1011
|
-
* });
|
|
1012
|
-
* const result = await zentao.getBugCreateParams();
|
|
1013
|
-
* ```
|
|
1014
|
-
*/
|
|
1015
|
-
async getBugCreateParams(params: {
|
|
1016
|
-
productID: number;
|
|
1017
|
-
extraFields?: string[];
|
|
1018
|
-
}): Promise<ZentaoApiResult> {
|
|
1019
|
-
const res = await this.request('bug', 'create', {
|
|
1020
|
-
name: 'getBugCreateParams',
|
|
1021
|
-
params: [['productID', params.productID]],
|
|
1022
|
-
fields: [
|
|
1023
|
-
'title',
|
|
1024
|
-
'productID',
|
|
1025
|
-
'productName',
|
|
1026
|
-
'projects',
|
|
1027
|
-
'moduleOptionMenu',
|
|
1028
|
-
'users',
|
|
1029
|
-
'stories',
|
|
1030
|
-
'builds',
|
|
1031
|
-
...(params?.extraFields ?? []),
|
|
1032
|
-
],
|
|
1033
|
-
});
|
|
1034
|
-
return res;
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
/**
|
|
1038
|
-
* 向系统添加一个 Bug
|
|
1039
|
-
* @param params Bug 信息参数
|
|
1040
|
-
* @returns
|
|
1041
|
-
* @example
|
|
1042
|
-
* ```js
|
|
1043
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
1044
|
-
* const zentao = new ZentaoApi({
|
|
1045
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
1046
|
-
* });
|
|
1047
|
-
* const result = await zentao.addBug({
|
|
1048
|
-
* product: 1, // 必填参数 所属产品ID
|
|
1049
|
-
* module: 2, // 选填参数 所属模块ID
|
|
1050
|
-
* project: 1, // 选填参数 所属项目ID
|
|
1051
|
-
* openedBuild: ['trunk', 3, 2], // 选填参数 影响版本ID【添加单个 Bug 可选信息结果中 builds 记录的 key 值】
|
|
1052
|
-
* assignedTo: 'lisi', // 选填参数 当前指派【用户账号】
|
|
1053
|
-
* deadline: '2019-11-21', // 选填参数 截止日期【格式示例:2019-11-11】
|
|
1054
|
-
* type: 'codeerror', // 选填参数 BUG类型【codeerror代码错误|config配置相关|install安装部署|security安全相关|performance性能问题|standard标准规范|automation测试脚本|designdefect设计缺陷|others其他
|
|
1055
|
-
* os: 'windows', // 选填参数 选填参数|操作系统【all-全部|windows-Windows|win10-Windows 10|win8-Windows 8|win7-Windows 7|vista-Windows Vista|winxp-Windows XP|win2012-Windows 2012|win2008-Windows 2008|win2003-Windows 2003|win2000-Windows 2000|android-Android|ios-IOS|wp8-WP8|wp7-WP7|symbian-Symbian|linux-Linux|freebsd-FreeBSD|osx-OS X|unix-Unix|others-其他】
|
|
1056
|
-
* browser: 'ie11', // 选填参数|浏览器【all-全部|ie-IE系列|ie11-IE11|ie10-IE10|ie9-IE9|ie8-IE8|ie7-IE7|ie6-IE6|chrome-Chrome|firefox-firefox系列|firefox4-firefox4|firefox3-firefox3|firefox2-firefox2|opera-opera系列|oprea11-oprea11|oprea10-opera10|opera9-opera9|safari-safari|maxthon-傲游|uc-UC|other-其他】
|
|
1057
|
-
* title: '添加bug测试四', // BUG标题
|
|
1058
|
-
* color: '#2dbdb2', // BUG颜色【示例:#2dbdb2】
|
|
1059
|
-
* severity: 2, // 严重程度【1~4】
|
|
1060
|
-
* pri: 1, // 优先级【1~4】
|
|
1061
|
-
* steps: '重现步骤描述', // 重现步骤
|
|
1062
|
-
* story: 0, // 重现步骤描述
|
|
1063
|
-
* task: 0, // 相关需求ID
|
|
1064
|
-
* mailto: ['lisi', '张三'], // 抄送
|
|
1065
|
-
* keywords: 'bug4' // BUG关键词
|
|
1066
|
-
* });
|
|
1067
|
-
* if (result.status) {
|
|
1068
|
-
* console.log('Bug 创建成功');
|
|
1069
|
-
* }
|
|
1070
|
-
* ```
|
|
1071
|
-
*/
|
|
1072
|
-
async addBug(params: {
|
|
1073
|
-
product: number;
|
|
1074
|
-
title: string;
|
|
1075
|
-
module?: number;
|
|
1076
|
-
project?: number;
|
|
1077
|
-
openedBuild?: any[];
|
|
1078
|
-
assignedTo?: string;
|
|
1079
|
-
deadline?: string;
|
|
1080
|
-
type?:
|
|
1081
|
-
| 'codeerror'
|
|
1082
|
-
| 'config'
|
|
1083
|
-
| 'install'
|
|
1084
|
-
| 'security'
|
|
1085
|
-
| 'performance'
|
|
1086
|
-
| 'standard'
|
|
1087
|
-
| 'automation'
|
|
1088
|
-
| 'designdefect'
|
|
1089
|
-
| 'others';
|
|
1090
|
-
os?:
|
|
1091
|
-
| 'all'
|
|
1092
|
-
| 'windows'
|
|
1093
|
-
| 'win10'
|
|
1094
|
-
| 'win8'
|
|
1095
|
-
| 'win7'
|
|
1096
|
-
| 'vista'
|
|
1097
|
-
| 'winxp'
|
|
1098
|
-
| 'win2012'
|
|
1099
|
-
| 'win2008'
|
|
1100
|
-
| 'win2003'
|
|
1101
|
-
| 'win2000'
|
|
1102
|
-
| 'android'
|
|
1103
|
-
| 'ios'
|
|
1104
|
-
| 'wp8'
|
|
1105
|
-
| 'wp7'
|
|
1106
|
-
| 'symbian'
|
|
1107
|
-
| 'linux'
|
|
1108
|
-
| 'freebsd'
|
|
1109
|
-
| 'osx'
|
|
1110
|
-
| 'unix'
|
|
1111
|
-
| 'others';
|
|
1112
|
-
browser?:
|
|
1113
|
-
| 'all'
|
|
1114
|
-
| 'ie'
|
|
1115
|
-
| 'ie11'
|
|
1116
|
-
| 'ie10'
|
|
1117
|
-
| 'ie9'
|
|
1118
|
-
| 'ie8'
|
|
1119
|
-
| 'ie7'
|
|
1120
|
-
| 'ie6'
|
|
1121
|
-
| 'chrome'
|
|
1122
|
-
| 'firefox'
|
|
1123
|
-
| 'firefox4'
|
|
1124
|
-
| 'firefox3'
|
|
1125
|
-
| 'firefox2'
|
|
1126
|
-
| 'opera'
|
|
1127
|
-
| 'oprea11'
|
|
1128
|
-
| 'oprea10'
|
|
1129
|
-
| 'opera'
|
|
1130
|
-
| 'safari'
|
|
1131
|
-
| 'maxthon'
|
|
1132
|
-
| 'uc'
|
|
1133
|
-
| 'other';
|
|
1134
|
-
color?: string;
|
|
1135
|
-
severity?: number;
|
|
1136
|
-
pri?: number;
|
|
1137
|
-
steps?: string;
|
|
1138
|
-
story?: number;
|
|
1139
|
-
task?: number;
|
|
1140
|
-
keywords?: string;
|
|
1141
|
-
mailto?: string[];
|
|
1142
|
-
}): Promise<ZentaoApiResult> {
|
|
1143
|
-
const res = await this.request('bug', 'create', {
|
|
1144
|
-
name: 'addBug',
|
|
1145
|
-
method: 'POST',
|
|
1146
|
-
params: [['productID', params.product]],
|
|
1147
|
-
data: {
|
|
1148
|
-
product: params.product,
|
|
1149
|
-
title: params.title,
|
|
1150
|
-
module: params.module ?? 0,
|
|
1151
|
-
project: params.project ?? 0,
|
|
1152
|
-
openedBuild: params.openedBuild ?? ['trunk'],
|
|
1153
|
-
assignedTo: params.assignedTo,
|
|
1154
|
-
deadline: params.deadline,
|
|
1155
|
-
type: params.type ?? 'codeerror',
|
|
1156
|
-
os: params.os ?? 'all',
|
|
1157
|
-
browser: params.browser ?? 'all',
|
|
1158
|
-
color: params.color,
|
|
1159
|
-
severity: params.severity ?? 3,
|
|
1160
|
-
pri: params.pri ?? 3,
|
|
1161
|
-
steps: params.steps,
|
|
1162
|
-
story: params.story ?? 0,
|
|
1163
|
-
task: params.task ?? 0,
|
|
1164
|
-
keywords: params.keywords,
|
|
1165
|
-
mailto: params.mailto,
|
|
1166
|
-
},
|
|
1167
|
-
});
|
|
1168
|
-
return res;
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
/**
|
|
1172
|
-
* 获取当前 Bug 详细信息以及确认 Bug 解决时可能用到的信息。
|
|
1173
|
-
*
|
|
1174
|
-
* @param {{bugID: number, extraFields?: string[]}} params 请求参数,`params.extraFields` 指定额外要返回的字段
|
|
1175
|
-
* @returns 请求结果
|
|
1176
|
-
* @example
|
|
1177
|
-
* ```js
|
|
1178
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
1179
|
-
* const zentao = new ZentaoApi({
|
|
1180
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
1181
|
-
* });
|
|
1182
|
-
* const result = await zentao.getBugResolveParams({bugID: 1});
|
|
1183
|
-
* ```
|
|
1184
|
-
*/
|
|
1185
|
-
async getBugResolveParams(params: {
|
|
1186
|
-
bugID: number;
|
|
1187
|
-
extraFields?: string[];
|
|
1188
|
-
}): Promise<ZentaoApiResult> {
|
|
1189
|
-
const res = await this.request('bug', 'resolve', {
|
|
1190
|
-
name: 'getBugResolveParams',
|
|
1191
|
-
params: [['bugID', params.bugID]],
|
|
1192
|
-
fields: [
|
|
1193
|
-
'title',
|
|
1194
|
-
'products',
|
|
1195
|
-
'bug',
|
|
1196
|
-
'users',
|
|
1197
|
-
'builds',
|
|
1198
|
-
'actions',
|
|
1199
|
-
...(params?.extraFields ?? []),
|
|
1200
|
-
],
|
|
1201
|
-
});
|
|
1202
|
-
return res;
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
/**
|
|
1206
|
-
* 解决一个 Bug
|
|
1207
|
-
* @param params 任务信息参数
|
|
1208
|
-
* @returns
|
|
1209
|
-
* @example
|
|
1210
|
-
* ```js
|
|
1211
|
-
* import { ZentaoApi } from 'zentao-api';
|
|
1212
|
-
* const zentao = new ZentaoApi({
|
|
1213
|
-
* url: 'https://pro.demo.zentao.net/', account: 'demo', password: '123456'
|
|
1214
|
-
* });
|
|
1215
|
-
* const result = await zentao.resolveBug({bugID: 1, resolution: 'fixed'});
|
|
1216
|
-
* if (result.status) {
|
|
1217
|
-
* console.log('bug 已解决');
|
|
1218
|
-
* }
|
|
1219
|
-
* ```
|
|
1220
|
-
*/
|
|
1221
|
-
async resolveBug(params: {
|
|
1222
|
-
bugID: number;
|
|
1223
|
-
resolution?:
|
|
1224
|
-
| 'bydesign'
|
|
1225
|
-
| 'duplicate'
|
|
1226
|
-
| 'external'
|
|
1227
|
-
| 'fixed'
|
|
1228
|
-
| 'notrepro'
|
|
1229
|
-
| 'postponed'
|
|
1230
|
-
| 'willnotfix';
|
|
1231
|
-
resolvedBuild?: string;
|
|
1232
|
-
resolvedDate?: string;
|
|
1233
|
-
assignedTo?: string;
|
|
1234
|
-
comment?: string;
|
|
1235
|
-
buildProject?: number;
|
|
1236
|
-
buildName?: string;
|
|
1237
|
-
createBuild?: 0 | 1;
|
|
1238
|
-
duplicateBug?: number;
|
|
1239
|
-
}): Promise<ZentaoApiResult> {
|
|
1240
|
-
const data: Record<string, any> = {
|
|
1241
|
-
resolution: params.resolution ?? 'fixed',
|
|
1242
|
-
resolvedBuild: params.resolvedBuild ?? 'trunk',
|
|
1243
|
-
resolvedDate:
|
|
1244
|
-
params.resolvedDate ??
|
|
1245
|
-
formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss'),
|
|
1246
|
-
assignedTo: params.assignedTo,
|
|
1247
|
-
comment: params.comment,
|
|
1248
|
-
duplicateBug: params.duplicateBug,
|
|
1249
|
-
status: 'resolved',
|
|
1250
|
-
};
|
|
1251
|
-
if (params.createBuild) {
|
|
1252
|
-
data.createBuild = 1;
|
|
1253
|
-
data.buildProject = params.buildProject;
|
|
1254
|
-
data.buildName = params.buildName;
|
|
1255
|
-
}
|
|
1256
|
-
const res = await this.request('bug', 'resolve', {
|
|
1257
|
-
name: 'resolveBug',
|
|
1258
|
-
method: 'POST',
|
|
1259
|
-
params: [['bugID', params.bugID]],
|
|
1260
|
-
data,
|
|
1261
|
-
resultConvertor: (_remoteData, result) => {
|
|
1262
|
-
if (result.result.result === 'fail') {
|
|
1263
|
-
result.status = 0;
|
|
1264
|
-
result.msg = result.result.message;
|
|
1265
|
-
result.result = null;
|
|
1266
|
-
}
|
|
1267
|
-
return result;
|
|
1268
|
-
},
|
|
1269
|
-
});
|
|
1270
|
-
return res;
|
|
1271
|
-
}
|
|
1272
|
-
}
|