private void SetIntegratedStatusForBranch(ChangesetModel changeset, Branch changesetBranch, List
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:
- CommitsSample
- ChangesetChangesSample
и прямой HTTP-запрос (но я не смог найти никакой соответствующей информации)
В основном я использую:
VssConnection _connection;
_connection = new VssConnection(new Uri("https://" + Settings.Default.TfsServerUri), new VssClientCredentials());
GitHttpClient gitClient = _connection.GetClient();
etc...
Я ожидал создать обходной путь, который в основном заменяет эту часть кода:
var merges = sourceControl.TrackMerges(
new int[] { changeset.Id },
new ItemIdentifier(changesetBranch.TfsPath),
everyBranch,
null);
Подробнее здесь: https://stackoverflow.com/questions/781 ... equivalent