|
4 | 4 | using System;
|
5 | 5 | using System.Collections.Generic;
|
6 | 6 | using System.Linq;
|
7 |
| -using System.Text.RegularExpressions; |
| 7 | +using System.Text; |
8 | 8 | using System.Threading;
|
9 | 9 | using System.Threading.Tasks;
|
10 | 10 | using Microsoft.DotNet.DarcLib.Helpers;
|
@@ -579,8 +579,13 @@ private async Task<List<DependencyUpdate>> BackflowDependenciesAndToolset(
|
579 | 579 |
|
580 | 580 | await targetRepo.StageAsync(["."], cancellationToken);
|
581 | 581 |
|
| 582 | + string commitMessage = string.Concat( |
| 583 | + $"Update dependencies from {build.GetRepository()} build {build.Id}", |
| 584 | + Environment.NewLine, |
| 585 | + BuildDependencyUpdateCommitMessage(repoChanges)); |
| 586 | + |
582 | 587 | await targetRepo.CommitAsync(
|
583 |
| - "Update dependencies from " + build.GetRepository() + " build " + build.Id, |
| 588 | + commitMessage, |
584 | 589 | allowEmpty: false,
|
585 | 590 | cancellationToken: cancellationToken);
|
586 | 591 |
|
@@ -666,6 +671,80 @@ private static List<DependencyUpdate> ComputeChanges(Matcher? excludedAssetsMatc
|
666 | 671 | .ToList();
|
667 | 672 | }
|
668 | 673 |
|
| 674 | + public static string BuildDependencyUpdateCommitMessage(IEnumerable<DependencyUpdate> updates) |
| 675 | + { |
| 676 | + if (!updates.Any()) |
| 677 | + { |
| 678 | + return "No dependency updates to commit"; |
| 679 | + } |
| 680 | + Dictionary<string, List<string>> removedDependencies = new(); |
| 681 | + Dictionary<string, List<string>> addedDependencies = new(); |
| 682 | + Dictionary<string, List<string>> updatedDependencies = new(); |
| 683 | + foreach (DependencyUpdate dependencyUpdate in updates) |
| 684 | + { |
| 685 | + if (dependencyUpdate.To != null && dependencyUpdate.From == null) |
| 686 | + { |
| 687 | + string versionBlurb = $"Version {dependencyUpdate.To.Version}"; |
| 688 | + AddDependencyToDictionary(addedDependencies, versionBlurb, dependencyUpdate.To.Name); |
| 689 | + continue; |
| 690 | + } |
| 691 | + if (dependencyUpdate.To == null && dependencyUpdate.From != null) |
| 692 | + { |
| 693 | + string versionBlurb = $"Version {dependencyUpdate.From.Version}"; |
| 694 | + AddDependencyToDictionary(removedDependencies, versionBlurb, dependencyUpdate.From.Name); |
| 695 | + continue; |
| 696 | + } |
| 697 | + if (dependencyUpdate.To != null && dependencyUpdate.From != null) |
| 698 | + { |
| 699 | + string versionBlurb = $"Version {dependencyUpdate.From.Version} -> {dependencyUpdate.To.Version}"; |
| 700 | + AddDependencyToDictionary(updatedDependencies, versionBlurb, dependencyUpdate.From.Name); |
| 701 | + continue; |
| 702 | + } |
| 703 | + } |
| 704 | + |
| 705 | + var result = new StringBuilder(); |
| 706 | + if (updatedDependencies.Any()) |
| 707 | + { |
| 708 | + result.AppendLine("Updated Dependencies:"); |
| 709 | + foreach ((string versionBlurb, List<string> packageNames) in updatedDependencies) |
| 710 | + { |
| 711 | + result.AppendLine(string.Join(", ", packageNames) + $" ({versionBlurb})"); |
| 712 | + } |
| 713 | + result.AppendLine(); |
| 714 | + } |
| 715 | + if (addedDependencies.Any()) |
| 716 | + { |
| 717 | + result.AppendLine("Added Dependencies:"); |
| 718 | + foreach ((string versionBlurb, List<string> packageNames) in addedDependencies) |
| 719 | + { |
| 720 | + result.AppendLine(string.Join(", ", packageNames) + $" ({versionBlurb})"); |
| 721 | + } |
| 722 | + result.AppendLine(); |
| 723 | + } |
| 724 | + if (removedDependencies.Any()) |
| 725 | + { |
| 726 | + result.AppendLine("Removed Dependencies:"); |
| 727 | + foreach ((string versionBlurb, List<string> packageNames) in removedDependencies) |
| 728 | + { |
| 729 | + result.AppendLine(string.Join(", ", packageNames) + $" ({versionBlurb})"); |
| 730 | + } |
| 731 | + result.AppendLine(); |
| 732 | + } |
| 733 | + return result.ToString().TrimEnd(); |
| 734 | + } |
| 735 | + |
| 736 | + private static void AddDependencyToDictionary(Dictionary<string, List<string>> dictionary, string versionBlurb, string dependencyName) |
| 737 | + { |
| 738 | + if (dictionary.TryGetValue(versionBlurb, out var list)) |
| 739 | + { |
| 740 | + list.Add(dependencyName); |
| 741 | + } |
| 742 | + else |
| 743 | + { |
| 744 | + dictionary[versionBlurb] = new List<string> { dependencyName }; |
| 745 | + } |
| 746 | + } |
| 747 | + |
669 | 748 | private async Task<VersionDetails> GetRepoDependencies(ILocalGitRepo repo, string commit)
|
670 | 749 | => GetDependencies(await repo.GetFileFromGitAsync(VersionFiles.VersionDetailsXml, commit));
|
671 | 750 |
|
|
0 commit comments