in operations/flow/pipeline.ts [162:271]
export async function createPipelineRunFunc(
organizationId: string,
pipelineId: string,
options?: Partial<Omit<CreatePipelineRunOptions, 'organizationId' | 'pipelineId'>>
): Promise<number> {
const url = `/oapi/v1/flow/organizations/${organizationId}/pipelines/${pipelineId}/runs`;
// 如果用户已经提供了格式化的params,直接使用
if (options?.params) {
const body = {
params: options.params
};
const response = await utils.yunxiaoRequest(url, {
method: "POST",
body: body,
});
return Number(response);
}
// 否则,基于用户提供的自然语言参数构建params
const paramsObject: Record<string, any> = {};
// 处理分支模式相关参数
if (options?.branchMode && options?.branches && options.branches.length > 0) {
paramsObject.branchModeBranchs = options.branches;
}
// 处理Release分支相关参数
if (options?.createReleaseBranch !== undefined) {
paramsObject.needCreateBranch = options.createReleaseBranch;
}
if (options?.releaseBranch) {
paramsObject.releaseBranch = options.releaseBranch;
}
// 处理环境变量
if (options?.environmentVariables && Object.keys(options.environmentVariables).length > 0) {
paramsObject.envs = options.environmentVariables;
}
// 处理特定仓库配置
if (options?.repositories && options.repositories.length > 0) {
// 初始化runningBranchs和runningTags对象
const runningBranchs: Record<string, string> = {};
const runningTags: Record<string, string> = {};
// 填充分支和标签信息
options.repositories.forEach(repo => {
if (repo.branch) {
runningBranchs[repo.url] = repo.branch;
}
if (repo.tag) {
runningTags[repo.url] = repo.tag;
}
});
// 只有在有内容时才添加到params对象
if (Object.keys(runningBranchs).length > 0) {
paramsObject.runningBranchs = runningBranchs;
}
if (Object.keys(runningTags).length > 0) {
paramsObject.runningTags = runningTags;
}
}
// 如果有自然语言描述,尝试解析它
if (options?.description) {
// 此处可以添加更复杂的自然语言处理逻辑
// 当前实现是简单的关键词匹配
const description = options.description.toLowerCase();
// 检测分支模式
if ((description.includes('branch mode') || description.includes('分支模式')) &&
!paramsObject.branchModeBranchs &&
options?.branches?.length) {
paramsObject.branchModeBranchs = options.branches;
}
// 检测是否需要创建release分支
if ((description.includes('create release') || description.includes('创建release')) &&
paramsObject.needCreateBranch === undefined) {
paramsObject.needCreateBranch = true;
}
// 如果提到特定release分支但没有指定
if ((description.includes('release branch') || description.includes('release分支')) &&
!paramsObject.releaseBranch &&
options?.branches?.length) {
// 假设第一个分支就是release分支
paramsObject.releaseBranch = options.branches[0];
}
}
const body: Record<string, any> = {};
if (Object.keys(paramsObject).length > 0) {
body.params = JSON.stringify(paramsObject);
}
const response = await utils.yunxiaoRequest(url, {
method: "POST",
body: body,
});
return Number(response);
}