gpt4 book ai didi

tfs - 以编程方式完成 TFS 合并请求

转载 作者:行者123 更新时间:2023-12-04 02:00:55 26 4
gpt4 key购买 nike

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

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

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

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

此外,我们可以像这样对 PR 进行投票:

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

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

最佳答案

GitHttpClient 有一个 UpdatePullRequestAsync 方法。

要完成拉取请求,您需要更新拉取请求的 Status 属性。并使用 UpdatePullRequestAsync 方法来完成您的 PR。

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

所以你的代码看起来像下面这样

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

编辑:

ByPassPolicy 不适用于已发布的 Microsoft.TeamFoundationServer.ExtendedClient 版本。

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

关于tfs - 以编程方式完成 TFS 合并请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47339126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com