到处寻求帮助,但没有成功。
我正在使用这个 https://github.com/Microsoft/azure-devops-python-api 并想对 DevOps 工作项发表评论。
到目前为止我做到了:
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
import pprint
from azure.devops.v5_1.work_item_tracking.models import Wiql
from vsts.work_item_tracking.v4_1.models.json_patch_operation import JsonPatchOperation
# Fill in with your personal access token and org URL
personal_access_token = 'P_A_T'
organization_url = 'https://xxxx.visualstudio.com'
# 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)
core_client = connection.clients.get_core_client()
wit_client = connection.clients.get_work_item_tracking_client()
patch_document = [
JsonPatchOperation(
op="add",
path="/fields/System.History",
value={
"text": "Hey StackOverFlow! Please help me",
},
)
]
wit_client.update_work_item(patch_document, "1550")
但是运行这个我收到以下错误:
msrest.exceptions.ClientRequestError: Error occurred in request., RetryError: HTTPSConnectionPool(host='xxxx.visualstudio.com', port=443): Max retries exceeded with url: /_apis/wit/workItems/1550 (Caused by ResponseError('too many 500 error responses'))
我做错了什么,为什么它不起作用:)?请帮助我SOF!
按照@tortal的建议,我猜它的值是错误的。您需要将字符串作为值传递。 而且 id 应该是“int”类型而不是字符串。
wit_client.update_work_item(patch_document, 1550)
为了帮助您,azure-devops 提供了一种方法“add_comment”,您可以在其中将文本作为参数传递。也许你可以用它。
req = CommentCreate(text="Hey StackOverFlow! Please help me")
work_item_client.add_comment(request=req, project='XXXX', work_item_id=1550)