admin管理员组

文章数量:1431434

I am trying to enhance my (C#) utility that can currently already Create a pull request using the GitHttpClient. I can query the PR and update it using UpdatePullRequestAsync.

What i am currently struggling with is to find a way to get the state of the build(s) that are linked to the PR. I explored the dotnet samples, but these are fairly limited: .cs

The statuses are empty. What would be the correct/best way to get the build status for a pull request using the client libraries?

In the end, i want to (force) complete my pull request if all the linked builds are successful. Which if im correct should be done like this:

// now complete the PR
var updatedPr = new GitPullRequest()
{
    Status = PullRequestStatus.Completed,
    CompletionOptions = new GitPullRequestCompletionOptions() { SquashMerge = true, DeleteSourceBranch = true, BypassPolicy = true }

};

var prStatus = gitClient.UpdatePullRequestAsync(updatedPr, repoId, pullRequestId).Result;
               

How can help me point to the right way getting this information?

I am trying to enhance my (C#) utility that can currently already Create a pull request using the GitHttpClient. I can query the PR and update it using UpdatePullRequestAsync.

What i am currently struggling with is to find a way to get the state of the build(s) that are linked to the PR. I explored the dotnet samples, but these are fairly limited: https://github/microsoft/azure-devops-dotnet-samples/blob/main/ClientLibrary/Samples/Git/PullRequestIterationStatusesSample.cs

The statuses are empty. What would be the correct/best way to get the build status for a pull request using the client libraries?

In the end, i want to (force) complete my pull request if all the linked builds are successful. Which if im correct should be done like this:

// now complete the PR
var updatedPr = new GitPullRequest()
{
    Status = PullRequestStatus.Completed,
    CompletionOptions = new GitPullRequestCompletionOptions() { SquashMerge = true, DeleteSourceBranch = true, BypassPolicy = true }

};

var prStatus = gitClient.UpdatePullRequestAsync(updatedPr, repoId, pullRequestId).Result;
               

How can help me point to the right way getting this information?

Share Improve this question edited Nov 19, 2024 at 12:03 jonrsharpe 122k30 gold badges268 silver badges476 bronze badges asked Nov 19, 2024 at 12:02 NicoNico 7197 silver badges28 bronze badges 1
  • Hi @Nico, Good day. Have you got a chance to check my answer below to use GetPullRequestStatusesAsync to get the statuses of the validation build iterations? Hope your query in this post can be resolved. Thx. – Alvin Zhao Commented Nov 25, 2024 at 7:02
Add a comment  | 

1 Answer 1

Reset to default 0

As far as I have tested, you may try and use GetPullRequestStatusesAsync to get the PR iteration statuses.

Here is my code snippet for your reference.

// Get the pull request statuses
var statuses = gitClient.GetPullRequestStatusesAsync(projectName, repoName, pullRequestId).Result;

// Serialize the object to JSON
string statusesJson = JsonConvert.SerializeObject(statuses, Formatting.Indented);

// Print the JSON
Console.WriteLine("============ Satuses ============");
Console.WriteLine(statusesJson);

本文标签: Get state of build policies in Azure DevOps Pull requestStack Overflow