python - 如何使用 azure devops python api。需要一些示例:获取用户故事信息、创建用户故事、更改状态
问题描述
我有一个完全满足我要求的程序,我在没有使用库的情况下编写它。我不小心删除了文件。使用版本控制。总是。
我正在尝试获取任务列表,但我完全不明白我在做什么。有人有例子吗?我需要几个简单的操作:创建带有标签的用户故事、获取用户故事信息(标题、描述、ID)、更改用户故事状态(活动、关闭)
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v6_0.work_item_tracking.work_item_tracking_client import WorkItemTrackingClient
import pprint
from azure.devops.v6_0.work_item_tracking.models import WorkItemBatchGetRequest
m_token = "x7micezp4c25btn3a1111111111111o23zlxuwrpdoa"
m_url = 'https://dev.azure.com/logistics/'
m_cred = BasicAuthentication('', m_token)
m_conn = Connection(base_url=m_url, creds=m_cred)
m_client = m_conn.clients.get_core_client()
kek = WorkItemBatchGetRequest(ids = [22, 33])
cc = WorkItemTrackingClient(m_url)
c = cc.get_work_items_batch(kek, "Manyport")
print(c.value)
解决方案
感谢汤姆支持您的回答,添加了有关如何在函数应用设置中添加用户身份的屏幕截图。
提供对服务资源的创建、检索、更新或删除访问的 Rest API 也支持 HTTP 操作并且是服务端点。
下面是带有 HTTP 客户端类的 Rest API 的示例代码。
public static async void GetProjects()
{
try
{
var personalaccesstoken = "PAT_FROM_WEBSITE";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", "", personalaccesstoken))));
using (HttpResponseMessage response = await client.GetAsync(
"https://dev.azure.com/{organization}/_apis/projects"))
{
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
有关更多信息,请查看带有 Rest API 的 Azure DevOps
推荐阅读
- algorithm - A* 是否从边缘以增量成本顺序(如 Dijkstra 的)弹出节点以获得一致的启发式?
- swift - 如何对 SIMD3 进行类型转换
ARFaceGeometry 顶点坐标 - python - 如何使用 pandas .eval() 来评估多列上的操作。?
- html - 部署到 pythonanywhere.com 时未显示 Django 应用程序页面
- scala - 如何有条件地在akka-http中添加路由路径?
- android - Android:从回收站视图中删除空行
- javascript - 通过 MediaSource 和 MediaSourceBuffer 来自 websocket 的 HTML5 视频流
- c# - 如何将 UDT 对象读入结果查询?
- linux - 解析日志文件,显示特定日期之间的日志
- java - 在进行 PDE 构建时如何解决 OSGi 库的依赖问题?