|
18 | 18 | using Microsoft.Extensions.Logging;
|
19 | 19 | using Microsoft.ServiceFabric.Actors;
|
20 | 20 | using Microsoft.ServiceFabric.Actors.Runtime;
|
| 21 | +using Microsoft.VisualStudio.Services.Common; |
21 | 22 | using ProductConstructionService.Client;
|
22 | 23 | using ProductConstructionService.Client.Models;
|
23 | 24 | using SubscriptionActorService.StateModel;
|
@@ -872,8 +873,11 @@ await AddDependencyFlowEventsAsync(
|
872 | 873 | MergePolicyCheckResult.PendingPolicies,
|
873 | 874 | pr.Url);
|
874 | 875 |
|
| 876 | + var requiredDescriptionUpdates = |
| 877 | + await CalculateOriginalDependencies(darcRemote, targetRepository, targetBranch, targetRepositoryUpdates); |
| 878 | + |
875 | 879 | pullRequest.Description = await _pullRequestBuilder.CalculatePRDescriptionAndCommitUpdatesAsync(
|
876 |
| - targetRepositoryUpdates.RequiredUpdates, |
| 880 | + requiredDescriptionUpdates, |
877 | 881 | pullRequest.Description,
|
878 | 882 | targetRepository,
|
879 | 883 | pullRequest.HeadBranch);
|
@@ -1075,6 +1079,48 @@ private async Task<RepositoryBranchUpdate> GetRepositoryBranchUpdate()
|
1075 | 1079 |
|
1076 | 1080 | private static string GetNewBranchName(string targetBranch) => $"darc-{targetBranch}-{Guid.NewGuid()}";
|
1077 | 1081 |
|
| 1082 | + /// <summary> |
| 1083 | + /// Given a set of updates, replace the `from` version of every dependency update with the corresponding version |
| 1084 | + /// from the target branch |
| 1085 | + /// </summary> |
| 1086 | + /// <param name="darcRemote">Darc client used to fetch target branch dependencies.</param> |
| 1087 | + /// <param name="targetRepository">Target repository to fetch the dependencies from.</param> |
| 1088 | + /// <param name="targetBranch">Target branch to fetch the dependencies from.</param> |
| 1089 | + /// <param name="targetRepositoryUpdates">Incoming updates to the repository</param> |
| 1090 | + /// <returns> |
| 1091 | + /// Asset update and the corresponding list of altered dependencies |
| 1092 | + /// </returns> |
| 1093 | + /// <remarks> |
| 1094 | + /// This method is intended for use in situations where we want to keep the information about the original dependency |
| 1095 | + /// version, such as when updating PR descriptions. |
| 1096 | + /// </remarks> |
| 1097 | + private static async Task<List<(UpdateAssetsParameters update, List<DependencyUpdate> deps)>> CalculateOriginalDependencies( |
| 1098 | + IRemote darcRemote, |
| 1099 | + string targetRepository, |
| 1100 | + string targetBranch, |
| 1101 | + TargetRepoDependencyUpdate targetRepositoryUpdates) |
| 1102 | + { |
| 1103 | + List<DependencyDetail> targetBranchDeps = [..await darcRemote.GetDependenciesAsync(targetRepository, targetBranch)]; |
| 1104 | + |
| 1105 | + List<(UpdateAssetsParameters update, List<DependencyUpdate> deps)> alteredUpdates = []; |
| 1106 | + foreach (var requiredUpdate in targetRepositoryUpdates.RequiredUpdates) |
| 1107 | + { |
| 1108 | + var updatedDependencies = requiredUpdate.deps |
| 1109 | + .Select(dependency => new DependencyUpdate() |
| 1110 | + { |
| 1111 | + From = targetBranchDeps |
| 1112 | + .Where(replace => dependency.From.Name == replace.Name) |
| 1113 | + .FirstOrDefault(dependency.From), |
| 1114 | + To = dependency.To, |
| 1115 | + }) |
| 1116 | + .ToList(); |
| 1117 | + |
| 1118 | + alteredUpdates.Add((requiredUpdate.update, updatedDependencies)); |
| 1119 | + } |
| 1120 | + |
| 1121 | + return alteredUpdates; |
| 1122 | + } |
| 1123 | + |
1078 | 1124 | #region Code flow subscriptions
|
1079 | 1125 |
|
1080 | 1126 | /// <summary>
|
|
0 commit comments