I'm currently exchanging SOAP Code to REST (6.0) Code of an ADOS OnPremise Application.
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); }}
I just can't find a solution to refactor the code above. Has anyone any ideas how I could solve my issue?
In the Background we're using VS2022 and the pipeline is set, if a commit runs without errors through the pipeline it will be automatically merged (with same exceptions but those are not relevant).
I've already tried to get the merges with trying out following .NET Rest approaches:
- CommitsSample
- ChangesetChangesSample
- and direct HTTP Request (but I could't find any relevant informations)
with using snippets from: https://github.com/microsoft/azure-devops-dotnet-samples/tree/main.
I'm mainly using:
VssConnection _connection;_connection = new VssConnection(new Uri("https://" + Settings.Default.TfsServerUri), new VssClientCredentials());GitHttpClient gitClient = _connection.GetClient<GitHttpClient>();etc...
I was expecting to create a workaround which basically exchanges mainly this part of the code:
var merges = sourceControl.TrackMerges( new int[] { changeset.Id }, new ItemIdentifier(changesetBranch.TfsPath), everyBranch, null);