【发布时间】:2020-01-13 13:49:02
【问题描述】:
尝试了各种方法以编程方式从 Azure DevOps 中提取代码审查 cmets。我可以查询这两个任务(代码审查请求和代码审查响应),但无法检索审查者给出的 cmets。
在 TFS、DiscussionThread 和 IDiscussionManager 中获取 cmets。但它没有 lon
方法一: 尝试使用命名空间 Microsoft.TeamFoundation.WorkItemTracking.WebApi 中的 GetCommentsAsync()
方法 2: “内容”将采用 JSON 格式。我也找不到任何评论 cmets。
internal class Program
{
// URI and PERSONALACCESSTOKEN are removed in the sample code due to security reasons.
// I referred this link for below details https://docs.microsoft.com/azure/devops/integrate/get-started/authentication/pats
private const string URI = "";
private const string PERSONALACCESSTOKEN = "";
private static void Main(string[] args)
{
GetTaskDetail(85527).Wait();
Console.ReadKey();
}
private static async Task GetTaskDetail(int workItemId)
{
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 = client.GetAsync(
string.Format(URI + "_apis/wit/workitems/{0}?$expand=all&api-version=5.0", workItemId)).Result)
{
response.EnsureSuccessStatusCode();
var content = response.Content.ReadAsStringAsync().Result;
}
}
}
【问题讨论】:
-
您应该使用
await而不是在异步方法返回的任务上调用.Result。
标签: c# .net azure-devops