From 322d3f0bc1acb99b5d2be280e5a8580b7edc8f55 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 +++++++++++--- ...henBothIncludeAndExcludeLabelIsSet.approved.txt | 5 +++++ .../ReleaseNotesBuilderTests.cs | 7 +++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.CorrectlyExcludeIssuesWhenBothIncludeAndExcludeLabelIsSet.approved.txt diff --git a/src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs b/src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs index 79273145..ff4584eb 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); diff --git a/src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.CorrectlyExcludeIssuesWhenBothIncludeAndExcludeLabelIsSet.approved.txt b/src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.CorrectlyExcludeIssuesWhenBothIncludeAndExcludeLabelIsSet.approved.txt new file mode 100644 index 00000000..b7344330 --- /dev/null +++ b/src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.CorrectlyExcludeIssuesWhenBothIncludeAndExcludeLabelIsSet.approved.txt @@ -0,0 +1,5 @@ +As part of this release we had [10 commits](https://github.com/TestUser/FakeRepository/commits/1.2.3) which resulted in [2 issues](https://github.com/gep13/FakeRepository/issues?q=milestone%3A1.2.3?closed=1) being closed. + +__Feature__ + +- [__#3__](http://example.com/3) Issue 3 diff --git a/src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.cs b/src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.cs index 7b3126e6..43e46526 100644 --- a/src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.cs +++ b/src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.cs @@ -184,6 +184,13 @@ public void CorrectlyExcludeIssues() Assert.True(true); // Just to make sonarlint happy } + [Test] + public void CorrectlyExcludeIssuesWhenBothIncludeAndExcludeLabelIsSet() + { + AcceptTest(10, CreateIssue(5, "Improvement", "Build"), CreateIssue(3, "Feature")); + Assert.True(true); + } + private static void AcceptTest(int commits, params Issue[] issues) { AcceptTest(commits, null, null, issues);