devops-mcp-server-extension 1.0.0
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 +218 -0
- package/README.md +527 -0
- package/README.zh-cn.md +503 -0
- package/dist/common/errors.js +77 -0
- package/dist/common/modularTemplates.js +483 -0
- package/dist/common/pipelineTemplates.js +19 -0
- package/dist/common/toolsetManager.js +123 -0
- package/dist/common/toolsets.js +23 -0
- package/dist/common/types.js +60 -0
- package/dist/common/utils.js +381 -0
- package/dist/common/version.js +1 -0
- package/dist/index.js +225 -0
- package/dist/operations/appstack/appOrchestrations.js +260 -0
- package/dist/operations/appstack/appTags.js +168 -0
- package/dist/operations/appstack/appTemplates.js +72 -0
- package/dist/operations/appstack/applications.js +171 -0
- package/dist/operations/appstack/changeOrders.js +320 -0
- package/dist/operations/appstack/changeRequests.js +288 -0
- package/dist/operations/appstack/deploymentResources.js +286 -0
- package/dist/operations/appstack/globalVars.js +221 -0
- package/dist/operations/appstack/releaseWorkflows.js +695 -0
- package/dist/operations/appstack/variableGroups.js +245 -0
- package/dist/operations/codeup/branches.js +157 -0
- package/dist/operations/codeup/changeRequestComments.js +140 -0
- package/dist/operations/codeup/changeRequests.js +230 -0
- package/dist/operations/codeup/commits.js +121 -0
- package/dist/operations/codeup/compare.js +30 -0
- package/dist/operations/codeup/files.js +249 -0
- package/dist/operations/codeup/repositories.js +71 -0
- package/dist/operations/codeup/types.js +414 -0
- package/dist/operations/flow/hostGroup.js +52 -0
- package/dist/operations/flow/pipeline.js +609 -0
- package/dist/operations/flow/pipelineJob.js +126 -0
- package/dist/operations/flow/resourceMember.js +137 -0
- package/dist/operations/flow/serviceConnection.js +27 -0
- package/dist/operations/flow/tag.js +191 -0
- package/dist/operations/flow/types.js +523 -0
- package/dist/operations/flow/vmDeployOrder.js +171 -0
- package/dist/operations/organization/members.js +106 -0
- package/dist/operations/organization/organization.js +110 -0
- package/dist/operations/organization/types.js +111 -0
- package/dist/operations/packages/artifacts.js +71 -0
- package/dist/operations/packages/repositories.js +39 -0
- package/dist/operations/packages/types.js +56 -0
- package/dist/operations/projex/effort.js +122 -0
- package/dist/operations/projex/project.js +243 -0
- package/dist/operations/projex/sprint.js +103 -0
- package/dist/operations/projex/types.js +618 -0
- package/dist/operations/projex/workitem.js +826 -0
- package/dist/operations/testhub/testcases.js +240 -0
- package/dist/operations/testhub/testplans.js +128 -0
- package/dist/tool-handlers/appstack-app-release-workflows.js +103 -0
- package/dist/tool-handlers/appstack-change-orders.js +55 -0
- package/dist/tool-handlers/appstack-change-requests.js +49 -0
- package/dist/tool-handlers/appstack-deployment-resources.js +31 -0
- package/dist/tool-handlers/appstack-global-vars.js +37 -0
- package/dist/tool-handlers/appstack-orchestrations.js +49 -0
- package/dist/tool-handlers/appstack-release-workflows.js +37 -0
- package/dist/tool-handlers/appstack-tags.js +37 -0
- package/dist/tool-handlers/appstack-templates.js +19 -0
- package/dist/tool-handlers/appstack-variable-groups.js +55 -0
- package/dist/tool-handlers/appstack.js +37 -0
- package/dist/tool-handlers/base.js +25 -0
- package/dist/tool-handlers/code-management.js +150 -0
- package/dist/tool-handlers/commit.js +31 -0
- package/dist/tool-handlers/effort.js +103 -0
- package/dist/tool-handlers/index.js +119 -0
- package/dist/tool-handlers/organization.js +72 -0
- package/dist/tool-handlers/packages.js +32 -0
- package/dist/tool-handlers/pipeline.js +289 -0
- package/dist/tool-handlers/project-management.js +201 -0
- package/dist/tool-handlers/resourceMember.js +43 -0
- package/dist/tool-handlers/service-connections.js +16 -0
- package/dist/tool-handlers/tag.js +64 -0
- package/dist/tool-handlers/test-management.js +74 -0
- package/dist/tool-handlers/vmDeployOrder.js +50 -0
- package/dist/tool-registry/appstack-app-release-workflows.js +80 -0
- package/dist/tool-registry/appstack-change-orders.js +40 -0
- package/dist/tool-registry/appstack-change-requests.js +35 -0
- package/dist/tool-registry/appstack-deployment-resources.js +20 -0
- package/dist/tool-registry/appstack-global-vars.js +25 -0
- package/dist/tool-registry/appstack-orchestrations.js +35 -0
- package/dist/tool-registry/appstack-release-workflows.js +25 -0
- package/dist/tool-registry/appstack-tags.js +25 -0
- package/dist/tool-registry/appstack-templates.js +10 -0
- package/dist/tool-registry/appstack-variable-groups.js +40 -0
- package/dist/tool-registry/appstack.js +25 -0
- package/dist/tool-registry/base.js +19 -0
- package/dist/tool-registry/code-management.js +109 -0
- package/dist/tool-registry/commit.js +20 -0
- package/dist/tool-registry/effort.js +39 -0
- package/dist/tool-registry/index.js +7 -0
- package/dist/tool-registry/organization.js +65 -0
- package/dist/tool-registry/packages.js +21 -0
- package/dist/tool-registry/pipeline.js +190 -0
- package/dist/tool-registry/project-management.js +143 -0
- package/dist/tool-registry/resourceMember.js +29 -0
- package/dist/tool-registry/service-connections.js +10 -0
- package/dist/tool-registry/tag.js +44 -0
- package/dist/tool-registry/test-management.js +59 -0
- package/dist/tool-registry/vmDeployOrder.js +34 -0
- package/package.json +52 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { yunxiaoRequest, buildUrl, isRegionEdition } from '../../common/utils.js';
|
|
3
|
+
import { resolveOrganizationId } from '../organization/organization.js';
|
|
4
|
+
// Schema for EnvDeployRequest
|
|
5
|
+
export const EnvDeployRequestSchema = z.object({
|
|
6
|
+
values: z.record(z.string()).optional().describe("环境部署参数键值对"),
|
|
7
|
+
});
|
|
8
|
+
// Schema for CreateChangeOrderReq
|
|
9
|
+
export const CreateChangeOrderReqSchema = z.object({
|
|
10
|
+
changeOrderName: z.string().describe("部署单名称"),
|
|
11
|
+
description: z.string().optional().describe("描述"),
|
|
12
|
+
envs: z.record(EnvDeployRequestSchema).describe("环境信息,key为环境名称,value为对应环境部署单参数(当前仅支持单环境部署)"),
|
|
13
|
+
orchestrationRevisionSha: z.string().optional().describe("编排版本sha值,部署单类型为Deploy时必填"),
|
|
14
|
+
rollbackChangeOrderVersion: z.string().optional().describe("部署单类型为Rollback时必填,指定回滚时使用的部署版本号"),
|
|
15
|
+
type: z.string().describe("部署单类型:Deploy-部署,Scale-扩缩,Rollback-回滚,Destroy-删除资源"),
|
|
16
|
+
});
|
|
17
|
+
// Schema for JobSummary
|
|
18
|
+
export const JobSummarySchema = z.object({
|
|
19
|
+
operator: z.string().nullable().optional().describe("操作人"),
|
|
20
|
+
action: z.string().nullable().optional().describe("操作类型"),
|
|
21
|
+
state: z.string().nullable().optional().describe("环境部署单状态"),
|
|
22
|
+
jobSn: z.string().nullable().optional().describe("环境部署单编号"),
|
|
23
|
+
message: z.string().nullable().optional().describe("消息"),
|
|
24
|
+
gmtCreate: z.string().nullable().optional().describe("创建时间"),
|
|
25
|
+
sn: z.string().nullable().optional().describe("环境部署单唯一标识"),
|
|
26
|
+
envName: z.string().nullable().optional().describe("环境名称"),
|
|
27
|
+
});
|
|
28
|
+
// Schema for ChangeOrderSummary
|
|
29
|
+
export const ChangeOrderSummarySchema = z.object({
|
|
30
|
+
creator: z.string().describe("创建人"),
|
|
31
|
+
description: z.string().nullable().optional().describe("描述"),
|
|
32
|
+
endedAt: z.string().nullable().optional().describe("部署单结束时间"),
|
|
33
|
+
gmtCreate: z.string().describe("部署单最后修改时间"),
|
|
34
|
+
jobs: z.array(JobSummarySchema).describe("环境部署单列表"),
|
|
35
|
+
name: z.string().describe("部署单名称"),
|
|
36
|
+
sn: z.string().describe("部署单唯一标识"),
|
|
37
|
+
startedAt: z.string().nullable().optional().describe("部署单开始时间"),
|
|
38
|
+
state: z.enum(["INIT", "PREPARING", "RUNNING", "SUSPENDED", "CANCELED", "SUCCESS", "FAILED"]).describe("部署单状态"),
|
|
39
|
+
type: z.enum(["Deploy", "Scale", "Rollback", "Destroy"]).describe("部署单类型"),
|
|
40
|
+
version: z.string().describe("使用版本"),
|
|
41
|
+
});
|
|
42
|
+
// Schema for ChangeOrderVersionRecord
|
|
43
|
+
export const ChangeOrderVersionRecordSchema = z.object({
|
|
44
|
+
// Based on the reference in the swagger, we'll define a basic structure
|
|
45
|
+
// You may need to update this with the actual fields from ChangeOrderVersionRecord
|
|
46
|
+
version: z.string().optional().describe("部署单版本"),
|
|
47
|
+
changeOrderSn: z.string().optional().describe("部署单编号"),
|
|
48
|
+
});
|
|
49
|
+
// Schema for JobLog
|
|
50
|
+
export const JobLogSchema = z.object({
|
|
51
|
+
content: z.string().nullable().optional().describe("日志内容"),
|
|
52
|
+
timestamp: z.string().nullable().optional().describe("日志时间戳"),
|
|
53
|
+
});
|
|
54
|
+
// Schema for ActionContext
|
|
55
|
+
export const ActionContextSchema = z.object({
|
|
56
|
+
comment: z.string().describe("操作备注"),
|
|
57
|
+
});
|
|
58
|
+
// Schema for ChangeJobActionReq
|
|
59
|
+
export const ChangeJobActionReqSchema = z.object({
|
|
60
|
+
actionType: z.string().describe("操作类型:SUSPEND-暂停,RESUME-恢复,ROLLBACK-回滚,STOP-终止"),
|
|
61
|
+
context: ActionContextSchema.optional().describe("操作上下文,comment 为操作备注"),
|
|
62
|
+
});
|
|
63
|
+
// Schema for CreateChangeOrder API
|
|
64
|
+
export const CreateChangeOrderRequestSchema = z.object({
|
|
65
|
+
organizationId: z.string().describe("组织ID"),
|
|
66
|
+
appName: z.string().describe("应用名"),
|
|
67
|
+
changeOrder: CreateChangeOrderReqSchema,
|
|
68
|
+
});
|
|
69
|
+
export const CreateChangeOrderResponseSchema = ChangeOrderSummarySchema;
|
|
70
|
+
// Schema for ListChangeOrderVersions API
|
|
71
|
+
export const ListChangeOrderVersionsRequestSchema = z.object({
|
|
72
|
+
organizationId: z.string().describe("组织ID"),
|
|
73
|
+
appName: z.string().describe("应用名"),
|
|
74
|
+
envNames: z.array(z.string()).optional().describe("环境标识列表,如不需按环境过滤,请置空"),
|
|
75
|
+
creators: z.array(z.string()).optional().describe("创建人云效账号id列表,如不需按创建人过滤,请置空"),
|
|
76
|
+
current: z.number().default(1).describe("当前页号(从 1 开始,默认取 1)"),
|
|
77
|
+
pageSize: z.number().default(10).describe("分页记录数(默认 10 条)"),
|
|
78
|
+
});
|
|
79
|
+
export const PaginationChangeOrderVersionRecordSchema = z.object({
|
|
80
|
+
current: z.number().describe("当前页数"),
|
|
81
|
+
pageSize: z.number().describe("每页大小"),
|
|
82
|
+
pages: z.number().describe("总页数"),
|
|
83
|
+
records: z.array(ChangeOrderVersionRecordSchema).describe("数据列表"),
|
|
84
|
+
total: z.number().describe("总数"),
|
|
85
|
+
});
|
|
86
|
+
export const ListChangeOrderVersionsResponseSchema = PaginationChangeOrderVersionRecordSchema;
|
|
87
|
+
// Schema for GetChangeOrder API
|
|
88
|
+
export const GetChangeOrderRequestSchema = z.object({
|
|
89
|
+
organizationId: z.string().describe("组织ID"),
|
|
90
|
+
appName: z.string().describe("应用名"),
|
|
91
|
+
changeOrderSn: z.string().describe("部署单编号"),
|
|
92
|
+
});
|
|
93
|
+
export const GetChangeOrderResponseSchema = ChangeOrderSummarySchema;
|
|
94
|
+
// Schema for ListChangeOrderJobLogs API
|
|
95
|
+
export const ListChangeOrderJobLogsRequestSchema = z.object({
|
|
96
|
+
organizationId: z.string().describe("组织ID"),
|
|
97
|
+
appName: z.string().describe("应用名"),
|
|
98
|
+
changeOrderSn: z.string().describe("部署单号"),
|
|
99
|
+
jobSn: z.string().describe("作业单号"),
|
|
100
|
+
current: z.number().default(1),
|
|
101
|
+
pageSize: z.number().default(10),
|
|
102
|
+
});
|
|
103
|
+
export const PaginationJobLogSchema = z.object({
|
|
104
|
+
current: z.number().describe("当前页数"),
|
|
105
|
+
pageSize: z.number().describe("每页大小"),
|
|
106
|
+
pages: z.number().describe("总页数"),
|
|
107
|
+
records: z.array(JobLogSchema).describe("数据列表"),
|
|
108
|
+
total: z.number().describe("总数"),
|
|
109
|
+
});
|
|
110
|
+
export const ListChangeOrderJobLogsResponseSchema = PaginationJobLogSchema;
|
|
111
|
+
// Schema for FindTaskOperationLog API
|
|
112
|
+
export const FindTaskOperationLogRequestSchema = z.object({
|
|
113
|
+
organizationId: z.string().describe("组织ID"),
|
|
114
|
+
appName: z.string(),
|
|
115
|
+
changeOrderSn: z.string(),
|
|
116
|
+
jobSn: z.string(),
|
|
117
|
+
stageSn: z.string(),
|
|
118
|
+
taskSn: z.string(),
|
|
119
|
+
});
|
|
120
|
+
export const FindTaskOperationLogResponseSchema = z.string();
|
|
121
|
+
// Schema for ExecuteJobAction API
|
|
122
|
+
export const ExecuteJobActionRequestSchema = z.object({
|
|
123
|
+
organizationId: z.string().describe("组织ID"),
|
|
124
|
+
appName: z.string().describe("应用名"),
|
|
125
|
+
changeOrderSn: z.string().describe("部署单编号,即 changeOrder.sn"),
|
|
126
|
+
jobSn: z.string().describe("环境部署单编号,即 job.sn"),
|
|
127
|
+
action: ChangeJobActionReqSchema,
|
|
128
|
+
});
|
|
129
|
+
export const ExecuteJobActionResponseSchema = ChangeOrderSummarySchema;
|
|
130
|
+
// Schema for ListChangeOrdersByOrigin API
|
|
131
|
+
export const ListChangeOrdersByOriginRequestSchema = z.object({
|
|
132
|
+
organizationId: z.string().describe("组织ID"),
|
|
133
|
+
originType: z.string().describe("创建来源类型"),
|
|
134
|
+
originId: z.string().describe("创建来源标识"),
|
|
135
|
+
appName: z.string().optional().describe("应用名"),
|
|
136
|
+
envName: z.string().optional().describe("环境名"),
|
|
137
|
+
});
|
|
138
|
+
export const ListChangeOrdersByOriginResponseSchema = z.array(ChangeOrderSummarySchema);
|
|
139
|
+
/**
|
|
140
|
+
* Create a change order (deployment order)
|
|
141
|
+
*
|
|
142
|
+
* @param params - The request parameters
|
|
143
|
+
* @returns The created change order summary
|
|
144
|
+
*/
|
|
145
|
+
export async function createChangeOrder(params) {
|
|
146
|
+
const { organizationId, appName, changeOrder } = params;
|
|
147
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
148
|
+
try {
|
|
149
|
+
const url = isRegionEdition()
|
|
150
|
+
? `/oapi/v1/appstack/apps/${appName}/changeOrders`
|
|
151
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeOrders`;
|
|
152
|
+
const response = await yunxiaoRequest(url, {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
body: changeOrder,
|
|
155
|
+
});
|
|
156
|
+
return CreateChangeOrderResponseSchema.parse(response);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* List change order versions
|
|
164
|
+
*
|
|
165
|
+
* @param params - The request parameters
|
|
166
|
+
* @returns The paginated list of change order versions
|
|
167
|
+
*/
|
|
168
|
+
export async function listChangeOrderVersions(params) {
|
|
169
|
+
const { organizationId, appName, envNames, creators, current, pageSize } = params;
|
|
170
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
171
|
+
try {
|
|
172
|
+
const query = {
|
|
173
|
+
current,
|
|
174
|
+
pageSize
|
|
175
|
+
};
|
|
176
|
+
if (envNames && envNames.length > 0) {
|
|
177
|
+
query.envNames = envNames;
|
|
178
|
+
}
|
|
179
|
+
if (creators && creators.length > 0) {
|
|
180
|
+
query.creators = creators;
|
|
181
|
+
}
|
|
182
|
+
const baseUrl = isRegionEdition()
|
|
183
|
+
? `/oapi/v1/appstack/apps/${appName}/changeOrders/versions`
|
|
184
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeOrders/versions`;
|
|
185
|
+
const url = buildUrl(baseUrl, query);
|
|
186
|
+
const response = await yunxiaoRequest(url, {
|
|
187
|
+
method: 'GET',
|
|
188
|
+
});
|
|
189
|
+
return ListChangeOrderVersionsResponseSchema.parse(response);
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Get a change order by its serial number
|
|
197
|
+
*
|
|
198
|
+
* @param params - The request parameters
|
|
199
|
+
* @returns The change order summary
|
|
200
|
+
*/
|
|
201
|
+
export async function getChangeOrder(params) {
|
|
202
|
+
const { organizationId, appName, changeOrderSn } = params;
|
|
203
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
204
|
+
try {
|
|
205
|
+
const url = isRegionEdition()
|
|
206
|
+
? `/oapi/v1/appstack/apps/${appName}/changeOrders/${changeOrderSn}`
|
|
207
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeOrders/${changeOrderSn}`;
|
|
208
|
+
const response = await yunxiaoRequest(url, {
|
|
209
|
+
method: 'GET',
|
|
210
|
+
});
|
|
211
|
+
return GetChangeOrderResponseSchema.parse(response);
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* List change order job logs
|
|
219
|
+
*
|
|
220
|
+
* @param params - The request parameters
|
|
221
|
+
* @returns The paginated list of job logs
|
|
222
|
+
*/
|
|
223
|
+
export async function listChangeOrderJobLogs(params) {
|
|
224
|
+
const { organizationId, appName, changeOrderSn, jobSn, current, pageSize } = params;
|
|
225
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
226
|
+
try {
|
|
227
|
+
const baseUrl = isRegionEdition()
|
|
228
|
+
? `/oapi/v1/appstack/apps/${appName}/changeOrders/${changeOrderSn}/jobs/${jobSn}/logs`
|
|
229
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeOrders/${changeOrderSn}/jobs/${jobSn}/logs`;
|
|
230
|
+
const url = buildUrl(baseUrl, {
|
|
231
|
+
current,
|
|
232
|
+
pageSize
|
|
233
|
+
});
|
|
234
|
+
const response = await yunxiaoRequest(url, {
|
|
235
|
+
method: 'GET',
|
|
236
|
+
});
|
|
237
|
+
return ListChangeOrderJobLogsResponseSchema.parse(response);
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
throw error;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Find task operation log
|
|
245
|
+
*
|
|
246
|
+
* @param params - The request parameters
|
|
247
|
+
* @returns The task operation log content
|
|
248
|
+
*/
|
|
249
|
+
export async function findTaskOperationLog(params) {
|
|
250
|
+
const { organizationId, appName, changeOrderSn, jobSn, stageSn, taskSn } = params;
|
|
251
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
252
|
+
try {
|
|
253
|
+
const url = isRegionEdition()
|
|
254
|
+
? `/oapi/v1/appstack/apps/${appName}/changeOrders/${changeOrderSn}/jobs/${jobSn}/stages/${stageSn}/tasks/${taskSn}/operationLog`
|
|
255
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeOrders/${changeOrderSn}/jobs/${jobSn}/stages/${stageSn}/tasks/${taskSn}/operationLog`;
|
|
256
|
+
const response = await yunxiaoRequest(url, {
|
|
257
|
+
method: 'GET',
|
|
258
|
+
});
|
|
259
|
+
return FindTaskOperationLogResponseSchema.parse(response);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Execute a job action
|
|
267
|
+
*
|
|
268
|
+
* @param params - The request parameters
|
|
269
|
+
* @returns The updated change order summary
|
|
270
|
+
*/
|
|
271
|
+
export async function executeJobAction(params) {
|
|
272
|
+
const { organizationId, appName, changeOrderSn, jobSn, action } = params;
|
|
273
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
274
|
+
try {
|
|
275
|
+
const url = isRegionEdition()
|
|
276
|
+
? `/oapi/v1/appstack/apps/${appName}/changeOrders/${changeOrderSn}/jobs/${jobSn}:execute`
|
|
277
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeOrders/${changeOrderSn}/jobs/${jobSn}:execute`;
|
|
278
|
+
const response = await yunxiaoRequest(url, {
|
|
279
|
+
method: 'PUT',
|
|
280
|
+
body: action,
|
|
281
|
+
});
|
|
282
|
+
return ExecuteJobActionResponseSchema.parse(response);
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* List change orders by origin
|
|
290
|
+
*
|
|
291
|
+
* @param params - The request parameters
|
|
292
|
+
* @returns The list of change orders
|
|
293
|
+
*/
|
|
294
|
+
export async function listChangeOrdersByOrigin(params) {
|
|
295
|
+
const { organizationId, originType, originId, appName, envName } = params;
|
|
296
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
297
|
+
try {
|
|
298
|
+
const query = {
|
|
299
|
+
originType,
|
|
300
|
+
originId
|
|
301
|
+
};
|
|
302
|
+
if (appName) {
|
|
303
|
+
query.appName = appName;
|
|
304
|
+
}
|
|
305
|
+
if (envName) {
|
|
306
|
+
query.envName = envName;
|
|
307
|
+
}
|
|
308
|
+
const baseUrl = isRegionEdition()
|
|
309
|
+
? `/oapi/v1/appstack/changeOrders:byOrigin`
|
|
310
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/changeOrders:byOrigin`;
|
|
311
|
+
const url = buildUrl(baseUrl, query);
|
|
312
|
+
const response = await yunxiaoRequest(url, {
|
|
313
|
+
method: 'GET',
|
|
314
|
+
});
|
|
315
|
+
return ListChangeOrdersByOriginResponseSchema.parse(response);
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { yunxiaoRequest, buildUrl, isRegionEdition } from '../../common/utils.js';
|
|
3
|
+
import { resolveOrganizationId } from '../organization/organization.js';
|
|
4
|
+
// Define the referenced schemas based on their definitions in appstack.swagger.json
|
|
5
|
+
const AuditItemSchema = z.object({
|
|
6
|
+
auditOrderSn: z.string().optional(),
|
|
7
|
+
refSn: z.string(),
|
|
8
|
+
refType: z.enum(["CR"]),
|
|
9
|
+
state: z.string(),
|
|
10
|
+
type: z.enum(["CODE_SPLC", "CODE_REVIEW"]),
|
|
11
|
+
}).describe("审批项");
|
|
12
|
+
const StageMetadataCommitVOSchema = z.object({
|
|
13
|
+
committedDate: z.string().describe("提交时间"),
|
|
14
|
+
committerId: z.string().describe("提交人"),
|
|
15
|
+
id: z.string().describe("变更执行记录版本ID"),
|
|
16
|
+
}).describe("变更执行记录版本");
|
|
17
|
+
const ChangeRequestExecutionVOSchema = z.object({
|
|
18
|
+
commit: StageMetadataCommitVOSchema.describe("变更执行记录版本"),
|
|
19
|
+
runNumber: z.string().describe("运行序号"),
|
|
20
|
+
state: z.enum(["RUNNING", "SUCCESS", "FAILED", "CANCELED", "UNKNOWN"]).describe("阶段执行状态"),
|
|
21
|
+
}).describe("变更执行记录");
|
|
22
|
+
const CodeReviewAuditItemSchema = AuditItemSchema.extend({
|
|
23
|
+
auditOrderSn: z.string().optional().describe("审批单编号"),
|
|
24
|
+
commitId: z.string().optional().describe("代码提交 ID"),
|
|
25
|
+
crId: z.string().describe("变更 ID"),
|
|
26
|
+
operatorId: z.string().describe("代码提交人 ID"),
|
|
27
|
+
refSn: z.string().optional(),
|
|
28
|
+
refType: z.string().optional(),
|
|
29
|
+
sourceVersion: z.string().describe("代码来源分支版本"),
|
|
30
|
+
state: z.string().describe("审批状态"),
|
|
31
|
+
targetVersion: z.string().describe("代码目标分支版本"),
|
|
32
|
+
type: z.string().describe("审批类型"),
|
|
33
|
+
url: z.string().optional().describe("代码提交 URL"),
|
|
34
|
+
}).describe("代码审核审批项");
|
|
35
|
+
const CodeSplcAuditItemSchema = AuditItemSchema.extend({
|
|
36
|
+
auditOrderSn: z.string().optional().describe("审批单编号"),
|
|
37
|
+
commitDate: z.string().describe("提交时间"),
|
|
38
|
+
commitEmployeeId: z.string().describe("提交人"),
|
|
39
|
+
commitMsg: z.string().optional().describe("提交信息"),
|
|
40
|
+
crId: z.string().describe("变更 ID"),
|
|
41
|
+
refSn: z.string().optional(),
|
|
42
|
+
refType: z.string().optional(),
|
|
43
|
+
state: z.string().describe("审批状态"),
|
|
44
|
+
trunkVersion: z.string().describe("主干版本"),
|
|
45
|
+
type: z.string().describe("审批类型"),
|
|
46
|
+
url: z.string().optional().describe("提交地址"),
|
|
47
|
+
version: z.string().describe("变更版本"),
|
|
48
|
+
}).describe("代码扫描审批项");
|
|
49
|
+
// Schema for the CreateChangeRequest API
|
|
50
|
+
export const CreateChangeRequestRequestSchema = z.object({
|
|
51
|
+
organizationId: z.string().describe("组织ID"),
|
|
52
|
+
appName: z.string().describe("应用名"),
|
|
53
|
+
appCodeRepoSn: z.string().describe("应用代码仓库标识符"),
|
|
54
|
+
autoDeleteBranchWhenEnd: z.boolean().describe("变更结束时候是否自动删除分支"),
|
|
55
|
+
branchName: z.string().describe("应用代码分支名称"),
|
|
56
|
+
createBranch: z.boolean().describe("是否创建分支"),
|
|
57
|
+
ownerAccountId: z.string().optional().describe("变更负责人账号"),
|
|
58
|
+
ownerId: z.string().optional().describe("变更负责人"),
|
|
59
|
+
title: z.string().describe("变更标题"),
|
|
60
|
+
});
|
|
61
|
+
export const CreateChangeRequestResponseSchema = z.object({
|
|
62
|
+
appCodeRepoSn: z.string().optional().describe("代码仓库唯一标识"),
|
|
63
|
+
appName: z.string().describe("应用名"),
|
|
64
|
+
autoDeleteBranchWhenEnd: z.boolean().describe("结束后是否自动删除分支"),
|
|
65
|
+
branch: z.string().optional().describe("变更代码分支"),
|
|
66
|
+
creatorAccountId: z.string().optional().describe("创建者的阿里云账号pk"),
|
|
67
|
+
creatorId: z.string().optional().describe("创建者者云效id"),
|
|
68
|
+
gmtCreate: z.string().describe("创建时间"),
|
|
69
|
+
gmtModified: z.string().describe("修改时间"),
|
|
70
|
+
name: z.string().optional().describe("变更名称"),
|
|
71
|
+
originBranch: z.string().optional().describe("代码分支源分支"),
|
|
72
|
+
originBranchRevisionSha: z.string().optional().describe("代码分支源分支版本"),
|
|
73
|
+
ownerAccountId: z.string().optional().describe("拥有者的阿里云账号pk"),
|
|
74
|
+
ownerId: z.string().optional().describe("拥有者ID"),
|
|
75
|
+
sn: z.string().describe("唯一标识符"),
|
|
76
|
+
state: z.string().describe("状态"),
|
|
77
|
+
type: z.string().describe("变更类型"),
|
|
78
|
+
});
|
|
79
|
+
// Schema for the GetChangeRequestAuditItems API
|
|
80
|
+
export const GetChangeRequestAuditItemsRequestSchema = z.object({
|
|
81
|
+
organizationId: z.string().describe("组织ID"),
|
|
82
|
+
appName: z.string().describe("应用名"),
|
|
83
|
+
sn: z.string().describe("变更标识符"),
|
|
84
|
+
refType: z.string().describe("关联类型"),
|
|
85
|
+
});
|
|
86
|
+
export const GetChangeRequestAuditItemsResponseSchema = z.array(z.union([
|
|
87
|
+
CodeReviewAuditItemSchema,
|
|
88
|
+
CodeSplcAuditItemSchema
|
|
89
|
+
]));
|
|
90
|
+
// Schema for the ListChangeRequestExecutions API
|
|
91
|
+
export const ListChangeRequestExecutionsRequestSchema = z.object({
|
|
92
|
+
organizationId: z.string().describe("组织ID"),
|
|
93
|
+
appName: z.string().describe("应用名"),
|
|
94
|
+
sn: z.string().describe("变更标识符"),
|
|
95
|
+
perPage: z.number().min(1).max(100).default(20).optional().describe("分页尺寸参数,决定一页最多返回多少对象"),
|
|
96
|
+
page: z.number().optional().describe("页面分页时使用,用于获取下一页内容,默认第1页"),
|
|
97
|
+
orderBy: z.enum(["id", "gmtCreate"]).optional().describe("分页排序属性,决定根据何种属性进行记录排序;推荐在实现严格遍历时,使用 id 属性"),
|
|
98
|
+
sort: z.enum(["asc", "desc"]).optional().describe("分页排序升降序,asc 为升序,desc 为降序;推荐在实现严格遍历时,使用升序"),
|
|
99
|
+
releaseWorkflowSn: z.string().describe("流程唯一标识"),
|
|
100
|
+
releaseStageSn: z.string().describe("阶段唯一标识"),
|
|
101
|
+
});
|
|
102
|
+
export const ListChangeRequestExecutionsResponseSchema = z.object({
|
|
103
|
+
current: z.number().describe("当前页数"),
|
|
104
|
+
pageSize: z.number().describe("每页大小"),
|
|
105
|
+
pages: z.number().describe("总页数"),
|
|
106
|
+
records: z.array(ChangeRequestExecutionVOSchema).describe("数据列表"),
|
|
107
|
+
total: z.number().describe("总数"),
|
|
108
|
+
});
|
|
109
|
+
// Schema for the ListChangeRequestWorkItems API
|
|
110
|
+
export const ListChangeRequestWorkItemsRequestSchema = z.object({
|
|
111
|
+
organizationId: z.string().describe("组织ID"),
|
|
112
|
+
appName: z.string().describe("应用名"),
|
|
113
|
+
sn: z.string().describe("变更标识符"),
|
|
114
|
+
});
|
|
115
|
+
export const ListChangeRequestWorkItemsResponseSchema = z.array(z.object({
|
|
116
|
+
description: z.string().optional().describe("变更工作项描述"),
|
|
117
|
+
name: z.string().optional().describe("变更工作项名称"),
|
|
118
|
+
sn: z.string().optional().describe("变更工作项唯一标识"),
|
|
119
|
+
type: z.string().optional().describe("变更工作项类型"),
|
|
120
|
+
value: z.string().optional().describe("变更工作项内容"),
|
|
121
|
+
}));
|
|
122
|
+
// Schema for the CancelChangeRequest API
|
|
123
|
+
export const CancelChangeRequestRequestSchema = z.object({
|
|
124
|
+
organizationId: z.string().describe("组织ID"),
|
|
125
|
+
appName: z.string().describe("应用名"),
|
|
126
|
+
sn: z.string().describe("变更标识符"),
|
|
127
|
+
});
|
|
128
|
+
export const CancelChangeRequestResponseSchema = z.boolean().describe("调用是否成功");
|
|
129
|
+
// Schema for the CloseChangeRequest API
|
|
130
|
+
export const CloseChangeRequestRequestSchema = z.object({
|
|
131
|
+
organizationId: z.string().describe("组织ID"),
|
|
132
|
+
appName: z.string().describe("应用名"),
|
|
133
|
+
sn: z.string().describe("变更标识符"),
|
|
134
|
+
});
|
|
135
|
+
export const CloseChangeRequestResponseSchema = z.boolean().describe("调用是否成功");
|
|
136
|
+
/**
|
|
137
|
+
* Create a change request
|
|
138
|
+
*
|
|
139
|
+
* @param params - The request parameters
|
|
140
|
+
* @returns The created change request
|
|
141
|
+
*/
|
|
142
|
+
export async function createChangeRequest(params) {
|
|
143
|
+
const { organizationId, appName, ...body } = params;
|
|
144
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
145
|
+
try {
|
|
146
|
+
const url = isRegionEdition()
|
|
147
|
+
? `/oapi/v1/appstack/apps/${appName}/changeRequests`
|
|
148
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeRequests`;
|
|
149
|
+
const response = await yunxiaoRequest(url, {
|
|
150
|
+
method: 'POST',
|
|
151
|
+
body: body,
|
|
152
|
+
});
|
|
153
|
+
return CreateChangeRequestResponseSchema.parse(response);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get audit items for a change request
|
|
161
|
+
*
|
|
162
|
+
* @param params - The request parameters
|
|
163
|
+
* @returns The list of audit items
|
|
164
|
+
*/
|
|
165
|
+
export async function getChangeRequestAuditItems(params) {
|
|
166
|
+
const { organizationId, appName, sn, refType } = params;
|
|
167
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
168
|
+
// Build query string properly
|
|
169
|
+
const query = {};
|
|
170
|
+
if (refType)
|
|
171
|
+
query.refType = refType;
|
|
172
|
+
try {
|
|
173
|
+
const baseUrl = isRegionEdition()
|
|
174
|
+
? `/oapi/v1/appstack/apps/${appName}/changeRequests/${sn}/auditItems`
|
|
175
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeRequests/${sn}/auditItems`;
|
|
176
|
+
const url = buildUrl(baseUrl, query);
|
|
177
|
+
const response = await yunxiaoRequest(url, {
|
|
178
|
+
method: 'GET',
|
|
179
|
+
});
|
|
180
|
+
return GetChangeRequestAuditItemsResponseSchema.parse(response);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* List change request executions
|
|
188
|
+
*
|
|
189
|
+
* @param params - The request parameters
|
|
190
|
+
* @returns The list of change request executions
|
|
191
|
+
*/
|
|
192
|
+
export async function listChangeRequestExecutions(params) {
|
|
193
|
+
const { organizationId, appName, sn, perPage, page, orderBy, sort, releaseWorkflowSn, releaseStageSn } = params;
|
|
194
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
195
|
+
// Build query string properly
|
|
196
|
+
const query = {};
|
|
197
|
+
if (perPage !== undefined)
|
|
198
|
+
query.perPage = perPage;
|
|
199
|
+
if (page !== undefined)
|
|
200
|
+
query.page = page;
|
|
201
|
+
if (orderBy)
|
|
202
|
+
query.orderBy = orderBy;
|
|
203
|
+
if (sort)
|
|
204
|
+
query.sort = sort;
|
|
205
|
+
if (releaseWorkflowSn)
|
|
206
|
+
query.releaseWorkflowSn = releaseWorkflowSn;
|
|
207
|
+
if (releaseStageSn)
|
|
208
|
+
query.releaseStageSn = releaseStageSn;
|
|
209
|
+
try {
|
|
210
|
+
const baseUrl = isRegionEdition()
|
|
211
|
+
? `/oapi/v1/appstack/apps/${appName}/changeRequests/${sn}/executions`
|
|
212
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeRequests/${sn}/executions`;
|
|
213
|
+
const url = buildUrl(baseUrl, query);
|
|
214
|
+
const response = await yunxiaoRequest(url, {
|
|
215
|
+
method: 'GET',
|
|
216
|
+
});
|
|
217
|
+
return ListChangeRequestExecutionsResponseSchema.parse(response);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* List work items for a change request
|
|
225
|
+
*
|
|
226
|
+
* @param params - The request parameters
|
|
227
|
+
* @returns The list of work items
|
|
228
|
+
*/
|
|
229
|
+
export async function listChangeRequestWorkItems(params) {
|
|
230
|
+
const { organizationId, appName, sn } = params;
|
|
231
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
232
|
+
try {
|
|
233
|
+
const url = isRegionEdition()
|
|
234
|
+
? `/oapi/v1/appstack/apps/${appName}/changeRequests/${sn}/workItems`
|
|
235
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeRequests/${sn}/workItems`;
|
|
236
|
+
const response = await yunxiaoRequest(url, {
|
|
237
|
+
method: 'GET',
|
|
238
|
+
});
|
|
239
|
+
return ListChangeRequestWorkItemsResponseSchema.parse(response);
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Cancel a change request
|
|
247
|
+
*
|
|
248
|
+
* @param params - The request parameters
|
|
249
|
+
* @returns Whether the cancellation was successful
|
|
250
|
+
*/
|
|
251
|
+
export async function cancelChangeRequest(params) {
|
|
252
|
+
const { organizationId, appName, sn } = params;
|
|
253
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
254
|
+
try {
|
|
255
|
+
const url = isRegionEdition()
|
|
256
|
+
? `/oapi/v1/appstack/apps/${appName}/changeRequests/${sn}:cancel`
|
|
257
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeRequests/${sn}:cancel`;
|
|
258
|
+
const response = await yunxiaoRequest(url, {
|
|
259
|
+
method: 'POST',
|
|
260
|
+
});
|
|
261
|
+
return CancelChangeRequestResponseSchema.parse(response);
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
throw error;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Close a change request
|
|
269
|
+
*
|
|
270
|
+
* @param params - The request parameters
|
|
271
|
+
* @returns Whether the close operation was successful
|
|
272
|
+
*/
|
|
273
|
+
export async function closeChangeRequest(params) {
|
|
274
|
+
const { organizationId, appName, sn } = params;
|
|
275
|
+
const finalOrgId = await resolveOrganizationId(organizationId);
|
|
276
|
+
try {
|
|
277
|
+
const url = isRegionEdition()
|
|
278
|
+
? `/oapi/v1/appstack/apps/${appName}/changeRequests/${sn}:finish`
|
|
279
|
+
: `/oapi/v1/appstack/organizations/${finalOrgId}/apps/${appName}/changeRequests/${sn}:finish`;
|
|
280
|
+
const response = await yunxiaoRequest(url, {
|
|
281
|
+
method: 'POST',
|
|
282
|
+
});
|
|
283
|
+
return CloseChangeRequestResponseSchema.parse(response);
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
}
|