Skip to content

Commit 322d3f0

Browse files
AdmiringWormgep13
authored andcommitted
(GitTools#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.
1 parent 3303c4c commit 322d3f0

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ public async Task<string> BuildReleaseNotesAsync(string user, string repository,
101101
private Dictionary<string, List<Issue>> GetIssuesDict(List<Issue> issues)
102102
{
103103
var issueLabels = _configuration.IssueLabelsInclude;
104+
var excludedIssueLabels = _configuration.IssueLabelsExclude;
105+
104106
var issuesByLabel = issues
107+
.Where(o => !o.Labels.Any(l => excludedIssueLabels.Any(eil => string.Equals(eil, l.Name, StringComparison.OrdinalIgnoreCase))))
105108
.SelectMany(o => o.Labels, (issue, label) => new { Label = label.Name, Issue = issue })
106109
.Where(o => issueLabels.Any(il => string.Equals(il, o.Label, StringComparison.OrdinalIgnoreCase)))
107110
.GroupBy(o => o.Label, o => o.Issue)
@@ -136,16 +139,21 @@ private string GetValidLabel(string label, int issuesCount)
136139
foreach (var issue in issues)
137140
{
138141
var includedIssuesCount = 0;
139-
var excludedIssuesCount = 0;
142+
var isExcluded = false;
140143

141144
foreach (var issueLabel in issue.Labels)
142145
{
143146
includedIssuesCount += _configuration.IssueLabelsInclude.Count(issueToInclude => issueLabel.Name.ToUpperInvariant() == issueToInclude.ToUpperInvariant());
144147

145-
excludedIssuesCount += _configuration.IssueLabelsExclude.Count(issueToExclude => issueLabel.Name.ToUpperInvariant() == issueToExclude.ToUpperInvariant());
148+
isExcluded = isExcluded || _configuration.IssueLabelsExclude.Any(issueToExclude => issueLabel.Name.ToUpperInvariant() == issueToExclude.ToUpperInvariant());
149+
}
150+
151+
if (isExcluded)
152+
{
153+
continue;
146154
}
147155

148-
if (includedIssuesCount + excludedIssuesCount != 1)
156+
if (includedIssuesCount != 1)
149157
{
150158
var allIssueLabels = _configuration.IssueLabelsInclude.Union(_configuration.IssueLabelsExclude).ToList();
151159
var allIssuesExceptLast = allIssueLabels.Take(allIssueLabels.Count - 1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
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.
2+
3+
__Feature__
4+
5+
- [__#3__](http://example.com/3) Issue 3

src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.cs

+7
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ public void CorrectlyExcludeIssues()
184184
Assert.True(true); // Just to make sonarlint happy
185185
}
186186

187+
[Test]
188+
public void CorrectlyExcludeIssuesWhenBothIncludeAndExcludeLabelIsSet()
189+
{
190+
AcceptTest(10, CreateIssue(5, "Improvement", "Build"), CreateIssue(3, "Feature"));
191+
Assert.True(true);
192+
}
193+
187194
private static void AcceptTest(int commits, params Issue[] issues)
188195
{
189196
AcceptTest(commits, null, null, issues);

0 commit comments

Comments
 (0)