azure-devops python 运行“create_work_item”时出错

发布于 2025-01-11 16:11:24 字数 2277 浏览 0 评论 0原文

我正在尝试使用 azure-devops python pip 包将大量 Epic/Story/Feature 票证迁移到 Azure Devops。我可以很好地创建单个票证,但我无法通过指定层次结构将这些票证链接在一起(票证 A 是子票证 B/C/D 的父级)

为了创建 EPIC 票证,我正在运行如下代码这:

    #set field
    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
    )

这有效,但现在我正在尝试弄清楚如何为这张 Epic 门票提供链接的儿童门票。

在这个 azure-devops python 包的 github 存储库中,我可以看到在 create_work_item 的定义中,有一个字符串变量 expand ,它有一个 Relations 选项 < /代码>

<一href="https://github.com/microsoft/azure-devops-python-api/blob/master/azure-devops/azure/devops/v5_1/work_item_tracking/work_item_tracking_client.py#L1578" rel="nofollow noreferrer">https://github.com/microsoft/azure-devops-python-api/blob/master/azure-devops/azure/devops/v5_1/work_item_tracking/work_item_tracking_client.py#L1578

:param str expand: The expand parameters for work item attributes. Possible options are { None, Relations, Fields, Links, All }.

中也有讨论create_work_item 函数的官方 azure-devops 文档: https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work-items/create?view=azure-devops-rest-6.0#workitemexpand

但是如果我将 expand='Relations' 添加到我的代码中,这会导致错误:

    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,
        expand='Relations'
    )

TypeError: WorkItemTrackingClient.create_work_item() got an Unexpected keywords argument 'expand'

我是否正确使用了这个 'expand' 变量?或者是否有其他方法可以使用 python 将儿童票添加到 azure 中的史诗中?谢谢

I am trying to use the azure-devops python pip package in order to migrate a large amount of Epic/Story/Feature tickets into Azure Devops. I can create singular tickets just fine, but I'm having trouble linking those tickets together by specifying the hierarchy (ticket A is a parent to child tickets B / C / D)

In order to create an EPIC ticket I'm running code like this:

    #set field
    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
    )

Which works, but now I'm trying to figure out how to give this Epic ticket a linked Child ticket.

In the github repo for this azure-devops python package, I can see that in the definition for create_work_item there is a string variable expand which has an option for Relations

https://github.com/microsoft/azure-devops-python-api/blob/master/azure-devops/azure/devops/v5_1/work_item_tracking/work_item_tracking_client.py#L1578

:param str expand: The expand parameters for work item attributes. Possible options are { None, Relations, Fields, Links, All }.

It's also discussed in the official azure-devops documentation for the create_work_item function:
https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work-items/create?view=azure-devops-rest-6.0#workitemexpand

But if I add expand='Relations' to my code it results in an error:

    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,
        expand='Relations'
    )

TypeError: WorkItemTrackingClient.create_work_item() got an unexpected keyword argument 'expand'

Am I using this 'expand' variable correctly? Or is there a different way I should add a child ticket to an epic in azure using python? Thanks

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

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

发布评论

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

评论(1

ぃ弥猫深巷。 2025-01-18 16:11:24

谢谢用户 Shamrai Aleksander - Stack Overflow。将您的建议作为答案发布以帮助其他社区成员。

要解决此 TypeError: WorkItemTrackingClient.create_work_item() got an Unexpected keywords argument 'expand' 错误:

您可以在 patch_document< 中附加关系,而不是使用 expand /代码>。您可以尝试此示例:

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)

参考文献:Azure Python 如何将子/相关票证链接到已创建的票证? - Stack OverflowGitHub - microsoft/azure-devops-python-api: Azure DevOps Python API

Thank you User Shamrai Aleksander - Stack Overflow . Posting your suggestion as an answer to help other community members.

To resolve this TypeError: WorkItemTrackingClient.create_work_item() got an unexpected keyword argument 'expand' error:

Instead of using expand, you can append the relation in patch_document. 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)

References: Azure Python how to link child/related tickets to an already created ticket? - Stack Overflow and GitHub - microsoft/azure-devops-python-api: Azure DevOps Python API

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