在正式的AzureDevOps REST文档中,更新附件的JSON主体如下:
[
{
"op": "test",
"path": "/rev",
"value": 3
},
{
"op": "replace",
"path": "/relations/2/attributes/comment",
"value": "Adding traceability to dependencies"
}
]这个数字2 (在relations/2/中)来自哪里?
到目前为止,我已经理解它是从零开始的,但是我不知道它是如何与附件匹配的。
通过更新附件的评论,我已经能够理解其中的逻辑,但我无法理解。
与下面测试用例中的3个附件相关的信息对应于:此魔术索引/附件名称/附件id (每次创建附件时递增)/URL中显示的附件id:
有什么想法吗?
发布于 2019-01-14 09:42:05
这个数字是关系的基于零的指数.这些关系包括附件和链接,这可能会让你感到困惑。
例如,使用Python,代码可以如下所示:
def get_relation_idx(tc, attachment_id):
"""Return the index in relations corresponding to a the attachment id (or part of it)"""
for idx, rel in enumerate(tc.relations):
if rel.rel == "AttachedFile" and attachment_id in rel.url:
return idx
return None
attachment_id = "87042366"
tc = wit_client.get_work_item(12345, expand="Relations")
idx = get_relation_idx(tc, attachment_id)
print("Attachment {} has index {}".format(attachment_id, idx))https://stackoverflow.com/questions/54145285
复制相似问题