@taole/deploy-helper 1.0.2 → 1.0.4

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.
Files changed (32) hide show
  1. package/README.md +1 -4
  2. package/index.mjs +2 -39
  3. package/lib/pipelineApi.mjs +17 -16
  4. package/lib/util.mjs +0 -40
  5. package/lib/yunxiaoFlowApi.mjs +115 -0
  6. package/package.json +4 -7
  7. package/lib/offlinePkg.mjs +0 -333
  8. package/lib/upload.js +0 -49
  9. package/modules/alibabacloud-devops-mcp-server/dist/common/errors.js +0 -69
  10. package/modules/alibabacloud-devops-mcp-server/dist/common/modularTemplates.js +0 -483
  11. package/modules/alibabacloud-devops-mcp-server/dist/common/pipelineTemplates.js +0 -19
  12. package/modules/alibabacloud-devops-mcp-server/dist/common/types.js +0 -1119
  13. package/modules/alibabacloud-devops-mcp-server/dist/common/utils.js +0 -353
  14. package/modules/alibabacloud-devops-mcp-server/dist/common/version.js +0 -1
  15. package/modules/alibabacloud-devops-mcp-server/dist/index.js +0 -1067
  16. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/branches.js +0 -144
  17. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/changeRequestComments.js +0 -89
  18. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/changeRequests.js +0 -203
  19. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/compare.js +0 -26
  20. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/files.js +0 -233
  21. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/repositories.js +0 -64
  22. package/modules/alibabacloud-devops-mcp-server/dist/operations/flow/hostGroup.js +0 -48
  23. package/modules/alibabacloud-devops-mcp-server/dist/operations/flow/pipeline.js +0 -514
  24. package/modules/alibabacloud-devops-mcp-server/dist/operations/flow/pipelineJob.js +0 -113
  25. package/modules/alibabacloud-devops-mcp-server/dist/operations/flow/serviceConnection.js +0 -23
  26. package/modules/alibabacloud-devops-mcp-server/dist/operations/organization/members.js +0 -94
  27. package/modules/alibabacloud-devops-mcp-server/dist/operations/organization/organization.js +0 -73
  28. package/modules/alibabacloud-devops-mcp-server/dist/operations/packages/artifacts.js +0 -64
  29. package/modules/alibabacloud-devops-mcp-server/dist/operations/packages/repositories.js +0 -35
  30. package/modules/alibabacloud-devops-mcp-server/dist/operations/projex/project.js +0 -206
  31. package/modules/alibabacloud-devops-mcp-server/dist/operations/projex/sprint.js +0 -30
  32. package/modules/alibabacloud-devops-mcp-server/dist/operations/projex/workitem.js +0 -264
@@ -1,514 +0,0 @@
1
- import * as utils from "../../common/utils.js";
2
- import { PipelineDetailSchema, PipelineListItemSchema, PipelineRunSchema, PipelineRunListItemSchema } from "../../common/types.js";
3
- import { generateModularPipeline } from "../../common/modularTemplates.js";
4
- import { listServiceConnectionsFunc } from "./serviceConnection.js";
5
- /**
6
- * 获取流水线详情
7
- * @param organizationId 组织ID
8
- * @param pipelineId 流水线ID
9
- * @returns 流水线详情
10
- */
11
- export async function getPipelineFunc(organizationId, pipelineId) {
12
- const url = `/oapi/v1/flow/organizations/${organizationId}/pipelines/${pipelineId}`;
13
- const response = await utils.yunxiaoRequest(url, {
14
- method: "GET",
15
- });
16
- return PipelineDetailSchema.parse(response);
17
- }
18
- /**
19
- * 获取流水线列表
20
- * @param organizationId 组织ID
21
- * @param options 查询选项
22
- * @returns 流水线列表
23
- */
24
- export async function listPipelinesFunc(organizationId, options) {
25
- const baseUrl = `/oapi/v1/flow/organizations/${organizationId}/pipelines`;
26
- // 构建查询参数
27
- const queryParams = {};
28
- // 处理时间戳参数
29
- // 如果传入的是日期字符串或Date对象,自动转换为毫秒时间戳
30
- if (options?.createStartTime !== undefined) {
31
- queryParams.createStartTime = utils.convertToTimestamp(options.createStartTime);
32
- }
33
- if (options?.createEndTime !== undefined) {
34
- queryParams.createEndTime = utils.convertToTimestamp(options.createEndTime);
35
- }
36
- if (options?.executeStartTime !== undefined) {
37
- queryParams.executeStartTime = utils.convertToTimestamp(options.executeStartTime);
38
- }
39
- if (options?.executeEndTime !== undefined) {
40
- queryParams.executeEndTime = utils.convertToTimestamp(options.executeEndTime);
41
- }
42
- if (options?.pipelineName !== undefined) {
43
- queryParams.pipelineName = options.pipelineName;
44
- }
45
- if (options?.statusList !== undefined) {
46
- queryParams.statusList = options.statusList;
47
- }
48
- if (options?.perPage !== undefined) {
49
- queryParams.perPage = options.perPage;
50
- }
51
- if (options?.page !== undefined) {
52
- queryParams.page = options.page;
53
- }
54
- const url = utils.buildUrl(baseUrl, queryParams);
55
- let response = await utils.yunxiaoRequest(url, {
56
- method: "GET",
57
- });
58
- const pagination = {
59
- nextPage: null,
60
- page: 1,
61
- perPage: 10,
62
- prevPage: null,
63
- total: 0,
64
- totalPages: 0
65
- };
66
- let items = [];
67
- if (Array.isArray(response)) {
68
- response = response.map((item) => ({
69
- ...item,
70
- id: item.id || item.pipelineId,
71
- name: item.name || item.pipelineName,
72
- creatorAccountId: item.creatorAccountId || item.createAccountId,
73
- createTime: item.createTime || item.createTime,
74
- }))
75
- items = response.map(item => PipelineListItemSchema.parse(item));
76
- }
77
- return {
78
- items,
79
- pagination
80
- };
81
- }
82
- /**
83
- * 智能查询流水线列表,能够解析自然语言中的时间表达
84
- * @param organizationId 组织ID
85
- * @param timeReference 自然语言时间引用,如"今天"、"本周"、"上个月"
86
- * @param options 其他查询选项
87
- * @returns 流水线列表
88
- */
89
- export async function smartListPipelinesFunc(organizationId, timeReference, options) {
90
- // 解析时间引用获取开始和结束时间戳
91
- const { startTime, endTime } = utils.parseDateReference(timeReference);
92
- // 合并选项
93
- const fullOptions = {
94
- ...options,
95
- executeStartTime: startTime,
96
- executeEndTime: endTime
97
- };
98
- return listPipelinesFunc(organizationId, fullOptions);
99
- }
100
- /**
101
- * 运行流水线
102
- * @param organizationId 组织ID
103
- * @param pipelineId 流水线ID
104
- * @param options 运行选项,可以是直接的JSON字符串或者自然语言描述的选项
105
- * @returns 流水线运行ID
106
- */
107
- export async function createPipelineRunFunc(organizationId, pipelineId, options) {
108
- const url = `/oapi/v1/flow/organizations/${organizationId}/pipelines/${pipelineId}/runs`;
109
- // 如果用户已经提供了格式化的params,直接使用
110
- if (options?.params) {
111
- const body = {
112
- params: options.params
113
- };
114
- const response = await utils.yunxiaoRequest(url, {
115
- method: "POST",
116
- body: body,
117
- });
118
- return Number(response);
119
- }
120
- // 否则,基于用户提供的自然语言参数构建params
121
- const paramsObject = {};
122
- // 处理分支模式相关参数
123
- if (options?.branchMode && options?.branches && options.branches.length > 0) {
124
- paramsObject.branchModeBranchs = options.branches;
125
- }
126
- // 处理Release分支相关参数
127
- if (options?.createReleaseBranch !== undefined) {
128
- paramsObject.needCreateBranch = options.createReleaseBranch;
129
- }
130
- if (options?.releaseBranch) {
131
- paramsObject.releaseBranch = options.releaseBranch;
132
- }
133
- // 处理环境变量
134
- if (options?.environmentVariables && Object.keys(options.environmentVariables).length > 0) {
135
- paramsObject.envs = options.environmentVariables;
136
- }
137
- // 处理特定仓库配置
138
- if (options?.repositories && options.repositories.length > 0) {
139
- // 初始化runningBranchs和runningTags对象
140
- const runningBranchs = {};
141
- const runningTags = {};
142
- // 填充分支和标签信息
143
- options.repositories.forEach(repo => {
144
- if (repo.branch) {
145
- runningBranchs[repo.url] = repo.branch;
146
- }
147
- if (repo.tag) {
148
- runningTags[repo.url] = repo.tag;
149
- }
150
- });
151
- // 只有在有内容时才添加到params对象
152
- if (Object.keys(runningBranchs).length > 0) {
153
- paramsObject.runningBranchs = runningBranchs;
154
- }
155
- if (Object.keys(runningTags).length > 0) {
156
- paramsObject.runningTags = runningTags;
157
- }
158
- }
159
- // 如果有自然语言描述,尝试解析它
160
- if (options?.description) {
161
- // 此处可以添加更复杂的自然语言处理逻辑
162
- // 当前实现是简单的关键词匹配
163
- const description = options.description.toLowerCase();
164
- // 检测分支模式
165
- if ((description.includes('branch mode') || description.includes('分支模式')) &&
166
- !paramsObject.branchModeBranchs &&
167
- options?.branches?.length) {
168
- paramsObject.branchModeBranchs = options.branches;
169
- }
170
- // 检测是否需要创建release分支
171
- if ((description.includes('create release') || description.includes('创建release')) &&
172
- paramsObject.needCreateBranch === undefined) {
173
- paramsObject.needCreateBranch = true;
174
- }
175
- // 如果提到特定release分支但没有指定
176
- if ((description.includes('release branch') || description.includes('release分支')) &&
177
- !paramsObject.releaseBranch &&
178
- options?.branches?.length) {
179
- // 假设第一个分支就是release分支
180
- paramsObject.releaseBranch = options.branches[0];
181
- }
182
- }
183
- const body = {};
184
- if (Object.keys(paramsObject).length > 0) {
185
- body.params = JSON.stringify(paramsObject);
186
- }
187
- const response = await utils.yunxiaoRequest(url, {
188
- method: "POST",
189
- body: body,
190
- });
191
- return Number(response);
192
- }
193
- /**
194
- * 获取最近一次流水线运行信息
195
- * @param organizationId 组织ID
196
- * @param pipelineId 流水线ID
197
- * @returns 最近一次流水线运行信息
198
- */
199
- export async function getLatestPipelineRunFunc(organizationId, pipelineId) {
200
- const url = `/oapi/v1/flow/organizations/${organizationId}/pipelines/${pipelineId}/runs/latestPipelineRun`;
201
- const response = await utils.yunxiaoRequest(url, {
202
- method: "GET",
203
- });
204
- return PipelineRunSchema.parse(response);
205
- }
206
- /**
207
- * 获取特定流水线运行实例
208
- * @param organizationId 组织ID
209
- * @param pipelineId 流水线ID
210
- * @param pipelineRunId 流水线运行ID
211
- * @returns 流水线运行实例信息
212
- */
213
- export async function getPipelineRunFunc(organizationId, pipelineId, pipelineRunId) {
214
- const url = `/oapi/v1/flow/organizations/${organizationId}/pipelines/${pipelineId}/runs/${pipelineRunId}`;
215
- const response = await utils.yunxiaoRequest(url, {
216
- method: "GET",
217
- });
218
- return PipelineRunSchema.parse(response);
219
- }
220
- /**
221
- * 获取流水线运行实例列表
222
- * @param organizationId 组织ID
223
- * @param pipelineId 流水线ID
224
- * @param options 查询选项
225
- * @returns 流水线运行实例列表和分页信息
226
- */
227
- export async function listPipelineRunsFunc(organizationId, pipelineId, options) {
228
- const baseUrl = `/oapi/v1/flow/organizations/${organizationId}/pipelines/${pipelineId}/runs`;
229
- // 构建查询参数
230
- const queryParams = {};
231
- if (options?.perPage !== undefined) {
232
- queryParams.perPage = options.perPage;
233
- }
234
- if (options?.page !== undefined) {
235
- queryParams.page = options.page;
236
- }
237
- if (options?.startTime !== undefined) {
238
- queryParams.startTime = utils.convertToTimestamp(options.startTime);
239
- }
240
- if (options?.endTime !== undefined) {
241
- queryParams.endTme = utils.convertToTimestamp(options.endTime);
242
- }
243
- if (options?.status !== undefined) {
244
- queryParams.status = options.status;
245
- }
246
- if (options?.triggerMode !== undefined) {
247
- queryParams.triggerMode = options.triggerMode;
248
- }
249
- const url = utils.buildUrl(baseUrl, queryParams);
250
- const response = await utils.yunxiaoRequest(url, {
251
- method: "GET",
252
- });
253
- const pagination = {
254
- nextPage: null,
255
- page: options?.page ?? 1,
256
- perPage: options?.perPage ?? 10,
257
- prevPage: null,
258
- total: 0,
259
- totalPages: 0
260
- };
261
- let items = [];
262
- if (Array.isArray(response)) {
263
- items = response.map(item => PipelineRunListItemSchema.parse(item));
264
- }
265
- return {
266
- items,
267
- pagination
268
- };
269
- }
270
- /**
271
- * 创建流水线
272
- * @param organizationId 组织ID
273
- * @param name 流水线名称
274
- * @param content 流水线YAML描述
275
- * @returns 流水线ID
276
- */
277
- export async function createPipelineFunc(organizationId, name, content) {
278
- const url = `/oapi/v1/flow/organizations/${organizationId}/pipelines`;
279
- const body = {
280
- name: name,
281
- content: content
282
- };
283
- const response = await utils.yunxiaoRequest(url, {
284
- method: "POST",
285
- body: body,
286
- });
287
- return Number(response);
288
- }
289
- /**
290
- * 基于结构化参数生成流水线YAML(不创建流水线)
291
- * @param options 结构化的流水线配置选项
292
- * @returns 生成的YAML字符串
293
- */
294
- export async function generatePipelineYamlFunc(options) {
295
- // 自动从repoUrl解析serviceName(如果用户没有明确指定)
296
- let derivedServiceName = options.serviceName;
297
- if (!derivedServiceName && options.repoUrl) {
298
- // 从Git URL中提取项目名称
299
- // 支持格式: git@codeup.aliyun.com:org/repo.git 或 https://codeup.aliyun.com/org/repo.git
300
- const repoUrlMatch = options.repoUrl.match(/[\/:]([^\/]+)\.git$/);
301
- if (repoUrlMatch) {
302
- derivedServiceName = repoUrlMatch[1];
303
- }
304
- }
305
- // 准备变量,确保版本号有双引号
306
- const variables = {
307
- // 基础配置
308
- ...(options.repoUrl && { repoUrl: options.repoUrl }),
309
- ...(options.branch && { branch: options.branch }),
310
- ...(derivedServiceName && { serviceName: derivedServiceName }),
311
- ...(options.serviceConnectionId && { serviceConnectionId: options.serviceConnectionId }),
312
- ...(options.packagesServiceConnection && { packagesServiceConnection: options.packagesServiceConnection }),
313
- ...(options.machineGroupId && { machineGroupId: options.machineGroupId }),
314
- ...(options.namespace && { namespace: options.namespace }),
315
- ...(options.dockerImage && { dockerImage: options.dockerImage }),
316
- // 版本相关(确保双引号)
317
- ...(options.jdkVersion && { jdkVersion: `"${options.jdkVersion}"` }),
318
- ...(options.mavenVersion && { mavenVersion: `"${options.mavenVersion}"` }),
319
- ...(options.nodeVersion && { nodeVersion: `"${options.nodeVersion}"` }),
320
- ...(options.pythonVersion && { pythonVersion: `"${options.pythonVersion}"` }),
321
- ...(options.goVersion && { goVersion: `"${options.goVersion}"` }),
322
- ...(options.kubectlVersion && { kubectlVersion: `"${options.kubectlVersion}"` }),
323
- // 构建物上传相关
324
- ...(options.uploadType && { uploadType: options.uploadType }),
325
- ...(options.artifactName && { artifactName: options.artifactName }),
326
- ...(options.artifactVersion && { artifactVersion: options.artifactVersion }),
327
- ...(options.packagesRepoId && { packagesRepoId: options.packagesRepoId }),
328
- ...(options.includePathInArtifact !== undefined && { includePathInArtifact: options.includePathInArtifact }),
329
- // 部署相关
330
- ...(options.executeUser && { executeUser: options.executeUser }),
331
- ...(options.artifactDownloadPath && { artifactDownloadPath: options.artifactDownloadPath }),
332
- ...(options.kubernetesClusterId && { kubernetesClusterId: options.kubernetesClusterId }),
333
- ...(options.yamlPath && { yamlPath: options.yamlPath }),
334
- // 命令
335
- ...(options.buildCommand && { buildCommand: options.buildCommand }),
336
- ...(options.testCommand && { testCommand: options.testCommand }),
337
- ...(options.deployCommand && { deployCommand: options.deployCommand }),
338
- };
339
- // 转换为模块化流水线选项
340
- const deployTargets = options.deployTarget ? [options.deployTarget] : [];
341
- // 使用模块化架构生成YAML
342
- return generateModularPipeline({
343
- keywords: [options.buildLanguage, options.buildTool],
344
- buildLanguages: [options.buildLanguage],
345
- buildTools: [options.buildTool],
346
- deployTargets: deployTargets,
347
- uploadType: options.uploadType || 'packages',
348
- variables: variables
349
- });
350
- }
351
- /**
352
- * 基于结构化参数创建流水线
353
- * @param organizationId 组织ID
354
- * @param options 结构化的流水线配置选项
355
- * @returns 创建结果,包含流水线ID和生成的YAML
356
- */
357
- export async function createPipelineWithOptionsFunc(organizationId, options) {
358
- // 获取默认服务连接ID(如果用户没有明确指定)
359
- let defaultServiceConnectionId = null;
360
- const hasServiceConnectionId = options.serviceConnectionId;
361
- if (!hasServiceConnectionId) {
362
- defaultServiceConnectionId = await getDefaultServiceConnectionId(organizationId);
363
- }
364
- // 获取默认Packages服务连接ID(如果用户没有明确指定且需要packages上传)
365
- let defaultPackagesServiceConnectionId = null;
366
- const hasPackagesServiceConnectionId = options.packagesServiceConnection;
367
- const needsPackagesUpload = !options.uploadType || options.uploadType === 'packages';
368
- if (!hasPackagesServiceConnectionId && needsPackagesUpload) {
369
- defaultPackagesServiceConnectionId = await getDefaultPackagesServiceConnectionId(organizationId);
370
- }
371
- // 获取默认主机组ID(如果用户没有明确指定且需要VM部署)
372
- let defaultMachineGroupId = null;
373
- const hasMachineGroupId = options.machineGroupId;
374
- const needsVMDeploy = options.deployTarget === 'vm';
375
- if (!hasMachineGroupId && needsVMDeploy) {
376
- defaultMachineGroupId = await getDefaultHostGroupId(organizationId);
377
- }
378
- // 自动从repoUrl解析serviceName(如果用户没有明确指定)
379
- let derivedServiceName = options.serviceName;
380
- if (!derivedServiceName && options.repoUrl) {
381
- // 从Git URL中提取项目名称
382
- // 支持格式: git@codeup.aliyun.com:org/repo.git 或 https://codeup.aliyun.com/org/repo.git
383
- const repoUrlMatch = options.repoUrl.match(/[\/:]([^\/]+)\.git$/);
384
- if (repoUrlMatch) {
385
- derivedServiceName = repoUrlMatch[1];
386
- }
387
- }
388
- // 准备模块化流水线生成的变量
389
- const finalVariables = {
390
- // 基础配置(直接使用用户提供的值)
391
- ...(options.repoUrl && { repoUrl: options.repoUrl }),
392
- ...(options.branch && { branch: options.branch }),
393
- ...(derivedServiceName && { serviceName: derivedServiceName }),
394
- // 使用获取到的默认服务连接ID
395
- ...(defaultServiceConnectionId && !hasServiceConnectionId && { serviceConnectionId: defaultServiceConnectionId }),
396
- // 使用获取到的默认Packages服务连接ID
397
- ...(defaultPackagesServiceConnectionId && !hasPackagesServiceConnectionId && { packagesServiceConnection: defaultPackagesServiceConnectionId }),
398
- // 使用获取到的默认主机组ID
399
- ...(defaultMachineGroupId && !hasMachineGroupId && { machineGroupId: defaultMachineGroupId }),
400
- // 用户明确指定的值优先级最高
401
- ...(options.serviceConnectionId && { serviceConnectionId: options.serviceConnectionId }),
402
- ...(options.packagesServiceConnection && { packagesServiceConnection: options.packagesServiceConnection }),
403
- ...(options.machineGroupId && { machineGroupId: options.machineGroupId }),
404
- ...(options.namespace && { namespace: options.namespace }),
405
- ...(options.dockerImage && { dockerImage: options.dockerImage }),
406
- // 版本相关(确保双引号)
407
- ...(options.jdkVersion && { jdkVersion: `"${options.jdkVersion}"` }),
408
- ...(options.mavenVersion && { mavenVersion: `"${options.mavenVersion}"` }),
409
- ...(options.nodeVersion && { nodeVersion: `"${options.nodeVersion}"` }),
410
- ...(options.pythonVersion && { pythonVersion: `"${options.pythonVersion}"` }),
411
- ...(options.goVersion && { goVersion: `"${options.goVersion}"` }),
412
- ...(options.kubectlVersion && { kubectlVersion: `"${options.kubectlVersion}"` }),
413
- // 构建物上传相关
414
- ...(options.uploadType && { uploadType: options.uploadType }),
415
- ...(options.artifactName && { artifactName: options.artifactName }),
416
- ...(options.artifactVersion && { artifactVersion: options.artifactVersion }),
417
- ...(options.packagesRepoId && { packagesRepoId: options.packagesRepoId }),
418
- ...(options.includePathInArtifact !== undefined && { includePathInArtifact: options.includePathInArtifact }),
419
- // 部署相关
420
- ...(options.executeUser && { executeUser: options.executeUser }),
421
- ...(options.artifactDownloadPath && { artifactDownloadPath: options.artifactDownloadPath }),
422
- ...(options.kubernetesClusterId && { kubernetesClusterId: options.kubernetesClusterId }),
423
- ...(options.yamlPath && { yamlPath: options.yamlPath }),
424
- // 命令
425
- ...(options.buildCommand && { buildCommand: options.buildCommand }),
426
- ...(options.testCommand && { testCommand: options.testCommand }),
427
- ...(options.deployCommand && { deployCommand: options.deployCommand }),
428
- };
429
- // 转换为模块化流水线选项
430
- const deployTargets = options.deployTarget ? [options.deployTarget] : [];
431
- // 使用模块化架构生成YAML
432
- const generatedYaml = generateModularPipeline({
433
- keywords: [options.buildLanguage, options.buildTool],
434
- buildLanguages: [options.buildLanguage],
435
- buildTools: [options.buildTool],
436
- deployTargets: deployTargets,
437
- uploadType: options.uploadType || 'packages',
438
- variables: finalVariables
439
- });
440
- // 创建流水线
441
- try {
442
- const pipelineId = await createPipelineFunc(organizationId, options.name, generatedYaml);
443
- return {
444
- pipelineId,
445
- generatedYaml
446
- };
447
- }
448
- catch (error) {
449
- // 如果是YAML校验失败或其他流水线创建错误,将详细信息透出给用户
450
- console.error('Create pipeline failed:', error);
451
- // 构造包含生成YAML的错误信息,方便用户排查
452
- const errorMessage = error instanceof Error ? error.message : String(error);
453
- const enhancedError = new Error(`Create pipeline failed: ${errorMessage}\n\n` +
454
- `YAML content:\n${generatedYaml}\n\n` +
455
- `Suggestions:\n` +
456
- `1. Check whether the YAML format is correct.\n` +
457
- `2. Verify whether the serviceConnectionID、machineGroupID、kubernetesClusterID and other parameters are existed and valid.`);
458
- // 保持原始错误的堆栈信息
459
- if (error instanceof Error && error.stack) {
460
- enhancedError.stack = error.stack;
461
- }
462
- throw enhancedError;
463
- }
464
- }
465
- /**
466
- * 获取默认的服务连接ID(用于代码源配置)
467
- * @param organizationId 组织ID
468
- * @returns 服务连接ID
469
- */
470
- async function getDefaultServiceConnectionId(organizationId) {
471
- try {
472
- // 获取Codeup类型的服务连接(代码源最常用)
473
- const serviceConnections = await listServiceConnectionsFunc(organizationId, 'codeup');
474
- if (serviceConnections && serviceConnections.length > 0) {
475
- return serviceConnections[0].uuid || null;
476
- }
477
- return null;
478
- }
479
- catch (error) {
480
- console.error('获取Codeup服务连接失败:', error);
481
- return null;
482
- }
483
- }
484
- /**
485
- * 获取默认的Packages服务连接ID(用于制品上传配置)
486
- * @param organizationId 组织ID
487
- * @returns Packages服务连接ID
488
- */
489
- async function getDefaultPackagesServiceConnectionId(organizationId) {
490
- try {
491
- // 获取packages类型的服务连接
492
- const serviceConnections = await listServiceConnectionsFunc(organizationId, 'packages');
493
- if (serviceConnections && serviceConnections.length > 0) {
494
- return serviceConnections[0].uuid || null;
495
- }
496
- return null;
497
- }
498
- catch (error) {
499
- console.error('获取Packages服务连接失败:', error);
500
- return null;
501
- }
502
- }
503
- /**
504
- * 获取默认的主机组ID(用于VM部署配置)
505
- * 注意:由于主机组API只返回数字ID而不是UUID,这个函数暂时不使用
506
- * 用户需要在描述中明确指定主机组UUID
507
- * @param organizationId 组织ID
508
- * @returns null(暂不自动获取)
509
- */
510
- async function getDefaultHostGroupId(organizationId) {
511
- // 暂时不自动获取主机组,因为API只返回数字ID,无法在流水线中使用
512
- // 用户需要在options中明确提供machineGroupId(UUID格式)
513
- return null;
514
- }
@@ -1,113 +0,0 @@
1
- /**
2
- * 流水线任务相关操作
3
- * 提供按照分类获取流水线执行的任务接口
4
- */
5
- import * as utils from "../../common/utils.js";
6
- import { PipelineJobItemSchema, PipelineJobHistoryItemSchema, PipelineJobRunLogSchema } from "../../common/types.js";
7
- /**
8
- * 按任务分类获取流水线执行的任务
9
- * @param organizationId Organization ID(组织ID)
10
- * @param pipelineId Pipeline ID(流水线ID)
11
- * @param category Task category, currently only supports DEPLOY(任务分类,当前仅支持DEPLOY)
12
- * @returns 任务列表
13
- */
14
- export async function listPipelineJobsByCategoryFunc(organizationId, pipelineId, category) {
15
- const url = `/oapi/v1/flow/organizations/${organizationId}/pipelines/${pipelineId}/listTasksByCategory/${category}`;
16
- const response = await utils.yunxiaoRequest(url, {
17
- method: "GET",
18
- });
19
- if (!Array.isArray(response)) {
20
- return [];
21
- }
22
- return response.map(job => PipelineJobItemSchema.parse(job));
23
- }
24
- /**
25
- * 获取流水线任务的执行历史
26
- * @param organizationId Organization ID(组织ID)
27
- * @param pipelineId Pipeline ID(流水线ID)
28
- * @param category Task category, currently only supports DEPLOY(任务分类,当前仅支持DEPLOY)
29
- * @param identifier Task identifier(任务标识)
30
- * @param page Page number, default 1
31
- * @param perPage Number of items per page, default 10, max 30
32
- * @returns Job history list and pagination information
33
- */
34
- export async function listPipelineJobHistorysFunc(organizationId, pipelineId, category, identifier, page = 1, perPage = 10) {
35
- const baseUrl = `/oapi/v1/flow/organizations/${organizationId}/pipelines/getComponentsWithoutButtons`;
36
- const queryParams = {
37
- pipelineId,
38
- category,
39
- identifier,
40
- page,
41
- perPage
42
- };
43
- const url = utils.buildUrl(baseUrl, queryParams);
44
- const response = await utils.yunxiaoRequest(url, {
45
- method: "GET",
46
- });
47
- const pagination = {
48
- nextPage: null,
49
- page: page,
50
- perPage: perPage,
51
- prevPage: null,
52
- total: 0,
53
- totalPages: 0
54
- };
55
- if (response && 'headers' in response) {
56
- const headers = response.headers;
57
- if (headers['x-next-page']) {
58
- pagination.nextPage = parseInt(headers['x-next-page']);
59
- }
60
- if (headers['x-page']) {
61
- pagination.page = parseInt(headers['x-page']);
62
- }
63
- if (headers['x-per-page']) {
64
- pagination.perPage = parseInt(headers['x-per-page']);
65
- }
66
- if (headers['x-prev-page']) {
67
- pagination.prevPage = parseInt(headers['x-prev-page']);
68
- }
69
- if (headers['x-total']) {
70
- pagination.total = parseInt(headers['x-total']);
71
- }
72
- if (headers['x-total-pages']) {
73
- pagination.totalPages = parseInt(headers['x-total-pages']);
74
- }
75
- }
76
- const items = Array.isArray(response)
77
- ? response.map(item => PipelineJobHistoryItemSchema.parse(item))
78
- : [];
79
- return {
80
- items,
81
- pagination
82
- };
83
- }
84
- /**
85
- * 手动运行流水线任务
86
- * @param organizationId Organization ID(组织ID)
87
- * @param pipelineId Pipeline ID(流水线ID)
88
- * @param pipelineRunId Pipeline run instance ID(流水线运行ID)
89
- * @param jobId Job ID for the pipeline run task(流水线运行任务ID)
90
- * @returns Whether the operation was successful
91
- */
92
- export async function executePipelineJobRunFunc(organizationId, pipelineId, pipelineRunId, jobId) {
93
- const url = `/oapi/v1/flow/organizations/${organizationId}/pipelines/${pipelineId}/pipelineRuns/${pipelineRunId}/jobs/${jobId}/start`;
94
- const response = await utils.yunxiaoRequest(url, {
95
- method: "POST",
96
- });
97
- return Boolean(response);
98
- }
99
- /**
100
- * 查询任务运行日志
101
- * @param organizationId Organization ID(组织ID)
102
- * @param pipelineId Pipeline ID(流水线ID)
103
- * @param pipelineRunId Pipeline run instance ID(流水线运行ID)
104
- * @param jobId Job ID of the pipeline run task(流水线运行任务ID)
105
- * @returns Log content and metadata
106
- */
107
- export async function getPipelineJobRunLogFunc(organizationId, pipelineId, pipelineRunId, jobId) {
108
- const url = `/oapi/v1/flow/organizations/${organizationId}/pipelines/${pipelineId}/runs/${pipelineRunId}/job/${jobId}/log`;
109
- const response = await utils.yunxiaoRequest(url, {
110
- method: "GET",
111
- });
112
- return PipelineJobRunLogSchema.parse(response);
113
- }
@@ -1,23 +0,0 @@
1
- import * as utils from "../../common/utils.js";
2
- import { ServiceConnectionSchema } from "../../common/types.js";
3
- /**
4
- * 获取服务连接列表
5
- * @param organizationId 组织ID
6
- * @param serviceConnectionType 服务连接类型
7
- * @returns 服务连接列表
8
- */
9
- export async function listServiceConnectionsFunc(organizationId, serviceConnectionType) {
10
- const baseUrl = `/oapi/v1/flow/organizations/${organizationId}/serviceConnections`;
11
- // 构建查询参数
12
- const queryParams = {
13
- sericeConnectionType: serviceConnectionType // 注意:API文档中拼写为 sericeConnectionType
14
- };
15
- const url = utils.buildUrl(baseUrl, queryParams);
16
- const response = await utils.yunxiaoRequest(url, {
17
- method: "GET",
18
- });
19
- if (!Array.isArray(response)) {
20
- return [];
21
- }
22
- return response.map(item => ServiceConnectionSchema.parse(item));
23
- }