diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/GitPullRequestCommentThreadExtensionsTests.cs b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/GitPullRequestCommentThreadExtensionsTests.cs index 9976b7f..ea3b0b1 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/GitPullRequestCommentThreadExtensionsTests.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Capabilities/GitPullRequestCommentThreadExtensionsTests.cs @@ -242,6 +242,32 @@ public void Should_Set_Correct_CommentSource() result.CommentSource.ShouldBe(commentSource); } + [Fact] + public void Should_Set_Correct_ProviderType() + { + // Given + var id = 123; + var status = AzureDevOpsCommentThreadStatus.Active; + var filePath = "/foo.cs"; + var providerType = "foo"; + var thread = + new AzureDevOpsPullRequestCommentThread + { + Id = id, + Status = status, + FilePath = filePath, + Comments = new List(), + Properties = new Dictionary(), + }; + thread.SetProviderType(providerType); + + // When + var result = thread.ToPullRequestDiscussionThread(); + + // Then + result.ProviderType.ShouldBe(providerType); + } + [Theory] [InlineData( AzureDevOpsCommentThreadStatus.Unknown, @@ -349,6 +375,66 @@ public void Should_Return_Comment_Source() } } + public sealed class TheGetProviderTypeExtension + { + [Fact] + public void Should_Throw_If_Thread_Is_Null() + { + // Given + AzureDevOpsPullRequestCommentThread thread = null; + + // When + var result = Record.Exception(() => thread.GetProviderType()); + + // Then + result.IsArgumentNullException("thread"); + } + + [Fact] + public void Should_Not_Throw_If_Properties_Are_Null() + { + // Given + var thread = + new AzureDevOpsPullRequestCommentThread + { + Id = 123, + Status = AzureDevOpsCommentThreadStatus.Active, + FilePath = "/foo.cs", + Comments = new List(), + Properties = null, + }; + + // When + var result = thread.GetProviderType(); + + // Then + result.ShouldBe(default); + } + + [Fact] + public void Should_Return_ProviderType() + { + // Given + var providerType = "fooProv"; + var thread = + new AzureDevOpsPullRequestCommentThread + { + Id = 123, + Status = AzureDevOpsCommentThreadStatus.Active, + FilePath = "/foo.cs", + Comments = new List(), + Properties = new Dictionary(), + }; + thread.SetProviderType(providerType); + + // When + var result = thread.GetProviderType(); + + // Then + result.ShouldBe(providerType); + } + } + public sealed class TheSetCommentSourceExtension { [Fact] @@ -410,6 +496,67 @@ public void Should_Set_Comment_Source() } } + public sealed class TheSetProviderTypeExtension + { + [Fact] + public void Should_Throw_If_Thread_Is_Null() + { + // Given + AzureDevOpsPullRequestCommentThread thread = null; + var value = "foo"; + + // When + var result = Record.Exception(() => thread.SetProviderType(value)); + + // Then + result.IsArgumentNullException("thread"); + } + + [Fact] + public void Should_Throw_If_Properties_Are_Null() + { + // Given + var thread = + new AzureDevOpsPullRequestCommentThread + { + Id = 123, + Status = AzureDevOpsCommentThreadStatus.Active, + FilePath = "/foo.cs", + Comments = new List(), + Properties = null, + }; + var value = "foo"; + + // When + var result = Record.Exception(() => thread.SetProviderType(value)); + + // Then + result.IsInvalidOperationException("Properties collection is not created."); + } + + [Fact] + public void Should_Set_ProviderType() + { + // Given + var providerType = "provType"; + var thread = + new AzureDevOpsPullRequestCommentThread + { + Id = 123, + Status = AzureDevOpsCommentThreadStatus.Active, + FilePath = "/foo.cs", + Comments = new List(), + Properties = new Dictionary(), + }; + + // When + thread.SetProviderType(providerType); + + // Then + thread.GetProviderType().ShouldBe(providerType); + } + } + public sealed class TheIsCommentSourceExtension { [Fact] diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Properties/AssemblyInfo.cs b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Properties/AssemblyInfo.cs index 98759e3..5680586 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Properties/AssemblyInfo.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps.Tests/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ -using System.Reflection; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/src/Cake.Issues.PullRequests.AzureDevOps.sln.DotSettings b/src/Cake.Issues.PullRequests.AzureDevOps.sln.DotSettings index 7cc51a4..4158618 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps.sln.DotSettings +++ b/src/Cake.Issues.PullRequests.AzureDevOps.sln.DotSettings @@ -1,3 +1,8 @@  DO_NOT_SHOW - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> \ No newline at end of file + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + Field, Property + True + True + True + \ 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 f619390..b6c15e8 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystem.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystem.cs @@ -241,6 +241,9 @@ private bool AddThreadProperties( // 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); diff --git a/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsPullRequestCommentThreadExtensions.cs b/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsPullRequestCommentThreadExtensions.cs index 3c54c5d..0b7fc2a 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsPullRequestCommentThreadExtensions.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsPullRequestCommentThreadExtensions.cs @@ -11,6 +11,7 @@ internal static class AzureDevOpsPullRequestCommentThreadExtensions private const string CommentSourcePropertyName = "CakeIssuesCommentSource"; private const string CommentIdentifierPropertyName = "CakeIssuesCommentIdentifier"; private const string IssueMessagePropertyName = "CakeIssuesIssueMessage"; + private const string ProviderTypePropertyName = "CakeIssuesProviderType"; /// /// Converts a from Azure DevOps to a as used in this addin. @@ -29,12 +30,13 @@ public static IPullRequestDiscussionThread ToPullRequestDiscussionThread(this Az { CommentSource = thread.GetCommentSource(), CommentIdentifier = thread.GetCommentIdentifier(), + ProviderType = thread.GetProviderType(), Resolution = thread.Status.ToPullRequestDiscussionResolution(), }; } /// - /// Gets the comment source value used to decorate comments created by this addin. + /// Gets the comment source value used to decorate comments created by this add-in. /// /// Thread to get the value from. /// Comment source value. @@ -46,7 +48,7 @@ public static string GetCommentSource(this AzureDevOpsPullRequestCommentThread t } /// - /// Sets the comment sourc e value used to decorate comments created by this addin. + /// Sets the comment source value used to decorate comments created by this addin. /// /// Thread for which the value should be set. /// Value to set as comment source. @@ -119,5 +121,29 @@ public static void SetIssueMessage(this AzureDevOpsPullRequestCommentThread thre thread.SetValue(IssueMessagePropertyName, value); } + + /// + /// Gets the provider type value used to identify specific provider origins later on when reading back existing issues. + /// + /// Thread to get the value from. + /// Comment source value. + public static string GetProviderType(this AzureDevOpsPullRequestCommentThread thread) + { + thread.NotNull(nameof(thread)); + + return thread.GetValue(ProviderTypePropertyName); + } + + /// + /// Sets the provider type value used to identify specific provider origins later on when reading back existing issues. + /// + /// Thread for which the value should be set. + /// Value to set as comment source. + public static void SetProviderType(this AzureDevOpsPullRequestCommentThread thread, string value) + { + thread.NotNull(nameof(thread)); + + thread.SetValue(ProviderTypePropertyName, value); + } } }