我目前正在将 SOAP 代码交换为 ADOS OnPremise 应用程序的 REST (6.0) 代码。
private void SetIntegratedStatusForBranch(ChangesetModel changeset, Branch changesetBranch, List<Branch> allBranches)
{
VersionControlServer sourceControl = (VersionControlServer)_tfs.GetService(typeof(VersionControlServer));
ItemIdentifier[] everyBranch = allBranches.Select(b => new ItemIdentifier(GetMainBranchOfTfsPath(b).TfsPath)).ToArray();
var merges = sourceControl.TrackMerges(
new int[] { changeset.Id },
new ItemIdentifier(changesetBranch.TfsPath),
everyBranch,
null);
Branch mainBranch = GetMainBranch(changesetBranch);
IntegrationModel integrationModel = new IntegrationModel();
if (changesetBranch.TfsPath.Contains("dev-main") && !merges.Any(m => m.TargetItem.Item == mainBranch.TfsPath))
{
integrationModel.IntegrationState = IntegratedState.NotIntegrated;
integrationModel.IntegrationDate = DateTime.MinValue;
integrationModel.IntegrationChangesetId = -1;
changeset.AddIntegratedBranch(mainBranch, integrationModel);
}
if (mainBranch.TfsPath == changesetBranch.TfsPath)
{
integrationModel.IntegrationState = IntegratedState.Integrated;
integrationModel.IntegrationDate = changeset.CreationDate;
integrationModel.IntegrationChangesetId = changeset.Id;
changeset.AddIntegratedBranch(mainBranch, integrationModel);
}
else if (changesetBranch.TfsPath.Contains("dlv"))
{
integrationModel.IntegrationState = IntegratedState.Integrated;
integrationModel.IntegrationDate = changeset.CreationDate;
integrationModel.IntegrationChangesetId = changeset.Id;
changeset.AddIntegratedBranch(changesetBranch, integrationModel);
}
foreach (var merge in merges)
{
IntegrationModel integration = new IntegrationModel
{
IntegrationState = IntegratedState.Integrated,
IntegrationDate = merge.TargetChangeset.CreationDate,
IntegrationChangesetId = merge.TargetChangeset.ChangesetId
};
Branch branch = allBranches.FirstOrDefault(x => (!merge.TargetItem.Item.Contains("dlv") && merge.TargetItem.Item.Contains(x.TfsPath)) || x.TfsPath == merge.TargetItem.Item);
changeset.AddIntegratedBranch(branch, integration);
}
}
我只是找不到重构上面代码的解决方案。有人知道如何解决我的问题吗?
在后台,我们使用VS2022并且设置了管道,如果提交通过管道运行没有错误,它将自动合并(有相同的例外,但那些不相关)。
我已经尝试通过尝试以下 .NET Rest 方法来进行合并:
使用以下片段:https://github.com/microsoft/azure-devops-dotnet-samples/tree/main。
我主要用的是:
VssConnection _connection;
_connection = new VssConnection(new Uri("https://" + Settings.Default.TfsServerUri), new VssClientCredentials());
GitHttpClient gitClient = _connection.GetClient<GitHttpClient>();
etc...
我希望创建一个解决方法,基本上主要交换这部分代码:
var merges = sourceControl.TrackMerges(
new int[] { changeset.Id },
new ItemIdentifier(changesetBranch.TfsPath),
everyBranch,
null);
我检查了 Microsoft.TeamFoundation.SourceControl.WebApi 的文档,但似乎没有针对
TrackMerges
方法的直接一对一映射。
这是TfvcMergeSource。您可以探索实现类似功能的可用方法。