Пример #1
0
        /// <summary>
        /// Converts a <see cref="GitPullRequestCommentThread"/> from TFS to a <see cref="IPullRequestDiscussionThread"/> as used in this addin.
        /// </summary>
        /// <param name="thread">TFS thread to convert.</param>
        /// <returns>Converted thread.</returns>
        public static IPullRequestDiscussionThread ToPullRequestDiscussionThread(this GitPullRequestCommentThread thread)
        {
            thread.NotNull(nameof(thread));

            if (thread.Comments == null)
            {
                throw new InvalidOperationException("Comments list is not created.");
            }

            FilePath filePath = null;

            if (thread.ThreadContext != null && thread.ThreadContext.FilePath != null)
            {
                filePath = thread.ThreadContext.FilePath.TrimStart('/');
            }

            return(new PullRequestDiscussionThread(
                       thread.Id,
                       thread.Status.ToPullRequestDiscussionStatus(),
                       filePath,
                       thread.Comments.Select(x => x.ToPullRequestDiscussionComment()))
            {
                CommentSource = thread.GetCommentSource(),
                Resolution = thread.Status.ToPullRequestDiscussionResolution()
            });
        }
Пример #2
0
        /// <summary>
        /// Gets the original message of the issue as provided by Cake.Issues.PullRequests,
        /// without any formatting done by this addin.
        /// </summary>
        /// <param name="thread">Thread to get the value from.</param>
        /// <returns>Original message of the issue.</returns>
        public static string GetIssueMessage(this GitPullRequestCommentThread thread)
        {
            thread.NotNull(nameof(thread));

            if (thread.Properties == null)
            {
                throw new InvalidOperationException("Properties collection is not created.");
            }

            return(thread.Properties.GetValue(IssueMessagePropertyName, string.Empty));
        }
        /// <summary>
        /// Converts a <see cref="GitPullRequestCommentThread"/> from TFS to a <see cref="IPrcaDiscussionThread"/> as used in this addin.
        /// </summary>
        /// <param name="thread">TFS thread to convert.</param>
        /// <returns>Converted thread.</returns>
        public static IPrcaDiscussionThread ToPrcaDiscussionThread(this GitPullRequestCommentThread thread)
        {
            thread.NotNull(nameof(thread));

            return(new PrcaDiscussionThread(
                       thread.Id,
                       thread.Status.ToPrcaDiscussionStatus(),
                       new FilePath(thread.ThreadContext.FilePath.TrimStart('/')),
                       thread.Comments.Select(x => x.ToPrcaDiscussionComment()))
            {
                CommentSource = thread.GetCommentSource(),
            });
        }
Пример #4
0
        private bool AddThreadProperties(
            GitPullRequestCommentThread thread,
            GitPullRequestIterationChanges changes,
            IIssue issue,
            int iterationId,
            string commentSource)
        {
            thread.NotNull(nameof(thread));
            changes.NotNull(nameof(changes));
            issue.NotNull(nameof(issue));

            var properties = new PropertiesCollection();

            if (issue.AffectedFileRelativePath != null)
            {
                if (this.tfsPullRequest.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
                {
                    throw new NotSupportedException("Legacy code reviews are not supported.");
                }
            }

            // A VSTS 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 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.Message);

            return(true);
        }
        /// <summary>
        /// Sets a value in the thread properties.
        /// </summary>
        /// <typeparam name="T">Type of the value.</typeparam>
        /// <param name="thread">Thread for which the value should be set.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="value">Value to set.</param>
        private static void SetValue <T>(this GitPullRequestCommentThread thread, string propertyName, T value)
        {
            thread.NotNull(nameof(thread));
            propertyName.NotNullOrWhiteSpace(nameof(propertyName));

            if (thread.Properties == null)
            {
                throw new InvalidOperationException("Properties collection is not created.");
            }

            if (thread.Properties.ContainsKey(propertyName))
            {
                thread.Properties[propertyName] = value;
            }
            else
            {
                thread.Properties.Add(propertyName, value);
            }
        }
        /// <summary>
        /// Sets the original message of the issue as provided by Cake.Prca.
        /// </summary>
        /// <param name="thread">Thread for which the value should be set.</param>
        /// <param name="value">Value to set as the original message.</param>
        public static void SetIssueMessage(this GitPullRequestCommentThread thread, string value)
        {
            thread.NotNull(nameof(thread));

            thread.SetValue(IssueMessagePropertyName, value);
        }
        /// <summary>
        /// Gets the original message of the issue as provided by Cake.Prca,
        /// without any formatting done by this addin.
        /// </summary>
        /// <param name="thread">Thread to get the value from.</param>
        /// <returns>Original message of the issue.</returns>
        public static string GetIssueMessage(this GitPullRequestCommentThread thread)
        {
            thread.NotNull(nameof(thread));

            return(thread.Properties.GetValue(IssueMessagePropertyName, string.Empty));
        }
        /// <summary>
        /// Checks if the custom comment source value used to decorate comments created by this addin
        /// has a specific value.
        /// </summary>
        /// <param name="thread">Thread to check.</param>
        /// <param name="value">Value to check for.</param>
        /// <returns><c>True</c> if the value is identical, <c>False</c> otherwise.</returns>
        public static bool IsCommentSource(this GitPullRequestCommentThread thread, string value)
        {
            thread.NotNull(nameof(thread));

            return(thread.GetCommentSource() == value);
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureDevOpsPullRequestCommentThread"/> class.
        /// </summary>
        /// <param name="thread">The original comment thread in the Azue DevOps pull request.</param>
        internal AzureDevOpsPullRequestCommentThread(GitPullRequestCommentThread thread)
        {
            thread.NotNull(nameof(thread));

            this.thread = thread;
        }