VSTS / AzureDevOps REST API 中关系的索引是什么?

What is the index of the relations in VSTS / AzureDevOps REST API?

在官方Documentation of AzureDevOps REST API中,更新附件的JSON正文如下:

[
  {
    "op": "test",
    "path": "/rev",
    "value": 3
  },
  {
    "op": "replace",
    "path": "/relations/2/attributes/comment",
    "value": "Adding traceability to dependencies"
  }
]

这个数字 2(在 relations/2/ 中)来自哪里?


到目前为止我知道它是从零开始的,但我不知道它是如何与附件匹配的。

通过更新附件的评论,我已经能看懂哪个是哪个了,但是我看不懂逻辑。

下面一个测试用例中3个附件的相关信息分别对应:这个魔法索引/附件名称/附件id(每次创建附件自增)/[=40中出现的附件id =]:

有什么想法吗?

这个数字是从零开始的关系索引。这些关系包括附件和链接,这可能让您感到困惑。

例如,使用 Python REST API,代码可能如下:

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))