使用 YouTrack Rest 将命令应用于字符串类型的自定义字段 API

Apply Command to String-type custom fields with YouTrack Rest API

感谢观看!

我有一个 YouTrack 实例,其中包含多个自定义字段,其中一些是字符串类型。我正在实施一个模块,通过 YouTrack REST API 的 PUT request, and then updating its fields with user-submitted values by applying commands 创建一个新问题。这在大多数情况下都很好用。

我知道我可以通过将多个命令连接到查询字符串中来同时对一个问题应用多个命令,如下所示:

Type Bug Priority Critical add Fix versions 5.1 tag regression

将导致

  • Type: Bug
  • Priority: Critical
  • Fix versions: 5.1

在各自的领域(以及添加回归标签)。但是,如果我尝试对多个字符串类型的自定义字段做同样的事情,那么:

Foo something Example Something else Bar P0001

结果

  • Foo: something Example Something else Bar P0001
  • Example:
  • Bar:

该命令仅适用于第一个字段,查询字符串的其余部分被视为其字符串值。我可以为每个字段单独应用命令,但是有没有更简单的方法来组合这些请求?

再次感谢!

这是预期的结果,因为 foo 之后的所有字符串都被视为该字段的值,并且空格也是字符串自定义字段的有效符号。

如果您尝试通过 UI 中的命令 window 应用此命令,您实际上会看到相同的结果。

好问题。

我遇到了同样的问题,并且在沮丧中度过了不健康的时间。 使用 YouTrack UI 中的命令 window 我注意到它留下了尾随引号,我无法在讨论最终确定或识别字符串值结尾的文档中找到任何内容。我也无法在命令参考、语法文档或示例中找到任何关于设置字符串字段值的提及。

对于我的解决方案,我将 Python 与 requestsurllib 模块一起使用。 - 尽管我希望您可以将解决方案转换为任何语言。

其余 API 将接受 POST

中的显式字符串
import requests
import urllib
from collections import OrderedDict

URL = 'http://youtrack.your.address:8000/rest/issue/{issue}/execute?'.format(issue='TEST-1234')

params = OrderedDict({
    'State': 'New',
    'Priority': 'Critical',
    'String Field': '"Message to submit"',
    'Other Details': '"Fold the toilet paper to a point when you are finished."'
})

str_cmd = ' '.join(' '.join([k, v]) for k, v in params.items())
command_url = URL + urllib.urlencode({'command':str_cmd})

result = requests.post(command_url)

# The command result:
# http://youtrack.your.address:8000/rest/issue/TEST-1234/execute?command=Priority+Critical+State+New+String+Field+%22Message+to+submit%22+Other+Details+%22Fold+the+toilet+paper+to+a+point+when+you+are+finished.%22

看到这个问题这么长时间都没有得到答复,我很难过。 - 希望这对您有所帮助!

编辑:

After continuing my work, I have concluded that sending all the field updates as a single POST is marginally better for the YouTrack server, but requires more effort than it's worth to:

1) know all fields in the Issues which are string values

2) pre-process all the string values into string literals

3) If you were to send all your field updates as a single request and just one of them was missing, failed to set, or was an unexpected value, then the entire request will fail and you potentially lose all the other information.

I wish the YouTrack documentation had some mention or discussion of these considerations.