diff --git a/.appveyor.yml b/.appveyor.yml index bd9dc86..f7f80b0 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -10,10 +10,9 @@ install: - ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk" - ps: mkdir $env:DOTNET_INSTALL_DIR -Force | Out-Null - ps: Invoke-WebRequest -Uri "https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.ps1" -OutFile "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" - - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Version 2.1.818 -InstallDir $env:DOTNET_INSTALL_DIR' - - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Version 3.1.414 -InstallDir $env:DOTNET_INSTALL_DIR' - - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Version 5.0.402 -InstallDir $env:DOTNET_INSTALL_DIR' - - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Version 6.0.100 -InstallDir $env:DOTNET_INSTALL_DIR' + - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Version 5.0.408 -InstallDir $env:DOTNET_INSTALL_DIR' + - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Version 6.0.405 -InstallDir $env:DOTNET_INSTALL_DIR' + - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Version 7.0.102 -InstallDir $env:DOTNET_INSTALL_DIR' - ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path" - ps: dotnet --info diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 727dfd7..4903ba5 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "cake.tool": { - "version": "0.38.5", + "version": "1.3.0", "commands": [ "dotnet-cake" ] diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 2fdc831..0421cff 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,20 +8,14 @@ updates: open-pull-requests-limit: 10 ignore: - dependency-name: Cake.Core - versions: - - "(,3.0)" + update-types: ["version-update:semver-minor"] - dependency-name: Cake.Testing - versions: - - "(,3.0)" + update-types: ["version-update:semver-minor"] - dependency-name: Cake.AzureDevOps - versions: - - "> 1.0.0, < 2" + update-types: ["version-update:semver-minor"] - dependency-name: Cake.Issues - versions: - - "> 1.0.0, < 2" + update-types: ["version-update:semver-minor"] - dependency-name: Cake.Issues.Testing - versions: - - "> 1.0.0, < 2" + update-types: ["version-update:semver-minor"] - dependency-name: Cake.Issues.PullRequests - versions: - - "> 1.0.0, < 2" \ No newline at end of file + update-types: ["version-update:semver-minor"] \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3735be4..e373d58 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -14,6 +14,16 @@ jobs: pool: vmImage: 'windows-2022' steps: + # .NET 5 required for GitVersion + - task: UseDotNet@2 + inputs: + version: '5.x' + - task: UseDotNet@2 + inputs: + version: '6.x' + - task: UseDotNet@2 + inputs: + version: '7.x' - powershell: | $ENV:CAKE_SKIP_GITVERSION=([string]::IsNullOrEmpty($ENV:SYSTEM_PULLREQUEST_PULLREQUESTID) -eq $False).ToString() .\build.ps1 @@ -22,34 +32,36 @@ jobs: - job: macOS pool: - vmImage: 'macOS-10.15' + vmImage: 'macOS-11' steps: + # .NET 5 required for GitVersion - task: UseDotNet@2 inputs: - version: '6.x' + version: '5.x' - task: UseDotNet@2 inputs: - version: '5.x' + version: '6.x' - task: UseDotNet@2 inputs: - version: '3.x' + version: '7.x' - bash: | ./build.sh displayName: 'Cake Build' - job: Ubuntu pool: - vmImage: 'ubuntu-18.04' + vmImage: 'ubuntu-20.04' steps: + # .NET 5 required for GitVersion - task: UseDotNet@2 inputs: - version: '6.x' + version: '5.x' - task: UseDotNet@2 inputs: - version: '5.x' + version: '6.x' - task: UseDotNet@2 inputs: - version: '3.x' + version: '7.x' - bash: | ./build.sh --verbosity=diagnostic displayName: 'Cake Build' \ No newline at end of file diff --git a/global.json b/global.json index c31f98b..e981252 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "sdk": { "allowPrerelease": true, - "version": "6.0.100", + "version": "7.0.100", "rollForward": "latestFeature" } } \ No newline at end of file diff --git a/recipe.cake b/recipe.cake index 14f7c43..224c42d 100644 --- a/recipe.cake +++ b/recipe.cake @@ -1,4 +1,8 @@ -#load nuget:?package=Cake.Recipe&version=2.2.1 +#load nuget:?package=Cake.Recipe&version=3.0.0 + +//************************************************************************************************* +// Settings +//************************************************************************************************* Environment.SetVariableNames(); @@ -10,27 +14,37 @@ BuildParameters.SetParameters( repositoryOwner: "cake-contrib", repositoryName: "Cake.Issues.PullRequests.AzureDevOps", appVeyorAccountName: "cakecontrib", + shouldRunCoveralls: false, // Disabled because it's currently failing shouldGenerateDocumentation: false, - shouldCalculateVersion: true, - shouldRunDupFinder: false, // dupFinder is missing in 2021.3.0-eap - shouldRunCodecov: false, shouldRunDotNetCorePack: true); BuildParameters.PrintParameters(Context); ToolSettings.SetToolSettings( context: Context, - dupFinderExcludePattern: new string[] { BuildParameters.RootDirectoryPath + "/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/*.cs" }, testCoverageFilter: "+[*]* -[xunit.*]* -[Cake.Core]* -[Cake.Common]* -[Cake.Testing]* -[*.Tests]* -[Cake.Issues]* -[Cake.Issues.Testing]* -[Cake.Issues.PullRequests]* -[Cake.AzureDevOps]* -[Shouldly]* -[DiffEngine]* -[EmptyFiles]*", testCoverageExcludeByAttribute: "*.ExcludeFromCodeCoverage*", testCoverageExcludeByFile: "*/*Designer.cs;*/*.g.cs;*/*.g.i.cs"); -// Workaround until https://github.com/cake-contrib/Cake.Recipe/issues/862 has been fixed in Cake.Recipe -ToolSettings.SetToolPreprocessorDirectives( - reSharperTools: "#tool nuget:?package=JetBrains.ReSharper.CommandLineTools&version=2021.3.1", - gitVersionGlobalTool: "#tool dotnet:?package=GitVersion.Tool&version=5.8.1"); +//************************************************************************************************* +// Custom tasks +//************************************************************************************************* + +Task("BreakBuildOnIssues") + .Description("Breaks build if any issues in the code are found.") + .Does((data) => +{ + if (data.Issues.Any()) + { + throw new Exception("Issues found in code."); + } +}); + +IssuesBuildTasks.IssuesTask + .IsDependentOn("BreakBuildOnIssues"); -// Disable Upload-Coveralls-Report task since it fails to install the tool on AppVeyor -BuildParameters.Tasks.UploadCoverallsReportTask.WithCriteria(() => false); +//************************************************************************************************* +// Execution +//************************************************************************************************* Build.RunDotNetCore(); diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/AzureDevOpsPullRequestSystemSettingsTests.cs b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/AzureDevOpsPullRequestSystemSettingsTests.cs index 02956b9..b5733e0 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/AzureDevOpsPullRequestSystemSettingsTests.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/AzureDevOpsPullRequestSystemSettingsTests.cs @@ -5,6 +5,7 @@ using Cake.Issues.Testing; using Xunit; + // ReSharper disable once ClassNeverInstantiated.Global public sealed class AzureDevOpsPullRequestSystemSettingsTests { public sealed class TheCtor diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/AzureDevOpsPullRequestSystemTests.cs b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/AzureDevOpsPullRequestSystemTests.cs index 9e68d3a..73bea30 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/AzureDevOpsPullRequestSystemTests.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/AzureDevOpsPullRequestSystemTests.cs @@ -7,6 +7,7 @@ using Cake.Testing; using Xunit; + // ReSharper disable once ClassNeverInstantiated.Global public sealed class AzureDevOpsPullRequestSystemTests { public sealed class TheCtor @@ -15,7 +16,7 @@ public sealed class TheCtor public void Should_Throw_If_Log_Is_Null() { // Given - ICakeLog log = null; + const ICakeLog log = null; var settings = new AzureDevOpsPullRequestSystemSettings( new Uri("https://google.com"), @@ -34,7 +35,7 @@ public void Should_Throw_If_Settings_Are_Null() { // Given var log = new FakeLog(); - AzureDevOpsPullRequestSystemSettings settings = null; + const AzureDevOpsPullRequestSystemSettings settings = null; // When var result = Record.Exception(() => new AzureDevOpsPullRequestSystem(log, settings)); diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Cake.Issues.PullRequests.AzureDevOps.Tests.csproj b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Cake.Issues.PullRequests.AzureDevOps.Tests.csproj index 9239395..1dfc99e 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Cake.Issues.PullRequests.AzureDevOps.Tests.csproj +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Cake.Issues.PullRequests.AzureDevOps.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1;net5.0;net6.0 + net6.0;net7.0 false Cake.Issues.PullRequests.AzureDevOps Copyright © BBT Software AG and contributors @@ -15,17 +15,17 @@ - - - - - - - + + + + + + + - - - + + + diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsCheckingCommitIdCapabilityTests.cs b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsCheckingCommitIdCapabilityTests.cs index f433063..900eb8a 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsCheckingCommitIdCapabilityTests.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsCheckingCommitIdCapabilityTests.cs @@ -7,6 +7,7 @@ using NSubstitute; using Xunit; + // ReSharper disable once ClassNeverInstantiated.Global public sealed class AzureDevOpsCheckingCommitIdCapabilityTests { public sealed class TheCtor @@ -15,7 +16,7 @@ public sealed class TheCtor public void Should_Throw_If_Log_Is_Null() { // Given - ICakeLog log = null; + const ICakeLog log = null; var pullRequestSystem = Substitute.For(); // When @@ -30,7 +31,7 @@ public void Should_Throw_If_PullRequestSystem_Is_Null() { // Given var log = new FakeLog(); - AzureDevOpsPullRequestSystem pullRequestSystem = null; + const AzureDevOpsPullRequestSystem pullRequestSystem = null; // When var result = Record.Exception(() => new AzureDevOpsCheckingCommitIdCapability(log, pullRequestSystem)); diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsDiscussionThreadsCapabilityTests.cs b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsDiscussionThreadsCapabilityTests.cs index 2a04fd4..6991f3b 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsDiscussionThreadsCapabilityTests.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsDiscussionThreadsCapabilityTests.cs @@ -7,6 +7,7 @@ using NSubstitute; using Xunit; + // ReSharper disable once ClassNeverInstantiated.Global public sealed class AzureDevOpsDiscussionThreadsCapabilityTests { public sealed class TheCtor @@ -15,7 +16,7 @@ public sealed class TheCtor public void Should_Throw_If_Log_Is_Null() { // Given - ICakeLog log = null; + const ICakeLog log = null; var pullRequestSystem = Substitute.For(); // When @@ -30,7 +31,7 @@ public void Should_Throw_If_PullRequestSystem_Is_Null() { // Given var log = new FakeLog(); - AzureDevOpsPullRequestSystem pullRequestSystem = null; + const AzureDevOpsPullRequestSystem pullRequestSystem = null; // When var result = Record.Exception(() => new AzureDevOpsDiscussionThreadsCapability(log, pullRequestSystem)); diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsFilteringByModifiedFilesCapabilityTests.cs b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsFilteringByModifiedFilesCapabilityTests.cs index f6172e6..a709525 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsFilteringByModifiedFilesCapabilityTests.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/AzureDevOpsFilteringByModifiedFilesCapabilityTests.cs @@ -7,6 +7,7 @@ using NSubstitute; using Xunit; + // ReSharper disable once ClassNeverInstantiated.Global public sealed class AzureDevOpsFilteringByModifiedFilesCapabilityTests { public sealed class TheCtor @@ -15,7 +16,7 @@ public sealed class TheCtor public void Should_Throw_If_Log_Is_Null() { // Given - ICakeLog log = null; + const ICakeLog log = null; var pullRequestSystem = Substitute.For(); // When @@ -30,7 +31,7 @@ public void Should_Throw_If_PullRequestSystem_Is_Null() { // Given var log = new FakeLog(); - AzureDevOpsPullRequestSystem pullRequestSystem = null; + const AzureDevOpsPullRequestSystem pullRequestSystem = null; // When var result = Record.Exception(() => new AzureDevOpsFilteringByModifiedFilesCapability(log, pullRequestSystem)); diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/CommentExtensionsTests.cs b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/CommentExtensionsTests.cs index 8dec569..18ad15c 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/CommentExtensionsTests.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/CommentExtensionsTests.cs @@ -6,6 +6,7 @@ using Shouldly; using Xunit; + // ReSharper disable once ClassNeverInstantiated.Global public sealed class CommentExtensionsTests { public sealed class TheToPullRequestDiscussionCommentExtension @@ -14,7 +15,7 @@ public sealed class TheToPullRequestDiscussionCommentExtension public void Should_Throw_If_Comment_Is_Null() { // Given - AzureDevOpsComment comment = null; + const AzureDevOpsComment comment = null; // When var result = Record.Exception(() => comment.ToPullRequestDiscussionComment()); @@ -27,7 +28,7 @@ public void Should_Throw_If_Comment_Is_Null() public void Should_Set_Correct_Content() { // Given - var content = "foo"; + const string content = "foo"; var comment = new AzureDevOpsComment { diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/CommentThreadStatusExtensionsTests.cs b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/CommentThreadStatusExtensionsTests.cs index 40ab28e..16bb576 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/CommentThreadStatusExtensionsTests.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/CommentThreadStatusExtensionsTests.cs @@ -5,6 +5,7 @@ using Shouldly; using Xunit; + // ReSharper disable once ClassNeverInstantiated.Global public sealed class CommentThreadStatusExtensionsTests { public sealed class TheToPullRequestDiscussionStatusExtension diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/GitPullRequestCommentThreadExtensionsTests.cs b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/GitPullRequestCommentThreadExtensionsTests.cs index 1fac687..e90013a 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/GitPullRequestCommentThreadExtensionsTests.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/GitPullRequestCommentThreadExtensionsTests.cs @@ -8,6 +8,7 @@ using Shouldly; using Xunit; + // ReSharper disable once ClassNeverInstantiated.Global public sealed class GitPullRequestCommentThreadExtensionsTests { public sealed class TheToPullRequestDiscussionThreadExtension @@ -16,7 +17,7 @@ public sealed class TheToPullRequestDiscussionThreadExtension public void Should_Throw_If_Thread_Is_Null() { // Given - AzureDevOpsPullRequestCommentThread thread = null; + const AzureDevOpsPullRequestCommentThread thread = null; // When var result = Record.Exception(() => thread.ToPullRequestDiscussionThread()); @@ -71,9 +72,9 @@ public void Should_Not_Throw_If_Properties_Are_Null() public void Should_Set_Correct_Id() { // Given - var id = 123; - var status = AzureDevOpsCommentThreadStatus.Active; - var filePath = "/foo.cs"; + const int id = 123; + const AzureDevOpsCommentThreadStatus status = AzureDevOpsCommentThreadStatus.Active; + const string filePath = "/foo.cs"; var thread = new AzureDevOpsPullRequestCommentThread { @@ -118,8 +119,8 @@ public void Should_Set_Correct_Status( PullRequestDiscussionStatus expectedResult) { // Given - var id = 123; - var filePath = "/foo.cs"; + const int id = 123; + const string filePath = "/foo.cs"; var thread = new AzureDevOpsPullRequestCommentThread { @@ -142,8 +143,8 @@ public void Should_Set_Correct_Status( public void Should_Set_Correct_FilePath(string filePath, string expectedResult) { // Given - var id = 123; - var status = AzureDevOpsCommentThreadStatus.Active; + const int id = 123; + const AzureDevOpsCommentThreadStatus status = AzureDevOpsCommentThreadStatus.Active; var thread = new AzureDevOpsPullRequestCommentThread { @@ -185,11 +186,11 @@ public void Should_Set_Correct_FilePath_If_ThreadContext_Is_Null() public void Should_Set_Correct_Comments() { // Given - var id = 123; - var status = AzureDevOpsCommentThreadStatus.Active; - var filePath = "/foo.cs"; - var commentContent = "foo"; - var commentIsDeleted = false; + const int id = 123; + const AzureDevOpsCommentThreadStatus status = AzureDevOpsCommentThreadStatus.Active; + const string filePath = "/foo.cs"; + const string commentContent = "foo"; + const bool commentIsDeleted = false; var thread = new AzureDevOpsPullRequestCommentThread { @@ -198,7 +199,7 @@ public void Should_Set_Correct_Comments() FilePath = filePath, Comments = new List { - new AzureDevOpsComment() + new () { Content = commentContent, IsDeleted = commentIsDeleted, @@ -220,10 +221,10 @@ public void Should_Set_Correct_Comments() public void Should_Set_Correct_CommentSource() { // Given - var id = 123; - var status = AzureDevOpsCommentThreadStatus.Active; - var filePath = "/foo.cs"; - var commentSource = "foo"; + const int id = 123; + const AzureDevOpsCommentThreadStatus status = AzureDevOpsCommentThreadStatus.Active; + const string filePath = "/foo.cs"; + const string commentSource = "foo"; var thread = new AzureDevOpsPullRequestCommentThread { @@ -246,10 +247,10 @@ public void Should_Set_Correct_CommentSource() public void Should_Set_Correct_ProviderType() { // Given - var id = 123; - var status = AzureDevOpsCommentThreadStatus.Active; - var filePath = "/foo.cs"; - var providerType = "foo"; + const int id = 123; + const AzureDevOpsCommentThreadStatus status = AzureDevOpsCommentThreadStatus.Active; + const string filePath = "/foo.cs"; + const string providerType = "foo"; var thread = new AzureDevOpsPullRequestCommentThread { @@ -295,8 +296,8 @@ public void Should_Set_Correct_Resolution( PullRequestDiscussionResolution expectedResult) { // Given - var id = 123; - var filePath = "/foo.cs"; + const int id = 123; + const string filePath = "/foo.cs"; var thread = new AzureDevOpsPullRequestCommentThread { @@ -321,7 +322,7 @@ public sealed class TheGetCommentSourceExtension public void Should_Throw_If_Thread_Is_Null() { // Given - AzureDevOpsPullRequestCommentThread thread = null; + const AzureDevOpsPullRequestCommentThread thread = null; // When var result = Record.Exception(() => thread.GetCommentSource()); @@ -355,7 +356,7 @@ public void Should_Not_Throw_If_Properties_Are_Null() public void Should_Return_Comment_Source() { // Given - var commentSource = "foo"; + const string commentSource = "foo"; var thread = new AzureDevOpsPullRequestCommentThread { @@ -381,7 +382,7 @@ public sealed class TheGetProviderTypeExtension public void Should_Throw_If_Thread_Is_Null() { // Given - AzureDevOpsPullRequestCommentThread thread = null; + const AzureDevOpsPullRequestCommentThread thread = null; // When var result = Record.Exception(() => thread.GetProviderType()); @@ -415,7 +416,7 @@ public void Should_Not_Throw_If_Properties_Are_Null() public void Should_Return_ProviderType() { // Given - var providerType = "fooProv"; + const string providerType = "fooProv"; var thread = new AzureDevOpsPullRequestCommentThread { @@ -441,8 +442,8 @@ public sealed class TheSetCommentSourceExtension public void Should_Throw_If_Thread_Is_Null() { // Given - AzureDevOpsPullRequestCommentThread thread = null; - var value = "foo"; + const AzureDevOpsPullRequestCommentThread thread = null; + const string value = "foo"; // When var result = Record.Exception(() => thread.SetCommentSource(value)); @@ -464,7 +465,7 @@ public void Should_Throw_If_Properties_Are_Null() Comments = new List(), Properties = null, }; - var value = "foo"; + const string value = "foo"; // When var result = Record.Exception(() => thread.SetCommentSource(value)); @@ -477,7 +478,7 @@ public void Should_Throw_If_Properties_Are_Null() public void Should_Set_Comment_Source() { // Given - var commentSource = "foo"; + const string commentSource = "foo"; var thread = new AzureDevOpsPullRequestCommentThread { @@ -502,8 +503,8 @@ public sealed class TheSetProviderTypeExtension public void Should_Throw_If_Thread_Is_Null() { // Given - AzureDevOpsPullRequestCommentThread thread = null; - var value = "foo"; + const AzureDevOpsPullRequestCommentThread thread = null; + const string value = "foo"; // When var result = Record.Exception(() => thread.SetProviderType(value)); @@ -538,7 +539,7 @@ public void Should_Throw_If_Properties_Are_Null() public void Should_Set_ProviderType() { // Given - var providerType = "provType"; + const string providerType = "provType"; var thread = new AzureDevOpsPullRequestCommentThread { @@ -563,8 +564,8 @@ public sealed class TheIsCommentSourceExtension public void Should_Throw_If_Thread_Is_Null() { // Given - AzureDevOpsPullRequestCommentThread thread = null; - var value = "foo"; + const AzureDevOpsPullRequestCommentThread thread = null; + const string value = "foo"; // When var result = Record.Exception(() => thread.IsCommentSource(value)); @@ -586,7 +587,7 @@ public void Should_Not_Throw_If_Properties_Are_Null() Comments = new List(), Properties = null, }; - var value = "foo"; + const string value = "foo"; // When var result = thread.IsCommentSource(value); @@ -599,7 +600,7 @@ public void Should_Not_Throw_If_Properties_Are_Null() public void Should_Return_True_For_Existing_Comment_Source() { // Given - var commentSource = "foo"; + const string commentSource = "foo"; var thread = new AzureDevOpsPullRequestCommentThread { @@ -647,7 +648,7 @@ public sealed class TheGetIssueMessageExtension public void Should_Throw_If_Thread_Is_Null() { // Given - AzureDevOpsPullRequestCommentThread thread = null; + const AzureDevOpsPullRequestCommentThread thread = null; // When var result = Record.Exception(() => thread.GetIssueMessage()); @@ -681,7 +682,7 @@ public void Should_Not_Throw_If_Properties_Are_Null() public void Should_Return_Message() { // Given - var message = "foo"; + const string message = "foo"; var thread = new AzureDevOpsPullRequestCommentThread { @@ -707,8 +708,8 @@ public sealed class TheSetIssueMessageExtension public void Should_Throw_If_Thread_Is_Null() { // Given - AzureDevOpsPullRequestCommentThread thread = null; - var value = "foo"; + const AzureDevOpsPullRequestCommentThread thread = null; + const string value = "foo"; // When var result = Record.Exception(() => thread.SetIssueMessage(value)); @@ -730,7 +731,7 @@ public void Should_Throw_If_Properties_Are_Null() Comments = new List(), Properties = null, }; - var value = "foo"; + const string value = "foo"; // When var result = Record.Exception(() => thread.SetIssueMessage(value)); @@ -743,7 +744,7 @@ public void Should_Throw_If_Properties_Are_Null() public void Should_Return_Message() { // Given - var message = "foo"; + const string message = "foo"; var thread = new AzureDevOpsPullRequestCommentThread { diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/ContentProviderTests.cs b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/ContentProviderTests.cs index d727869..2c0be3f 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/ContentProviderTests.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/ContentProviderTests.cs @@ -4,6 +4,7 @@ using Shouldly; using Xunit; + // ReSharper disable once ClassNeverInstantiated.Global public sealed class ContentProviderTests { public sealed class TheGetContentMethod diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.sln.DotSettings b/src/Cake.Issues.PullRequests.AzureDevOps.sln.DotSettings index 4158618..1e74221 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.sln.DotSettings +++ b/src/Cake.Issues.PullRequests.AzureDevOps.sln.DotSettings @@ -1,8 +1,14 @@  DO_NOT_SHOW - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - Field, Property - True - True - True - \ No newline at end of file + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + + DO_NOT_SHOW + DO_NOT_SHOW + Field, Property, Event, Method + + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> \ No newline at end of file diff --git a/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystem.cs b/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystem.cs index 7add89c..5b5a8f7 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystem.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystem.cs @@ -146,38 +146,47 @@ private IEnumerable CreateDiscussionThreads // ReSharper disable once PossibleMultipleEnumeration issues.NotNull(nameof(issues)); + if (this.azureDevOpsPullRequest.CodeReviewId <= 0) + { + this.Log.Error("Skipping creation of discussion thread since code review ID is not set."); + return new List(); + } + this.Log.Verbose("Creating new discussion threads"); - var result = new List(); // Code flow properties - var iterationId = 0; - IEnumerable changes = null; - - if (this.azureDevOpsPullRequest.CodeReviewId > 0) - { - iterationId = this.GetCodeFlowLatestIterationId(); - changes = this.GetCodeFlowChanges(iterationId); - } + var iterationId = this.GetCodeFlowLatestIterationId(); + var changes = this.GetCodeFlowChanges(iterationId).ToList(); // Filter issues not related to a file. if (!this.settings.ReportIssuesNotRelatedToAFile) { + // ReSharper disable once PossibleMultipleEnumeration issues = issues.Where(x => x.AffectedFileRelativePath != null); } + var result = new List(); + // ReSharper disable once PossibleMultipleEnumeration foreach (var issue in issues) { + var changeTrackingId = + this.TryGetCodeFlowChangeTrackingId(changes, issue.AffectedFileRelativePath); + if (changeTrackingId < 0) + { + // Don't post comment if we couldn't determine the change. + this.Log.Information( + "Skipping discussion comment for the issue at line {0} from {1} since change tracking ID could not be determined", + issue.Line, + issue.AffectedFileRelativePath); + continue; + } + this.Log.Information( "Creating a discussion comment for the issue at line {0} from {1}", issue.Line, issue.AffectedFileRelativePath); - var newThread = new AzureDevOpsPullRequestCommentThread() - { - Status = AzureDevOpsCommentThreadStatus.Active, - }; - var discussionComment = new AzureDevOpsComment { CommentType = AzureDevOpsCommentType.System, @@ -185,27 +194,37 @@ private IEnumerable CreateDiscussionThreads Content = ContentProvider.GetContent(issue), }; - if (!this.AddThreadProperties(newThread, changes, issue, iterationId, commentSource)) + var newThread = new AzureDevOpsPullRequestCommentThread() { - continue; - } + Status = AzureDevOpsCommentThreadStatus.Active, + Comments = new List { discussionComment }, + Properties = this.GetThreadProperties(changeTrackingId, issue, iterationId), + }; + + // Add a custom property to be able to distinguish all comments created this way. + newThread.SetCommentSource(commentSource); + + // Add custom property for identifying the comment for subsequent runs + newThread.SetCommentIdentifier(issue.Identifier); + + // Add a custom property to be able to distinguish all comments by provider type later on + newThread.SetProviderType(issue.ProviderType); + + // Add a custom property to be able to return issue message from existing threads, + // without any formatting done by this addin, back to Cake.Issues.PullRequests. + newThread.SetIssueMessage(issue.MessageText); - newThread.Comments = new List { discussionComment }; result.Add(newThread); } return result; } - private bool AddThreadProperties( - AzureDevOpsPullRequestCommentThread thread, - IEnumerable changes, + private Dictionary GetThreadProperties( + int changeTrackingId, IIssue issue, - int iterationId, - string commentSource) + int iterationId) { - thread.NotNull(nameof(thread)); - changes.NotNull(nameof(changes)); issue.NotNull(nameof(issue)); var properties = new Dictionary(); @@ -214,14 +233,6 @@ private bool AddThreadProperties( { if (this.azureDevOpsPullRequest.CodeReviewId > 0) { - var changeTrackingId = - this.TryGetCodeFlowChangeTrackingId(changes, issue.AffectedFileRelativePath); - if (changeTrackingId < 0) - { - // Don't post comment if we couldn't determine the change. - return false; - } - AddCodeFlowProperties(issue, iterationId, changeTrackingId, properties); } else @@ -233,22 +244,7 @@ private bool AddThreadProperties( // An Azure DevOps UI extension will recognize this and format the comments differently. properties.Add("CodeAnalysisThreadType", "CodeAnalysisIssue"); - thread.Properties = properties; - - // Add a custom property to be able to distinguish all comments created this way. - thread.SetCommentSource(commentSource); - - // Add custom property for identifying the comment for subsequent runs - thread.SetCommentIdentifier(issue.Identifier); - - // Add a custom property to be able to distinguish all comments by provider type later on - thread.SetProviderType(issue.ProviderType); - - // Add a custom property to be able to return issue message from existing threads, - // without any formatting done by this addin, back to Cake.Issues.PullRequests. - thread.SetIssueMessage(issue.MessageText); - - return true; + return properties; } private int GetCodeFlowLatestIterationId() @@ -260,45 +256,53 @@ private int GetCodeFlowLatestIterationId() private IEnumerable GetCodeFlowChanges(int iterationId) { - var changes = this.azureDevOpsPullRequest.GetIterationChanges(iterationId); + var changes = + this.azureDevOpsPullRequest.GetIterationChanges(iterationId); - if (changes != null) + if (changes == null) { - this.Log.Verbose("Change count: {0}", changes.Count()); + this.Log.Warning("Changes for iteration {0} could not be detected", iterationId); + return new List(); } - return changes; + var result = changes.ToList(); + this.Log.Verbose("Change count: {0}", result.Count); + + return result; } private int TryGetCodeFlowChangeTrackingId(IEnumerable changes, FilePath path) { + // ReSharper disable once PossibleMultipleEnumeration changes.NotNull(nameof(changes)); path.NotNull(nameof(path)); - var change = changes.Where(x => x.ItemPath != null && x.ItemPath.FullPath == "/" + path.ToString()).ToList(); - - if (change.Count == 0) - { - this.Log.Error( - "Cannot post a comment for the file {0} because no changes on the pull request server could be found.", - path); - return -1; - } + // ReSharper disable once PossibleMultipleEnumeration + var change = + changes + .Where(x => x.ItemPath != null && x.ItemPath.FullPath == "/" + path) + .ToList(); - if (change.Count > 1) + switch (change.Count) { - this.Log.Error( - "Cannot post a comment for the file {0} because more than one change has been found on the pull request server:" + Environment.NewLine + "{1}", - path, - string.Join( - Environment.NewLine, - change.Select( - x => string.Format( - CultureInfo.InvariantCulture, - " ID: {0}, Path: {1}", - x.ChangeId, - x.ItemPath)))); - return -1; + case 0: + this.Log.Error( + "Cannot post a comment for the file {0} because no changes on the pull request server could be found.", + path); + return -1; + case > 1: + this.Log.Error( + "Cannot post a comment for the file {0} because more than one change has been found on the pull request server:" + Environment.NewLine + "{1}", + path, + string.Join( + Environment.NewLine, + change.Select( + x => string.Format( + CultureInfo.InvariantCulture, + " ID: {0}, Path: {1}", + x.ChangeId, + x.ItemPath)))); + return -1; } var changeTrackingId = change.Single().ChangeTrackingId; diff --git a/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystemSettings.cs b/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystemSettings.cs index 54983ac..31e5420 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystemSettings.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystemSettings.cs @@ -71,6 +71,7 @@ public AzureDevOpsPullRequestSystemSettings() /// is still up to date before posting comments. /// Default value is true. /// + // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global public bool CheckCommitId { get; set; } = true; /// @@ -78,6 +79,7 @@ public AzureDevOpsPullRequestSystemSettings() /// resolved oder reopened. /// Default value is true. /// + // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global public bool ManageDiscussionThreadStatus { get; set; } = true; /// @@ -85,6 +87,7 @@ public AzureDevOpsPullRequestSystemSettings() /// as comments or not. /// Default value is false. /// - public bool ReportIssuesNotRelatedToAFile { get; set; } = false; + // ReSharper disable once UnusedAutoPropertyAccessor.Global + public bool ReportIssuesNotRelatedToAFile { get; set; } } } diff --git a/src/Cake.Issues.PullRequests.AzureDevOps/Cake.Issues.PullRequests.AzureDevOps.csproj b/src/Cake.Issues.PullRequests.AzureDevOps/Cake.Issues.PullRequests.AzureDevOps.csproj index 8e030b9..9f6ec75 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps/Cake.Issues.PullRequests.AzureDevOps.csproj +++ b/src/Cake.Issues.PullRequests.AzureDevOps/Cake.Issues.PullRequests.AzureDevOps.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1;net5.0;net6.0 + net6.0;net7.0 bin\$(Configuration)\$(TargetFramework)\Cake.Issues.PullRequests.AzureDevOps.xml @@ -32,7 +32,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin MIT git https://github.com/cake-contrib/Cake.Issues.PullRequests.AzureDevOps.git - https://github.com/cake-contrib/Cake.Issues.PullRequests.AzureDevOps/releases/tag/2.0.0 + https://github.com/cake-contrib/Cake.Issues.PullRequests.AzureDevOps/releases/tag/3.0.0 @@ -41,11 +41,11 @@ See the Project Site for an overview of the whole ecosystem of addins for workin - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive