前言:最近在做对接Azure DevOps的API的工作,最开始也做了很多调研,官方给的API也是很丰富与完整,但是在对接工作项(WorkItems)时发现,官方并没有给WorkItems的列表或者分页的API,具体原因并不清楚,不过也可以通过id的list去获取工作项的list,id的list就需要通过wiql去获取。
这里对Azure DevOps的wiql进行分享,用作示例的是对工作项(WorkItems)的id的list进行获取,获取其他的id列表也可以类似使用。
WorkItemSearch workItemSearch = new WorkItemSearch(); IDictionary<string, object> SearchDic = new Dictionary<string, object>(); SearchDic.Add(searchField, quaryItem); workItemSearch.SearchDic = SearchDic; QueryWiql queryWiql = new QueryWiql(); var sql = $"SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = '{ConfigManagerHelper.DevOpsProject()}'"; if (workItemSearch != null) { if (workItemSearch.Id == 0) sql += " AND [System.Id] > 0"; else sql += $" AND [System.Id] > {workItemSearch.Id}"; foreach (var searchDic in workItemSearch.SearchDic) { sql += $" AND [{searchDic.Key}] = '{searchDic.Value}'"; } } sql += " order by [System.Id]"; queryWiql.Query = sql; var httpContent = HttpJsonHelper.ObjectToByteArrayContent(queryWiql); var result = HttpJsonHelper.HttpPost(m_httpClientFactory, m_devOpsUrl, $"_apis/wit/wiql?$top={top}&api-version={ConfigManagerHelper.ApiVersion()}", httpContent, ConfigManagerHelper.BasicToken());
top代表需要获取的条数,api-version是版本号,m_devOpsUrl是对https://dev.azure.com/{organization}/{project}的设置。写法类似sql,但是有些语法不支持,需要自行查阅。
官方文档链接:Work Items - Get Work Items Batch - REST API (Azure DevOps Work Item Tracking) | Microsoft Learn
标签:workItemSearch,DevOps,System,API,sql,Azure,SearchDic,Id From: https://www.cnblogs.com/yangruibokeyuan/p/17661589.html