Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #183 from janniksam/feature/addProviderTypeAsExtPr…
Browse files Browse the repository at this point in the history
…operty

Add custom property ProviderType to AzureDevOpsPullRequestCommentThread
  • Loading branch information
pascalberger authored Jul 18, 2020
2 parents 3217412 + dca0466 commit 2c19302
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AzureDevOpsComment>(),
Properties = new Dictionary<string, object>(),
};
thread.SetProviderType(providerType);

// When
var result = thread.ToPullRequestDiscussionThread();

// Then
result.ProviderType.ShouldBe(providerType);
}

[Theory]
[InlineData(
AzureDevOpsCommentThreadStatus.Unknown,
Expand Down Expand Up @@ -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<AzureDevOpsComment>(),
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<AzureDevOpsComment>(),
Properties = new Dictionary<string, object>(),
};
thread.SetProviderType(providerType);

// When
var result = thread.GetProviderType();

// Then
result.ShouldBe(providerType);
}
}

public sealed class TheSetCommentSourceExtension
{
[Fact]
Expand Down Expand Up @@ -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<AzureDevOpsComment>(),
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<AzureDevOpsComment>(),
Properties = new Dictionary<string, object>(),
};

// When
thread.SetProviderType(providerType);

// Then
thread.GetProviderType().ShouldBe(providerType);
}
}

public sealed class TheIsCommentSourceExtension
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/Cake.Issues.PullRequests.AzureDevOps.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeThisQualifier/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ThisQualifier/INSTANCE_MEMBERS_QUALIFY_MEMBERS/@EntryValue">Field, Property</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/TRAILING_COMMA_IN_MULTILINE_LISTS/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AddImportsToDeepestScope/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/QualifiedUsingAtNestedScope/@EntryValue">True</s:Boolean>
</wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/// <summary>
/// Converts a <see cref="AzureDevOpsPullRequestCommentThread"/> from Azure DevOps to a <see cref="IPullRequestDiscussionThread"/> as used in this addin.
Expand All @@ -29,12 +30,13 @@ public static IPullRequestDiscussionThread ToPullRequestDiscussionThread(this Az
{
CommentSource = thread.GetCommentSource(),
CommentIdentifier = thread.GetCommentIdentifier(),
ProviderType = thread.GetProviderType(),
Resolution = thread.Status.ToPullRequestDiscussionResolution(),
};
}

/// <summary>
/// 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.
/// </summary>
/// <param name="thread">Thread to get the value from.</param>
/// <returns>Comment source value.</returns>
Expand All @@ -46,7 +48,7 @@ public static string GetCommentSource(this AzureDevOpsPullRequestCommentThread t
}

/// <summary>
/// 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.
/// </summary>
/// <param name="thread">Thread for which the value should be set.</param>
/// <param name="value">Value to set as comment source.</param>
Expand Down Expand Up @@ -119,5 +121,29 @@ public static void SetIssueMessage(this AzureDevOpsPullRequestCommentThread thre

thread.SetValue(IssueMessagePropertyName, value);
}

/// <summary>
/// Gets the provider type value used to identify specific provider origins later on when reading back existing issues.
/// </summary>
/// <param name="thread">Thread to get the value from.</param>
/// <returns>Comment source value.</returns>
public static string GetProviderType(this AzureDevOpsPullRequestCommentThread thread)
{
thread.NotNull(nameof(thread));

return thread.GetValue<string>(ProviderTypePropertyName);
}

/// <summary>
/// Sets the provider type value used to identify specific provider origins later on when reading back existing issues.
/// </summary>
/// <param name="thread">Thread for which the value should be set.</param>
/// <param name="value">Value to set as comment source.</param>
public static void SetProviderType(this AzureDevOpsPullRequestCommentThread thread, string value)
{
thread.NotNull(nameof(thread));

thread.SetValue(ProviderTypePropertyName, value);
}
}
}

0 comments on commit 2c19302

Please sign in to comment.