Skip to content

Commit

Permalink
(GitTools#574) Exclude all issues with label
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AdmiringWorm committed Feb 8, 2024
1 parent a94d9d5 commit 9fff4cf
Showing 1 changed file with 11 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

0 comments on commit 9fff4cf

Please sign in to comment.