gpt4 book ai didi

javascript - 使用工作流检查问题字段是否变为 "In Progress"时出现异常

转载 作者:行者123 更新时间:2023-11-29 18:43:35 26 4
gpt4 key购买 nike

我的问题字段有一个 State 和一个名为 In Progress 的选项

enter image description here

因此,我编写了一个 Youtrack 工作流程,当问题变成“进行中”时,它会向我的 Discord channel 发布一个 http 帖子。

这是它的 JavaScript 代码:


var entities = require('@jetbrains/youtrack-scripting-api/entities');
var http = require('@jetbrains/youtrack-scripting-api/http');

exports.rule = entities.Issue.onChange({
// TODO: give the rule a human-readable title
title: 'Open-discord-channel',
guard: function(ctx) {
return ctx.issue.fields.becomes(ctx.State, ctx.State.InProgress);
},
action: function(ctx) {
var issue = ctx.issue;
var connection = new http.Connection('https://discordapp.com');
connection.addHeader('Content-Type', 'application/json');
var response = connection.postSync('/api/webhooks/123/1DJucC8-vdZR-xxx', [], issue.description);
if (response && response.code === 200) {
issue.addComment(response.response);
}

// TODO: specify what to do when a change is applied to an issue
},
requirements: {
// TODO: add requirements
}
});

激活此工作流时会抛出此异常:

TypeError: Cannot read property "InProgress" from undefined (open-discord-channel/open-discord-channel#16)
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4198)
org.mozilla.javascript.gen.open_discord_channel_open_discord_channel_2052._c_anonymous_1(open-discord-channel/open-discord-channel:16)

它告诉我 Cannot read property "InProgress" 但实际上 return ctx.issue.fields.becomes(ctx.State, ctx.State.InProgress);InProgress 由嵌入式 Youtrack Workflow 编辑器建议。

谁能告诉我如何访问真正的“进行中”值以使此代码运行?

编辑

试过这个return ctx.issue.fields.becomes(ctx.State.name, "进行中");

还是给了我一个异常(exception)

Processing issue COOPR-85:
TypeError: Cannot read property "name" from undefined (open-discord-channel/open-discord-channel#16)
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4198)
org.mozilla.javascript.gen.open_discord_channel_open_discord_channel_2076._c_anonymous_1(open-discord-channel/open-discord-channel:16)

最佳答案

如果您想使用 ctx.issue.fields.becomes(ctx.State, ctx.State.InProgress) 语法,请将“进行中”状态的定义添加到 要求部分:

requirements: {
State: {
type: entities.State.fieldType,
InProgress: {
name: 'In Progress'
}
}
}

或者,为避免 Cannot read property "name"from undefined 错误,请检查 State 字段的空值:

return ctx.issue.fields.State && ctx.issue.fields.becomes(ctx.State.name, "In Progress");

希望对您有所帮助。

关于javascript - 使用工作流检查问题字段是否变为 "In Progress"时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55455713/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com