所以我想使用 POST 请求端点创建拉取请求,但想将标签添加到 PR 中。我知道有一个单独的端点可以将标签添加到 PR,但想知道这些是否可以在同一个调用中完成。现在我的 PR 创建请求正文包含源引用、目标引用、标题和描述。
调用API创建新PR时,您可以通过API的请求体为PR添加标签/标签。
下面是在创建新 PR 时使用 Azure DevOps Python 客户端库添加标签/标签的示例。
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
# Fill in with your PAT and organization URL.
personal_access_token = '<PAT>'
organization_url = 'https://dev.azure.com/<organization-name>'
# Create a connection to the organization.
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
# Get the Git client.
git_client = connection.clients.get_git_client()
# Set the request body of the API call. Add 2 labels when creating the new PR.
body = {
"title": "Merge changes - 2024091801",
"description": "Merge changes - 2024091801\nCreate PR using Azure DevOps Python client libraries.",
"isDraft": False,
"sourceRefName": "refs/heads/dev",
"targetRefName": "refs/heads/main",
"labels": [
{
"name": "lable01"
},
{
"name": "lable02"
}
]
}
# Call the API to create a new PR with the request boby.
git_client.create_pull_request(body, '<repository-name>', '<project-name>')