From d4711cf5e99648a82a901510a9c98d2ad7063130 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Sat, 18 Jul 2020 10:46:23 +0200 Subject: [PATCH 1/2] Update to Cake.Issues.PullRequests 0.9.0-beta.2 --- .../Cake.Issues.PullRequests.AzureDevOps.Tests.csproj | 2 +- .../Cake.Issues.PullRequests.AzureDevOps.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 27b7304..bbf49e5 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 @@ -17,7 +17,7 @@ - + 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 5953cbc..f551874 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps/Cake.Issues.PullRequests.AzureDevOps.csproj +++ b/src/Cake.Issues.PullRequests.AzureDevOps/Cake.Issues.PullRequests.AzureDevOps.csproj @@ -44,7 +44,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin - + From b5dd595eec4a758692b806e0007807fb4a1318ea Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Thu, 16 Jul 2020 23:42:09 +0200 Subject: [PATCH 2/2] (GH-180) Support IIssue.Identifier --- .../AzureDevOpsPullRequestSystem.cs | 3 +++ .../AzureDevOpsDiscussionThreadsCapability.cs | 12 +++++++-- ...evOpsPullRequestCommentThreadExtensions.cs | 26 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystem.cs b/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystem.cs index 17ca7ed..f619390 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystem.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps/AzureDevOpsPullRequestSystem.cs @@ -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); diff --git a/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsDiscussionThreadsCapability.cs b/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsDiscussionThreadsCapability.cs index ec22c9c..53b8351 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsDiscussionThreadsCapability.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsDiscussionThreadsCapability.cs @@ -34,9 +34,17 @@ protected override IEnumerable 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); diff --git a/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsPullRequestCommentThreadExtensions.cs b/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsPullRequestCommentThreadExtensions.cs index eb2fe0f..3c54c5d 100644 --- a/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsPullRequestCommentThreadExtensions.cs +++ b/src/Cake.Issues.PullRequests.AzureDevOps/Capabilities/AzureDevOpsPullRequestCommentThreadExtensions.cs @@ -9,6 +9,7 @@ internal static class AzureDevOpsPullRequestCommentThreadExtensions { private const string CommentSourcePropertyName = "CakeIssuesCommentSource"; + private const string CommentIdentifierPropertyName = "CakeIssuesCommentIdentifier"; private const string IssueMessagePropertyName = "CakeIssuesIssueMessage"; /// @@ -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(), }; } @@ -69,6 +71,30 @@ public static bool IsCommentSource(this AzureDevOpsPullRequestCommentThread thre return thread.GetCommentSource() == value; } + /// + /// Gets the comment identifier to identify the issue for which the comment was created. + /// + /// Thread to get the value from. + /// Comment identifier value. + public static string GetCommentIdentifier(this AzureDevOpsPullRequestCommentThread thread) + { + thread.NotNull(nameof(thread)); + + return thread.GetValue(CommentIdentifierPropertyName); + } + + /// + /// Sets the comment identifier value used to identify the issue for which the comment was created. + /// + /// Thread for which the value should be set. + /// Value to set as comment identifier. + public static void SetCommentIdentifier(this AzureDevOpsPullRequestCommentThread thread, string value) + { + thread.NotNull(nameof(thread)); + + thread.SetValue(CommentIdentifierPropertyName, value); + } + /// /// Gets the original message of the issue as provided by Cake.Issues.PullRequests, /// without any formatting done by this addin.