在C#中使用Azure DevOps REST API,我正在创建一个拉取请求,然后尝试像这样完成它(简化):
var pullRequest = new GitPullRequest {
Title = "My PR",
SourceRefName = "refs/heads/my",
TargetRefName = "refs/heads/master",
Commits = commits
};
pullRequest = await gitClient.CreatePullRequestAsync(pullRequest, repositoryId);
await Task.Delay(3000);
if (pullRequest.MergeStatus == PullRequestAsyncStatus.Succeeded) {
var pr2 = new GitPullRequest
{
LastMergeSourceCommit = pullRequest.LastMergeSourceCommit,
Status = PullRequestStatus.Completed
};
var result = await gitClient.UpdatePullRequestAsync(pullRequest, pullRequest.Repository.Id, pullRequest.pullRequestId);
}
如果没有冲突,则可以正常工作。但是,如果拉取请求存在冲突,则MergeStatus将为“冲突”。现在,假设有人手动解决了这些冲突,并且PR已准备好进行合并。
解决冲突后,我再次收到请求请求
var pullRequest = await gitClient.GetPullRequestByIdAsync(pullRequestId);
即使UI显示绿色,pullRequest.MergeStatus仍然存在冲突。
一旦将MergeStatus设置为“冲突”,是否有办法刷新它?我尝试通过将MergeStatus设置为Queued来更新拉取请求。还是API中缺少的功能?
答案 0 :(得分:0)
希望你能熬过去,以防万一有人来找我(就像我今天做的那样)这对我有用。
var prOriginal = gitClient.CreatePullRequestAsync(
new GitPullRequest() {
SourceRefName = $"refs/heads/{Input.SrcBranch}",
TargetRefName = $"refs/heads/{Input.TgtBranch}",
Title = Input.Title,
Description = Input.Description
},
tgtRepo.Id).Result;
Thread.Sleep(TimeSpan.FromSeconds(30));
var statusRetry = 0;
var prTest = gitClient.GetPullRequestAsync(
tgtRepo.Id,
prOriginal.PullRequestId).Result;
while(PullRequestAsyncStatus.Succeeded != prTest.MergeStatus) {
// TODO decide when to quit.
Thread.Sleep(TimeSpan.FromSeconds(30));
prTest = gitClient.GetPullRequestAsync(
tgtRepo.Id,
prOriginal.PullRequestId).Result;
}
Debug.WriteLine($"MergeStatus: {prTest.MergeStatus}");
我在线解决问题后,MergeStatus 很快就成功恢复了。现在,如果我可以使用 api 解决这些冲突,我会很好。