Skip to content

Commit

Permalink
Merge pull request #575 from AdmiringWorm/AdmiringWorm/issue574
Browse files Browse the repository at this point in the history
(#574) Exclude all issues with label
  • Loading branch information
gep13 authored Mar 9, 2024
2 parents 3303c4c + 322d3f0 commit 44e8ed0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ public async Task<string> BuildReleaseNotesAsync(string user, string repository,
private Dictionary<string, List<Issue>> GetIssuesDict(List<Issue> 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)
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 44e8ed0

Please sign in to comment.