0

and thanks for looking!

I have an instance of YouTrack with several custom fields, some of which are String-type. I'm implementing a module to create a new issue via the YouTrack REST API's PUT request, and then updating its fields with user-submitted values by applying commands. This works great---most of the time.

I know that I can apply multiple commands to an issue at the same time by concatenating them into the query string, like so:

Type Bug Priority Critical add Fix versions 5.1 tag regression

will result in

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

in their respective fields (as well as adding the regression tag). But, if I try to do the same thing with multiple String-type custom fields, then:

Foo something Example Something else Bar P0001

results in

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

The command only applies to the first field, and the rest of the query string is treated like its String value. I can apply the command individually for each field, but is there an easier way to combine these requests?

Thanks again!

4

2 回答 2

1

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

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

于 2017-02-17T08:41:38.053 回答
1

这么好的问题。

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

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

其余 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

我很难过看到这个问题这么久没有得到答复。- 希望这可以帮助!

编辑:

在继续我的工作后,我得出结论,将所有字段更新作为一个单独发送POST对于 YouTrack 服务器来说稍微好一点,但需要付出更多的努力而不值得:

1)知道问题中的所有字段都是string

2) 将所有字符串值预处理为字符串文字

3) 如果您将所有字段更新作为一个请求发送,而其中只有一个丢失、未能设置或为意外值,则整个请求将失败,您可能会丢失所有其他信息。

我希望 YouTrack 文档对这些注意事项有所提及或讨论。

于 2018-12-08T15:23:12.653 回答