Azure Python 如何将子/相关票证链接到已创建的票证?

发布于 2025-01-11 16:09:46 字数 1288 浏览 3 评论 0原文

我正在使用 Azure Python 工具在 python 脚本中创建 Epic/Story/Feature 工作项,如下所示:

# add fields
jpo = JsonPatchOperation()
jpo.from_ = None
jpo.op = "add"
jpo.path = "/fields/Microsoft.VSTS.Scheduling.FinishDate"
jpo.value = default_field
jpos.append(jpo)

#create work item
createdWorkItem = wit_client.create_work_item(
    document=jpos,
    project=project.id,
    type="EPIC",
    validate_only=validate_only,
    bypass_rules=bypass_rules,
    suppress_notifications=suppress_notifications
)

#save details to local json file
epic_details = {
    "op": "add",
    "path": "/relations/-",
    "value": {
        "rel": "System.LinkTypes.Hierarchy-Reverse",
        "name": "Parent",
        "url": createdWorkItem.url
    }
}

我需要将我的票证链接在一起,例如在票证之间添加子/父关系。我试图通过首先创建所有票证,然后在需要的地方将它们链接起来来做到这一点。

如果两个票证都已存在,是否可以使用 Azure Devops Python 工具将子工作项添加到史诗工作项?谢谢。

编辑:我找到了此处引用的函数 ParentChildWIMaphttps://github.com/microsoft/azure-devops-python-api/blob/451cade4c475482792cbe9e522c1fee32393139e/azure-devops/azure/devops/v5_1/work/models.py#L711 但我不确定如何使用它

I am using the Azure Python tool to create Epic/Story/Feature work items in a python script like so:

# add fields
jpo = JsonPatchOperation()
jpo.from_ = None
jpo.op = "add"
jpo.path = "/fields/Microsoft.VSTS.Scheduling.FinishDate"
jpo.value = default_field
jpos.append(jpo)

#create work item
createdWorkItem = wit_client.create_work_item(
    document=jpos,
    project=project.id,
    type="EPIC",
    validate_only=validate_only,
    bypass_rules=bypass_rules,
    suppress_notifications=suppress_notifications
)

#save details to local json file
epic_details = {
    "op": "add",
    "path": "/relations/-",
    "value": {
        "rel": "System.LinkTypes.Hierarchy-Reverse",
        "name": "Parent",
        "url": createdWorkItem.url
    }
}

I need to link my tickets together, such as adding a Child / Parent relationship between tickets. I'm trying to do this by creating all my tickets first, then linking them all where needed.

Is there some way with the Azure Devops Python tool that I can add a child workitem to a epic workitem if both tickets already exist? Thanks.

edit: I've found the function ParentChildWIMap referenced here:
https://github.com/microsoft/azure-devops-python-api/blob/451cade4c475482792cbe9e522c1fee32393139e/azure-devops/azure/devops/v5_1/work/models.py#L711
But I'm unsure on how to use it

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在夏天 2025-01-18 16:09:46

如果您使用 https://github.com/microsoft/azure-devops-python-api ,你可以尝试这个示例:

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v6_0.py_pi_api import JsonPatchOperation
import pprint

# Fill in with your personal access token and org URL
personal_access_token = '<pat>'
organization_url = 'https://dev.azure.com/<org>'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

# Get a client (the "core" client provides access to projects, teams, etc)
wi_client = connection.clients.get_work_item_tracking_client()

parent_id = 2129
child_id = 2217

parent_work_item = wi_client.get_work_item(parent_id);

pprint.pprint(parent_work_item.url)

patch_document = []
patch_document.append(JsonPatchOperation(op='add',path="/relations/-",value={"rel": "System.LinkTypes.Hierarchy-Reverse","url": parent_work_item.url}))


wi_client.update_work_item(patch_document, child_id)

If you use https://github.com/microsoft/azure-devops-python-api , you can try this sample:

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v6_0.py_pi_api import JsonPatchOperation
import pprint

# Fill in with your personal access token and org URL
personal_access_token = '<pat>'
organization_url = 'https://dev.azure.com/<org>'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

# Get a client (the "core" client provides access to projects, teams, etc)
wi_client = connection.clients.get_work_item_tracking_client()

parent_id = 2129
child_id = 2217

parent_work_item = wi_client.get_work_item(parent_id);

pprint.pprint(parent_work_item.url)

patch_document = []
patch_document.append(JsonPatchOperation(op='add',path="/relations/-",value={"rel": "System.LinkTypes.Hierarchy-Reverse","url": parent_work_item.url}))


wi_client.update_work_item(patch_document, child_id)
随遇而安 2025-01-18 16:09:46

我也花了相当长的时间才弄清楚这一点。
与前面的答案类似,有关如何根据 yaml 文件中的内容创建具有可选子任务的工作项的示例:

https://github.com/filipjonckers/azure-devops-bulk-workitems

希望这对您有帮助。

Took me quite some time to figure this one out too.
Similar to the previous answer, an example on how to create work items with optional subtasks based on content from yaml files:

https://github.com/filipjonckers/azure-devops-bulk-workitems

Hope this is helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文