azure-devops - Get all work items from devops throug rest api
问题描述
According to documentation you can get work items as following:
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=5.1
However you need to provide ids for all the workitems you want. What if you just want all workitems? If I skip Ids I get following:
Response status code does not indicate success: 404 (Not Found).
OK I am getting a little closer thanks to some of the repsonses:
var uri = "https://dev.azure.com/xx";
var personalAccessToken = "xx";
var project = "GAC";
VssBasicCredential credentials = new VssBasicCredential("", personalAccessToken);
Wiql wiql = new Wiql()
{
Query = "Select [State], [Title],[Remaining Work] From WorkItems Where [Work Item Type] = 'Bug' OR [Work Item Type] = 'Task' And [System.TeamProject] = '" + project+"'"
};
//create instance of work item tracking http client
using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(new Uri(uri), credentials))
{
//execute the query to get the list of work items in the results
WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;
//some error handling
if (workItemQueryResult.WorkItems.Count() != 0)
{
foreach (IEnumerable<WorkItemReference> batch in workItemQueryResult.WorkItems.Batch(100))
{
var workItemIds = batch.Select(p => p.Id).ToArray();
var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(workItemIds, expand: WorkItemExpand.All).Result;
}
}
}
However I dont get information around what I am primary looking for like Completed, Remaining works etc. Any pointers?
解决方案
you need to create a query to fetch work items programmatically.
Apart from the core system fields, the fields are very dependent from the process template (Agile, Scrum,...) used. You can even have custom fields. So how to find out the name, or more specific, the ReferenceName, in order to query it?
using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
{
List<WorkItemField> fieldsQuery = await workItemTrackingHttpClient.GetFieldsAsync(_project, null, null, System.Threading.CancellationToken.None);
if (fieldsQuery.Count() != 0)
{
foreach (var fieldItem in fieldsQuery)
{
Console.WriteLine("{0} / {1}", fieldItem.Name, fieldItem.ReferenceName);
}
}
}
推荐阅读
- c# - 包含(非异或)方式的多边形填充路径联合
- javascript - 如何将数组分成相等的块?
- opengl - 是否可以在 Azure App Service Linux 中使用 OpenGL?
- javascript - 在javascript中,通过“new Function()”创建函数时如何设置函数参数名称?
- apache-beam - 如何在 Apache Beam 中“加入”频繁更新的流和不规则更新的流?
- r - 在 dplyr 中使用变异和动态命名的变量
- printing - 以准确的尺寸打印 PNG 文件
- mysql - 创建新的 AWS RDS 实例并导入数据,而不是将 MySQL 版本从 5.6 更新到 5.7
- sql - 如何从sql中YYYYMM格式的字符串列表中获取一个月?
- html - 如何从R中的html获取信息?