diff --git a/Plogon/BuildProcessor.cs b/Plogon/BuildProcessor.cs index 6724ed7..ffe7274 100644 --- a/Plogon/BuildProcessor.cs +++ b/Plogon/BuildProcessor.cs @@ -1302,20 +1302,16 @@ private BuildResult.ReviewedNeed GetNeedStatus(string key, string version, State private void CommitReviewedNeeds(IEnumerable needs) { - foreach (var need in needs) - { - if (need.ReviewedBy != null) - continue; - - this.pluginRepository.State.ReviewedNeeds.Add(new State.Need + this.pluginRepository.AddReviewedNeeds(needs + .Where(need => need.ReviewedBy != null) + .Select(need => new State.Need { Key = need.Name, ReviewedBy = this.actor ?? throw new Exception("Committing, but reviewer is null"), Version = need.Version, ReviewedAt = DateTime.UtcNow, Type = need.Type, - }); - } + })); } private static void CopySourceForArchive(DirectoryInfo from, DirectoryInfo to, int depth = 0) diff --git a/Plogon/Repo/PluginRepository.cs b/Plogon/Repo/PluginRepository.cs index 214c1ec..13ac6a5 100644 --- a/Plogon/Repo/PluginRepository.cs +++ b/Plogon/Repo/PluginRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; @@ -148,4 +149,33 @@ public void UpdatePluginHave(string channelName, string plugin, string haveCommi SaveState(); } + + /// + /// Add a list of needs to the repository. + /// + /// The needs to add. + public void AddReviewedNeeds(IEnumerable needs) + { + foreach (var need in needs) + { + AddReviewedNeed(need); + } + + this.SaveState(); + } + + /// + /// Add a need to the repository. + /// + /// The need to add. + /// Thrown if the need was already reviewed. + private void AddReviewedNeed(State.Need need) + { + if (this.State.ReviewedNeeds.Any(x => x.Key == need.Key && x.Version == need.Version)) + { + throw new Exception($"Need {need.Key}(v{need.Version}) already in state"); + } + + this.State.ReviewedNeeds.Add(need); + } }