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 #181 from pascalberger/feature/gh-180
Browse files Browse the repository at this point in the history
(GH-180) Support IIssue.Identifier
  • Loading branch information
pascalberger authored Jul 18, 2020
2 parents 0f58fec + b5dd595 commit 3217412
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.33.0" />
<PackageReference Include="Cake.Issues" Version="0.9.0-beta0002" />
<PackageReference Include="Cake.Issues.PullRequests" Version="0.9.0-beta0001" />
<PackageReference Include="Cake.Issues.PullRequests" Version="0.9.0-beta0002" />
<PackageReference Include="Cake.Issues.Testing" Version="0.9.0-beta0002" />
<PackageReference Include="Cake.Testing" Version="0.33.0" />
<PackageReference Include="Cake.AzureDevOps" Version="0.4.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ private bool AddThreadProperties(
// 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 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 @@ -44,7 +44,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin
<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.33.0" PrivateAssets="All" />
<PackageReference Include="Cake.Issues" Version="0.9.0-beta0002" PrivateAssets="All" />
<PackageReference Include="Cake.Issues.PullRequests" Version="0.9.0-beta0001" PrivateAssets="All" />
<PackageReference Include="Cake.Issues.PullRequests" Version="0.9.0-beta0002" PrivateAssets="All" />
<PackageReference Include="Cake.AzureDevOps" Version="0.4.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ protected override IEnumerable<IPullRequestDiscussionThread> InternalFetchDiscus

var pullRequestThread = thread.ToPullRequestDiscussionThread();

// Comment identifier was introduced with Cake.Issues 0.9.0.
// To also support pull request written by previous versions of Cake.Issues
// we return the message without additional formatting in case no
// identifier was set on the thread.
if (string.IsNullOrEmpty(pullRequestThread.CommentIdentifier))
{
pullRequestThread.CommentIdentifier = thread.GetIssueMessage();
}

// Assuming that the first comment is the one written by this addin, we replace the content
// containing additional formatting done by this addin with the original issue message to
// allow Cake.Issues.PullRequests to do a proper comparison to find out which issues already were posted.
// containing additional formatting done by this addin with the original issue message.
pullRequestThread.Comments.First().Content = thread.GetIssueMessage();

threadList.Add(pullRequestThread);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
internal static class AzureDevOpsPullRequestCommentThreadExtensions
{
private const string CommentSourcePropertyName = "CakeIssuesCommentSource";
private const string CommentIdentifierPropertyName = "CakeIssuesCommentIdentifier";
private const string IssueMessagePropertyName = "CakeIssuesIssueMessage";

/// <summary>
Expand All @@ -27,6 +28,7 @@ public static IPullRequestDiscussionThread ToPullRequestDiscussionThread(this Az
thread.Comments.Select(x => x.ToPullRequestDiscussionComment()))
{
CommentSource = thread.GetCommentSource(),
CommentIdentifier = thread.GetCommentIdentifier(),
Resolution = thread.Status.ToPullRequestDiscussionResolution(),
};
}
Expand Down Expand Up @@ -69,6 +71,30 @@ public static bool IsCommentSource(this AzureDevOpsPullRequestCommentThread thre
return thread.GetCommentSource() == value;
}

/// <summary>
/// Gets the comment identifier to identify the issue for which the comment was created.
/// </summary>
/// <param name="thread">Thread to get the value from.</param>
/// <returns>Comment identifier value.</returns>
public static string GetCommentIdentifier(this AzureDevOpsPullRequestCommentThread thread)
{
thread.NotNull(nameof(thread));

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

/// <summary>
/// Sets the comment identifier value used to identify the issue for which the comment was created.
/// </summary>
/// <param name="thread">Thread for which the value should be set.</param>
/// <param name="value">Value to set as comment identifier.</param>
public static void SetCommentIdentifier(this AzureDevOpsPullRequestCommentThread thread, string value)
{
thread.NotNull(nameof(thread));

thread.SetValue(CommentIdentifierPropertyName, value);
}

/// <summary>
/// Gets the original message of the issue as provided by Cake.Issues.PullRequests,
/// without any formatting done by this addin.
Expand Down

0 comments on commit 3217412

Please sign in to comment.