From 9fff4cff09d347609b48283584899fef6b5e2af2 Mon Sep 17 00:00:00 2001 From: AdmiringWorm Date: Thu, 8 Feb 2024 14:33:25 +0100 Subject: [PATCH] (#574) Exclude all issues with label This updates the handling on how we are excluding labels when generating release notes. This allows issues to be assigned with a normal label, but still be excluded if a different label is listed in the exclusion list. Previously you would need to add and remove labels between drafting a release notes. --- .../ReleaseNotes/ReleaseNotesBuilder.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs b/src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs index 79273145..8e1bef64 100644 --- a/src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs +++ b/src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs @@ -101,7 +101,10 @@ public async Task BuildReleaseNotesAsync(string user, string repository, private Dictionary> GetIssuesDict(List issues) { var issueLabels = _configuration.IssueLabelsInclude; + var excludedIssueLabels = _configuration.IssueLabelsExclude; + var issuesByLabel = issues + .Where(o => !o.Labels.Any(l => excludedIssueLabels.Any(eil => string.Equals(eil, l.Name, StringComparison.OrdinalIgnoreCase)))) .SelectMany(o => o.Labels, (issue, label) => new { Label = label.Name, Issue = issue }) .Where(o => issueLabels.Any(il => string.Equals(il, o.Label, StringComparison.OrdinalIgnoreCase))) .GroupBy(o => o.Label, o => o.Issue) @@ -136,16 +139,21 @@ private string GetValidLabel(string label, int issuesCount) foreach (var issue in issues) { var includedIssuesCount = 0; - var excludedIssuesCount = 0; + var isExcluded = false; foreach (var issueLabel in issue.Labels) { includedIssuesCount += _configuration.IssueLabelsInclude.Count(issueToInclude => issueLabel.Name.ToUpperInvariant() == issueToInclude.ToUpperInvariant()); - excludedIssuesCount += _configuration.IssueLabelsExclude.Count(issueToExclude => issueLabel.Name.ToUpperInvariant() == issueToExclude.ToUpperInvariant()); + isExcluded = isExcluded && _configuration.IssueLabelsExclude.Any(issueToExclude => issueLabel.Name.ToUpperInvariant() == issueToExclude.ToUpperInvariant()); + } + + if (isExcluded) + { + continue; } - if (includedIssuesCount + excludedIssuesCount != 1) + if (includedIssuesCount != 1) { var allIssueLabels = _configuration.IssueLabelsInclude.Union(_configuration.IssueLabelsExclude).ToList(); var allIssuesExceptLast = allIssueLabels.Take(allIssueLabels.Count - 1);