简体   繁体   English

azure devops REST API:如何检查拉取请求状态

[英]azure devops REST API: How to check pull request status

I'm trying to find if a PR is closed, abandoned, or active, merging, or with conflicts.我正在尝试查找 PR 是否已关闭、已放弃或处于活动状态、正在合并或存在冲突。 I'm trying GetPullRequestStatusesAsync, but I don't get anything back.我正在尝试 GetPullRequestStatusesAsync,但我没有得到任何回报。 The test ids cover various states, but the Statuses Result is simply empty.测试 ID 涵盖各种状态,但状态结果只是空的。

using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using Microsoft.TeamFoundation.SourceControl.WebApi;

var collection = "https://myurl";
var project = "pro";
var repo = "repo";

var codepat = Environment.GetEnvironmentVariable("code_pat");
if (codepat.IsNullOrEmpty()) { throw new Exception($"code_pat must be set in the environment."); }

var creds = new VssBasicCredential(string.Empty, codepat);
var conn = new VssConnection(new Uri(collection), creds);
using var gitClient = conn.GetClient<GitHttpClient>();
var srcRepo = gitClient.GetRepositoryAsync(project, repo).Result;

int[] prids = { 2345, 3254, 7645, 1357 };

foreach(var id in prids)
{
    Console.WriteLine($"id: {id}");
    var result = gitClient.GetPullRequestStatusesAsync(srcRepo.Id, id).Result;
    foreach (var r in result)
    {
        Console.WriteLine($"- {r.Id}: {r.State}, {r.Description}");
    }
    Console.WriteLine();
}

I got what I needed with GetPullRequestByIdAsync (but it would be nice to know what GetPullRequestStatusesAsync should return).我用 GetPullRequestByIdAsync 得到了我需要的东西(但很高兴知道 GetPullRequestStatusesAsync 应该返回什么)。

var pr = gitClient.GetPullRequestByIdAsync(id).Result;
Console.WriteLine($"- {pr.Status}, {pr.MergeStatus}");
  • Active, Conflicts活跃,冲突

  • Active, Succeeded活跃,成功

  • Completed, Succeeded完成,成功

  • Abandoned, NotSet被遗弃,未设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM