Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/0.9.1' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Oct 8, 2020
2 parents aee27dd + 135e599 commit ebb115a
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 11 deletions.
2 changes: 1 addition & 1 deletion nuspec/nuget/Cake.Issues.PullRequests.nuspec
Expand Up @@ -22,7 +22,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin
<repository type="git" url="https://github.com/cake-contrib/Cake.Issues.PullRequests.git"/>
<copyright>Copyright © BBT Software AG and contributors</copyright>
<tags>Cake Script Cake-Issues CodeAnalysis Linting Issues Pull-Requests</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.PullRequests/releases/tag/0.9.0</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.PullRequests/releases/tag/0.9.1</releaseNotes>
</metadata>
<files>
<file src="..\..\..\..\nuspec\nuget\icon.png" target="" />
Expand Down
Expand Up @@ -10,15 +10,15 @@
<CodeAnalysisRuleSet>..\Cake.Issues.PullRequests.Tests.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Cake.Core" Version="0.33.0" />
<PackageReference Include="Cake.Testing" Version="0.33.0" />
<PackageReference Include="Cake.Issues" Version="0.9.0" />
<PackageReference Include="Cake.Issues.Testing" Version="0.9.0" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cake.Issues.PullRequests\Cake.Issues.PullRequests.csproj" />
Expand Down
261 changes: 261 additions & 0 deletions src/Cake.Issues.PullRequests.Tests/IssueFiltererTests.cs
Expand Up @@ -547,6 +547,152 @@ public void Should_Limit_Messages_To_Maximum()
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global issue limit of 2 across all runs for provider 'ProviderType Foo' (2 issues already posted in previous runs)");
}

[Fact]
public void Should_Limit_Messages_To_Zero()
{
// Given
var fixture = new IssueFiltererFixture();
fixture.Settings.ProviderIssueLimits.Add(
"ProviderType Foo",
new ProviderIssueIssueLimits(maxIssuesToPostAcrossRuns: 0));

var newIssue1 =
IssueBuilder
.NewIssue("Message Foo", "ProviderType Foo", "ProviderName Foo")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 10)
.OfRule("Rule Foo")
.WithPriority(IssuePriority.Warning)
.Create();

var newIssue2 =
IssueBuilder
.NewIssue("Message Bar", "ProviderType Bar", "ProviderName Bar")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 12)
.OfRule("Rule Bar")
.WithPriority(IssuePriority.Warning)
.Create();

// When
var issues =
fixture.FilterIssues(
new List<IIssue>
{
newIssue1, newIssue2
},
new Dictionary<IIssue, IssueCommentInfo>(),
new List<IPullRequestDiscussionThread>
{
new PullRequestDiscussionThread(
1,
PullRequestDiscussionStatus.Active,
@"src\Cake.Issues.Tests\FakeIssueProvider.cs",
new List<IPullRequestDiscussionComment>
{
new PullRequestDiscussionComment
{
Content = "Message FooBar",
IsDeleted = false
}
})
{
ProviderType = "ProviderType Foo"
},
new PullRequestDiscussionThread(
1,
PullRequestDiscussionStatus.Active,
@"src\Cake.Issues.Tests\FakeIssueProvider.cs",
new List<IPullRequestDiscussionComment>
{
new PullRequestDiscussionComment
{
Content = "Message FooBar",
IsDeleted = false
}
})
{
ProviderType = "ProviderType Foo"
}
});

// Then
issues.Count().ShouldBe(1);
issues.ShouldContain(newIssue2);
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global issue limit of 0 across all runs for provider 'ProviderType Foo' (2 issues already posted in previous runs)");
}

[Fact]
public void Should_Ignore_Limit_When_Negative()
{
// Given
var fixture = new IssueFiltererFixture();
fixture.Settings.ProviderIssueLimits.Add(
"ProviderType Foo",
new ProviderIssueIssueLimits(maxIssuesToPostAcrossRuns: -3));

var newIssue1 =
IssueBuilder
.NewIssue("Message Foo", "ProviderType Foo", "ProviderName Foo")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 10)
.OfRule("Rule Foo")
.WithPriority(IssuePriority.Warning)
.Create();

var newIssue2 =
IssueBuilder
.NewIssue("Message Bar", "ProviderType Foo", "ProviderName Foo")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 12)
.OfRule("Rule Bar")
.WithPriority(IssuePriority.Warning)
.Create();

// When
var issues =
fixture.FilterIssues(
new List<IIssue>
{
newIssue1, newIssue2
},
new Dictionary<IIssue, IssueCommentInfo>(),
new List<IPullRequestDiscussionThread>
{
new PullRequestDiscussionThread(
1,
PullRequestDiscussionStatus.Active,
@"src\Cake.Issues.Tests\FakeIssueProvider.cs",
new List<IPullRequestDiscussionComment>
{
new PullRequestDiscussionComment
{
Content = "Message FooBar",
IsDeleted = false
}
})
{
ProviderType = "ProviderType Foo"
},
new PullRequestDiscussionThread(
1,
PullRequestDiscussionStatus.Active,
@"src\Cake.Issues.Tests\FakeIssueProvider.cs",
new List<IPullRequestDiscussionComment>
{
new PullRequestDiscussionComment
{
Content = "Message FooBar",
IsDeleted = false
}
})
{
ProviderType = "ProviderType Foo"
}
});

// Then
issues.Count().ShouldBe(2);
issues.ShouldContain(newIssue1);
issues.ShouldContain(newIssue2);
}

[Fact]
public void Should_Limit_Messages_To_Maximum_By_Priority()
{
Expand Down Expand Up @@ -749,6 +895,121 @@ public void Should_Limit_Messages_To_Maximum()
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global limit of 1 issues which should be reported for issue provider 'ProviderTypeB'");
}

[Fact]
public void Should_Limit_Messages_To_Zero()
{
// Given
var fixture = new IssueFiltererFixture();
fixture.Settings.ProviderIssueLimits.Add(
"ProviderTypeA",
new ProviderIssueIssueLimits(maxIssuesToPost: 0));
fixture.Settings.ProviderIssueLimits.Add(
"ProviderTypeB",
new ProviderIssueIssueLimits(maxIssuesToPost: 0));

var issue1 =
IssueBuilder
.NewIssue("Message Foo", "ProviderTypeA", "ProviderNameA")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 10)
.OfRule("Rule Foo")
.WithPriority(IssuePriority.Warning)
.Create();
var issue2 =
IssueBuilder
.NewIssue("Message Bar", "ProviderTypeA", "ProviderNameA")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 12)
.OfRule("Rule Bar")
.WithPriority(IssuePriority.Warning)
.Create();
var issue3 =
IssueBuilder
.NewIssue("Message Foo", "ProviderTypeB", "ProviderNameB")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 10)
.OfRule("Rule Bar")
.WithPriority(IssuePriority.Warning)
.Create();
var issue4 =
IssueBuilder
.NewIssue("Message Bar", "ProviderTypeB", "ProviderNameB")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 12)
.OfRule("Rule Bar")
.WithPriority(IssuePriority.Warning)
.Create();

// When
var issues =
fixture.FilterIssues(
new List<IIssue>
{
issue1, issue2, issue3, issue4
},
new Dictionary<IIssue, IssueCommentInfo>());

// Then
issues.Count().ShouldBe(0);

fixture.Log.Entries.ShouldContain(x => x.Message == "2 issue(s) were filtered to match the global limit of 0 issues which should be reported for issue provider 'ProviderTypeA'");
fixture.Log.Entries.ShouldContain(x => x.Message == "2 issue(s) were filtered to match the global limit of 0 issues which should be reported for issue provider 'ProviderTypeB'");
}

[Fact]
public void Should_Ignore_Limit_When_Negative()
{
// Given
var fixture = new IssueFiltererFixture();
fixture.Settings.ProviderIssueLimits.Add(
"ProviderTypeA",
new ProviderIssueIssueLimits(maxIssuesToPost: -3));
fixture.Settings.ProviderIssueLimits.Add(
"ProviderTypeB",
new ProviderIssueIssueLimits(maxIssuesToPost: -1));

var issue1 =
IssueBuilder
.NewIssue("Message Foo", "ProviderTypeA", "ProviderNameA")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 10)
.OfRule("Rule Foo")
.WithPriority(IssuePriority.Warning)
.Create();
var issue2 =
IssueBuilder
.NewIssue("Message Bar", "ProviderTypeA", "ProviderNameA")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 12)
.OfRule("Rule Bar")
.WithPriority(IssuePriority.Warning)
.Create();
var issue3 =
IssueBuilder
.NewIssue("Message Foo", "ProviderTypeB", "ProviderNameB")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 10)
.OfRule("Rule Bar")
.WithPriority(IssuePriority.Warning)
.Create();
var issue4 =
IssueBuilder
.NewIssue("Message Bar", "ProviderTypeB", "ProviderNameB")
.InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 12)
.OfRule("Rule Bar")
.WithPriority(IssuePriority.Warning)
.Create();

// When
var issues =
fixture.FilterIssues(
new List<IIssue>
{
issue1, issue2, issue3, issue4
},
new Dictionary<IIssue, IssueCommentInfo>());

// Then
issues.Count().ShouldBe(4);
issues.ShouldContain(issue1);
issues.ShouldContain(issue2);
issues.ShouldContain(issue3);
issues.ShouldContain(issue4);
}

[Fact]
public void Should_Limit_Messages_To_Maximum_By_Priority()
{
Expand Down
Expand Up @@ -27,7 +27,7 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.33.0" />
<PackageReference Include="Cake.Issues" Version="0.9.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
</ItemGroup>
</Project>
21 changes: 14 additions & 7 deletions src/Cake.Issues.PullRequests/IssueFilterer.cs
Expand Up @@ -252,8 +252,9 @@ private IList<IIssue> FilterIssuesByPath(IList<IIssue> issues)
// Apply issue limits per provider for this run
foreach (var currentProviderLimitPair in this.settings.ProviderIssueLimits)
{
var currentProviderTypeMaxLimit = (currentProviderLimitPair.Value?.MaxIssuesToPost).GetValueOrDefault();
if (currentProviderTypeMaxLimit <= 0)
var currentProviderTypeMaxLimit = currentProviderLimitPair.Value?.MaxIssuesToPost;
if (!currentProviderTypeMaxLimit.HasValue ||
currentProviderTypeMaxLimit < 0)
{
continue;
}
Expand All @@ -271,7 +272,7 @@ private IList<IIssue> FilterIssuesByPath(IList<IIssue> issues)

var countBefore = result.Count;
result = result.Where(p => p.ProviderType != currentProviderType)
.Concat(newIssuesForProviderType.Take(currentProviderTypeMaxLimit))
.Concat(newIssuesForProviderType.Take(currentProviderTypeMaxLimit.Value))
.ToList();

var issuesFilteredCount = countBefore - result.Count;
Expand Down Expand Up @@ -303,18 +304,24 @@ private IList<IIssue> FilterIssuesByPath(IList<IIssue> issues)
// Apply issue limits per provider across mulitple runs
foreach (var currentProviderLimitPair in this.settings.ProviderIssueLimits)
{
var currentProviderTypeMaxLimit = (currentProviderLimitPair.Value?.MaxIssuesToPostAcrossRuns).GetValueOrDefault();
if (currentProviderTypeMaxLimit <= 0)
var currentProviderTypeMaxLimit = currentProviderLimitPair.Value?.MaxIssuesToPostAcrossRuns;
if (!currentProviderTypeMaxLimit.HasValue ||
currentProviderTypeMaxLimit < 0)
{
continue;
}

var currentProviderType = currentProviderLimitPair.Key;

var existingThreadCountForProvider =
existingThreads.Count(p => p.ProviderType == currentProviderType);

var maxIssuesLeftToTakeForProviderType =
currentProviderTypeMaxLimit - existingThreadCountForProvider;
currentProviderTypeMaxLimit.Value - existingThreadCountForProvider;
if (maxIssuesLeftToTakeForProviderType < 0)
{
maxIssuesLeftToTakeForProviderType = 0;
}

var newIssuesForProviderType =
result.Where(p => p.ProviderType == currentProviderType)
.SortWithDefaultPriorization()
Expand Down

0 comments on commit ebb115a

Please sign in to comment.