Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#574) Exclude all issues with label #575

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading