Youtrack跨项目状态联动:Bug DB更新关联Support工单状态
YouTrack Bug DB项目工作流规则优化
问题1:完善守卫条件
原函数仅检查是否存在关联链接,无法验证链接指向的是Support项目工单。修改后的函数会精准校验affects helpdesk log类型的关联工单是否属于Support项目:
const issue_0 = ctx.issue; function hasLinkedSupportIssue() { // 用some()匹配C#的.Any()逻辑,只要存在一个符合条件的关联工单就返回true return issue_0.links['affects helpdesk log'].added.some(linkedIssue => { return linkedIssue.project.key === 'Support'; }); }
问题2:优化状态更新操作
原代码的遍历逻辑和状态赋值方式存在问题,以下是修正后的实现:
状态更新函数修正
YouTrack工作流中不能直接通过赋值修改字段,必须使用applyCommand()执行状态变更命令,同时保留项目校验逻辑:
const updateState = function(supportIssue) { if(supportIssue.project.key === 'Support') { // 通过命令式方式更新状态,确保在工作流中生效 supportIssue.applyCommand(`State ${ctx.SupportState.ActionRequired.name}`); } }
关联工单遍历优化
直接针对目标链接类型的关联工单遍历,无需处理其他无关链接:
// 仅遍历"affects helpdesk log"类型的新增关联工单,执行状态更新 issue_0.links['affects helpdesk log'].added.forEach(updateState);
完整requirements参考配置
确保两个项目的状态字段定义正确:
requirements: { BugState: { name: "State", type: entities.State.fieldType, InProgress: {name: "In Progress"}, Closed: {name: "Closed"} }, SupportState: { name: "State", type: entities.State.fieldType, AwaitingFix: {name: "Awaiting Fix"}, ActionRequired: {name: "Action Required"} } }
内容的提问来源于stack exchange,提问作者Mark R
相关产品推荐
相关产品推荐

