以编程方式完成TFS拉取请求 [英] Complete TFS Pull Request programmatically

查看:280
本文介绍了以编程方式完成TFS拉取请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Microsoft.TeamFoundationServer.Client(15.112.1)连接到 TFS 2017 Update 2 服务器,我们可以获取有关现有PR的详细信息,如下所示:

Using the Microsoft.TeamFoundationServer.Client (15.112.1) to connect to a TFS 2017 Update 2 server we can get details about an existing PR like this:

var connection = new VssConnection(collectionUri, credentials);
var client = connection.GetClient<GitHttpClient>();
var pr = await client.GetPullRequestByIdAsync(pullRequestId);

此外,我们可以像这样创建新的PR:

Also, we can create new PR like this:

var pr = await client.CreatePullRequestAsync(
        new GitPullRequest
        {
          SourceRefName = "master",
          TargetRefName = "develop",
          Title = "[Automatic Merge]"
        },
        projectName, repositoryName);

此外,我们可以像这样对公关投票:

In addition, we can vote on the PR like this:

var pr = await client.CreatePullRequestReviewerAsync(
            reviewer, projectName, repositoryName, pullRequestId, authorizedIdenity.Id.ToString());

是否有任何方法可以完成PR(替代分支或不存在分支) 政策)并继续进行合并操作?

Is there any way to complete the PR (overriding or not existing branch policies) and proceed with the merge operation?

推荐答案

GitHttpClient具有 UpdatePullRequestAsync 方法.

The GitHttpClient has an UpdatePullRequestAsync method.

要完成请求请求,您需要更新请求请求的 Status (状态)属性.并使用 UpdatePullRequestAsync 方法来完成您的PR.

To complete the pull request you need to update the Status property of your pull request. and use the UpdatePullRequestAsync method to complete your PR.

请确保设置CompletionOptions属性以指定是否要合并提交,删除源分支等.

Please make sure that to set the the CompletionOptions property to specify whether you are merging the commit, delete the source branch etc.

因此您的代码如下所示

pr.Status = PullRequestStatus.Completed
pr.CompletionOption = new GitPullRequestCompletionOption() { SquashMerge = true };
client.UpdatePullRequest(pr, repositoryId, pullRequestId);

ByPassPolicy不适用于Microsoft.TeamFoundationServer.ExtendedClient的发行版本.

The ByPassPolicy is not available for the released version of Microsoft.TeamFoundationServer.ExtendedClient yet.

但是,如果安装库 Microsoft.TeamFoundationServer.ExtendedClient 的预发行版NuGet软件包 v15.122.1-preview ,您将看到ByPassPolicy选项作为属性.在GitPullrequestCompletionOptions类中.您可以将其设置为true,以通过策略.

However, if you install the pre-release NuGet Package v15.122.1-preview of library Microsoft.TeamFoundationServer.ExtendedClient, you will see the option ByPassPolicy as a property in the GitPullrequestCompletionOptions class. You can set it to true to by pass policy.

这篇关于以编程方式完成TFS拉取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆