我的问题字段有一个State
和一个名为In Progress
的选项
所以我写了一个Youtrack工作流程,当问题 “进行中”时,在我的不和谐频道上发布了一个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, "In Progress");
还是给我一个例外
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)
答案 0 :(得分:2)
如果要使用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
错误,请检查“状态”字段中是否为空值:
return ctx.issue.fields.State && ctx.issue.fields.becomes(ctx.State.name, "In Progress");
我希望它将对您有所帮助。