Azure DevOps Python API 使用教程
项目地址:https://gitcode.com/gh_mirrors/az/azure-devops-python-api
1. 项目的目录结构及介绍
Azure DevOps Python API 项目的目录结构如下:
azure-devops-python-api/
├── azure/
│ └── devops/
│ ├── __init__.py
│ ├── _file_cache.py
│ ├── _helpers.py
│ ├── _version.py
│ ├── connection.py
│ ├── decorators.py
│ ├── exceptions.py
│ ├── git.py
│ ├── identity.py
│ ├── location.py
│ ├── operations.py
│ ├── policy.py
│ ├── release.py
│ ├── service_hooks.py
│ ├── task_agent.py
│ ├── test.py
│ ├── wiki.py
│ ├── work.py
│ └── work_item_tracking.py
├── samples/
│ ├── __init__.py
│ ├── create_build_definition.py
│ ├── create_git_repository.py
│ ├── create_work_item.py
│ ├── get_build_definitions.py
│ ├── get_builds.py
│ ├── get_git_repositories.py
│ ├── get_work_items.py
│ └── update_work_item.py
├── tests/
│ ├── __init__.py
│ ├── conftest.py
│ ├── test_connection.py
│ ├── test_git.py
│ ├── test_identity.py
│ ├── test_location.py
│ ├── test_operations.py
│ ├── test_policy.py
│ ├── test_release.py
│ ├── test_service_hooks.py
│ ├── test_task_agent.py
│ ├── test_test.py
│ ├── test_wiki.py
│ ├── test_work.py
│ └── test_work_item_tracking.py
├── .gitignore
├── LICENSE
├── README.md
├── requirements.txt
└── setup.py
目录结构介绍
azure/devops/
:包含主要的 API 实现文件。samples/
:包含使用该 API 的示例代码。tests/
:包含测试代码。.gitignore
:Git 忽略文件。LICENSE
:项目许可证。README.md
:项目说明文档。requirements.txt
:项目依赖文件。setup.py
:项目安装文件。
2. 项目的启动文件介绍
项目的启动文件通常是示例代码文件,位于 samples/
目录下。以下是一些关键的启动文件:
samples/create_work_item.py
:演示如何使用 API 创建工作项。samples/get_work_items.py
:演示如何使用 API 获取工作项。samples/update_work_item.py
:演示如何使用 API 更新工作项。
启动文件示例
以 samples/create_work_item.py
为例:
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
import os
# 获取个人访问令牌和组织 URL
personal_access_token = 'YOUR_PAT'
organization_url = 'https://dev.azure.com/YOUR_ORG'
# 创建认证对象
credentials = BasicAuthentication('', personal_access_token)
# 创建连接对象
connection = Connection(base_url=organization_url, creds=credentials)
# 获取工作项跟踪客户端
wit_client = connection.clients.get_work_item_tracking_client()
# 创建工作项
work_item = wit_client.create_work_item(
project='YOUR_PROJECT',
document=[
{
'op': 'add',
'path': '/fields/System.Title',
'value': 'Sample Task'
}
],
type='Task'
)
print('Created work item ID:', work_item.id)
3. 项目的配置文件介绍
项目的配置文件主要包括 requirements.txt
和 setup.py
。
requirements.txt
requirements.txt
文件列出了项目依赖的所有 Python 包:
msrest>=0.6.18
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考