Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/Maestro/SubscriptionActorService/PullRequestActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,13 @@ await AddDependencyFlowEventsAsync(
MergePolicyCheckResult.PendingPolicies,
pr.Url);

// When changing `from` and `to` for depenency updates in a PR's description, we want `from` to keep
// pointing to the original version from the target branch.
var requiredDescriptionUpdates =
await ReplaceFromDependency(darcRemote, targetRepository, targetBranch, targetRepositoryUpdates);

pullRequest.Description = await _pullRequestBuilder.CalculatePRDescriptionAndCommitUpdatesAsync(
targetRepositoryUpdates.RequiredUpdates,
requiredDescriptionUpdates,
pullRequest.Description,
targetRepository,
pullRequest.HeadBranch);
Expand Down Expand Up @@ -1075,6 +1080,37 @@ private async Task<RepositoryBranchUpdate> GetRepositoryBranchUpdate()

private static string GetNewBranchName(string targetBranch) => $"darc-{targetBranch}-{Guid.NewGuid()}";

private static async Task<List<(UpdateAssetsParameters update, List<DependencyUpdate> deps)>> ReplaceFromDependency(
IRemote darcRemote,
string targetRepository,
string targetBranch,
TargetRepoDependencyUpdate targetRepositoryUpdates
)
{
List<DependencyDetail> targetBranchDeps = (await darcRemote.GetDependenciesAsync(targetRepository, targetBranch)).ToList();

//
var requiredDescriptionUpdates = targetRepositoryUpdates.RequiredUpdates
.Select(requiredUpdates =>
{
requiredUpdates.deps = requiredUpdates.deps
.Select(update =>
{
update.From = targetBranchDeps
.Where(replace => update.From.Name == replace.Name)
.FirstOrDefault(update.From);

return update;
})
.ToList();

return requiredUpdates;
})
.ToList();

return requiredDescriptionUpdates;
}

#region Code flow subscriptions

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,13 @@ await AddDependencyFlowEventsAsync(
MergePolicyCheckResult.PendingPolicies,
pr.Url);

// When changing `from` and `to` for depenency updates in a PR's description, we want `from` to keep
// pointing to the original version from the target branch.
var requiredDescriptionUpdates =
await ReplaceFromDependency(darcRemote, targetRepository, targetBranch, targetRepositoryUpdates);

pullRequest.Description = await _pullRequestBuilder.CalculatePRDescriptionAndCommitUpdatesAsync(
targetRepositoryUpdates.RequiredUpdates,
requiredDescriptionUpdates,
pullRequest.Description,
targetRepository,
pullRequest.HeadBranch);
Expand Down Expand Up @@ -836,6 +841,37 @@ private async Task ClearAllStateAsync()
await _pullRequestUpdateReminders.UnsetReminderAsync();
}

private static async Task<List<(SubscriptionUpdateWorkItem update, List<DependencyUpdate> deps)>> ReplaceFromDependency(
IRemote darcRemote,
string targetRepository,
string targetBranch,
TargetRepoDependencyUpdate targetRepositoryUpdates
)
{
List<DependencyDetail> targetBranchDeps = (await darcRemote.GetDependenciesAsync(targetRepository, targetBranch)).ToList();

//
var requiredDescriptionUpdates = targetRepositoryUpdates.RequiredUpdates
.Select(requiredUpdates =>
{
requiredUpdates.deps = requiredUpdates.deps
.Select(update =>
{
update.From = targetBranchDeps
.Where(replace => update.From.Name == replace.Name)
.FirstOrDefault(update.From);

return update;
})
.ToList();

return requiredUpdates;
})
.ToList();

return requiredDescriptionUpdates;
}

#region Code flow subscriptions

/// <summary>
Expand Down
9 changes: 6 additions & 3 deletions test/Maestro.ScenarioTests/MaestroScenarioTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void SetTestParameters(TestParameters parameters)
if (!string.IsNullOrEmpty(_parameters.MaestroToken))
{
_baseDarcRunArgs.AddRange(["-p", _parameters.MaestroToken]);
}
}
}

protected async Task<Octokit.PullRequest> WaitForPullRequestAsync(string targetRepo, string targetBranch)
Expand Down Expand Up @@ -487,7 +487,10 @@ protected async Task AddDependenciesToLocalRepo(string repoPath, string name, st
{
using (ChangeDirectory(repoPath))
{
await RunDarcAsync(["add-dependency", "--name", name, "--type", isToolset ? "toolset" : "product", "--repo", repoUri, "--version", "0.0.1"]);
await RunDarcAsync(
[
"add-dependency", "--name", name, "--version", "0.0.1", "--type", isToolset ? "toolset" : "product", "--repo", repoUri
]);
}
}
protected async Task<string> GetTestChannelsAsync()
Expand Down Expand Up @@ -682,7 +685,7 @@ protected async Task AddDependenciesToLocalRepo(string repoPath, List<AssetData>

protected async Task<string> GatherDrop(int buildId, string outputDir, bool includeReleased, string extraAssetsRegex)
{
string[] args = [ "gather-drop", "--id", buildId.ToString(), "--dry-run", "--output-dir", outputDir ];
string[] args = ["gather-drop", "--id", buildId.ToString(), "--dry-run", "--output-dir", outputDir];

if (includeReleased)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,10 @@ protected async Task AddDependenciesToLocalRepo(string repoPath, List<AssetData>
{
foreach (AssetData asset in dependencies)
{
List<string> parameters = ["add-dependency", "--name", asset.Name, "--type", "product", "--repo", repoUri];
List<string> parameters =
[
"add-dependency", "--name", asset.Name,"--type", "product", "--repo", repoUri,
];

if (!string.IsNullOrEmpty(coherentParent))
{
Expand Down