示例#1
0
        /// <summary>
        /// Returns threads that should be reopened.
        /// </summary>
        /// <param name="existingThreads">Existing discussion threads on the pull request.</param>
        /// <param name="issueComments">Issues and their related existing comments on the pull request.</param>
        /// <param name="reportIssuesToPullRequestSettings">Settings for posting the issues.</param>
        /// <returns>List of threads which should be reopened.</returns>
        private IEnumerable <IPullRequestDiscussionThread> GetThreadsToReopen(
            IList <IPullRequestDiscussionThread> existingThreads,
            IDictionary <IIssue, IssueCommentInfo> issueComments,
            ReportIssuesToPullRequestSettings reportIssuesToPullRequestSettings)
        {
            existingThreads.NotNull(nameof(existingThreads));
            issueComments.NotNull(nameof(issueComments));
            reportIssuesToPullRequestSettings.NotNull(nameof(reportIssuesToPullRequestSettings));

            var resolvedComments =
                new HashSet <IPullRequestDiscussionComment>(
                    issueComments.Values.SelectMany(x => x.ResolvedComments));

            var result =
                existingThreads.Where(
                    thread =>
                    thread.Status == PullRequestDiscussionStatus.Resolved &&
                    thread.CommentSource == reportIssuesToPullRequestSettings.CommentSource &&
                    thread.Comments.Any(x => resolvedComments.Contains(x))).ToList();

            this.log.Verbose(
                "Found {0} existing thread(s) that are resolved but still have an open issue.",
                result.Count);

            return(result);
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Orchestrator"/> class.
        /// </summary>
        /// <param name="log">Cake log instance.</param>
        /// <param name="pullRequestSystem">Object for accessing pull request system.
        /// <c>null</c> if only issues should be read.</param>
        /// <param name="settings">Settings.</param>
        public Orchestrator(
            ICakeLog log,
            IPullRequestSystem pullRequestSystem,
            ReportIssuesToPullRequestSettings settings)
        {
#pragma warning disable SA1123 // Do not place regions within elements
            #region DupFinder Exclusion
#pragma warning restore SA1123 // Do not place regions within elements

            log.NotNull(nameof(log));
            pullRequestSystem.NotNull(nameof(pullRequestSystem));
            settings.NotNull(nameof(settings));

            this.log = log;
            this.pullRequestSystem = pullRequestSystem;
            this.settings          = settings;

            #endregion

            // Initialize pull request system.
            this.log.Verbose("Initialize pull request system...");
            this.pullRequestSystemInitialized = this.pullRequestSystem.Initialize(this.settings);
            if (!this.pullRequestSystemInitialized)
            {
                this.log.Warning("Error initializing the pull request system.");
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="IssueFilterer"/> class.
        /// </summary>
        /// <param name="log">The Cake log instance.</param>
        /// <param name="pullRequestSystem">Pull request system to use.</param>
        /// <param name="settings">Settings to use.</param>
        public IssueFilterer(
            ICakeLog log,
            IPullRequestSystem pullRequestSystem,
            ReportIssuesToPullRequestSettings settings)
        {
#pragma warning disable SA1123 // Do not place regions within elements
            #region DupFinder Exclusion
#pragma warning restore SA1123 // Do not place regions within elements

            log.NotNull(nameof(log));
            pullRequestSystem.NotNull(nameof(pullRequestSystem));
            settings.NotNull(nameof(settings));

            this.log = log;
            this.pullRequestSystem = pullRequestSystem;
            this.settings          = settings;

            #endregion
        }
        public static PullRequestIssueResult ReportIssuesToPullRequest(
            this ICakeContext context,
            IIssueProvider issueProvider,
            IPullRequestSystem pullRequestSystem,
            ReportIssuesToPullRequestSettings settings)
        {
            context.NotNull(nameof(context));
            issueProvider.NotNull(nameof(issueProvider));
            pullRequestSystem.NotNull(nameof(pullRequestSystem));
            settings.NotNull(nameof(settings));

            return
                (context.ReportIssuesToPullRequest(
                     new List <IIssueProvider> {
                issueProvider
            },
                     pullRequestSystem,
                     settings));
        }
示例#5
0
        /// <summary>
        /// Marks resolved comment threads created by this logic with active issues as active.
        /// </summary>
        /// <param name="discussionThreadsCapability">Pull request system capability for working with discussion threads.</param>
        /// <param name="existingThreads">Existing discussion threads on the pull request.</param>
        /// <param name="issueComments">Issues and their related existing comments on the pull request.</param>
        /// <param name="reportIssuesToPullRequestSettings">Settings for posting the issues.</param>
        private void ReopenExistingComments(
            ISupportDiscussionThreads discussionThreadsCapability,
            IList <IPullRequestDiscussionThread> existingThreads,
            IDictionary <IIssue, IssueCommentInfo> issueComments,
            ReportIssuesToPullRequestSettings reportIssuesToPullRequestSettings)
        {
            existingThreads.NotNull(nameof(existingThreads));
            issueComments.NotNull(nameof(issueComments));
            reportIssuesToPullRequestSettings.NotNull(nameof(reportIssuesToPullRequestSettings));

            if (!existingThreads.Any())
            {
                this.log.Verbose("No existings threads to reopen.");
                return;
            }

            var threadsToReopen =
                this.GetThreadsToReopen(existingThreads, issueComments, reportIssuesToPullRequestSettings).ToList();

            this.log.Verbose("Reopen {0} threads...", threadsToReopen.Count);
            discussionThreadsCapability.ReopenDiscussionThreads(threadsToReopen);
        }
        public static PullRequestIssueResult ReportIssuesToPullRequest(
            this ICakeContext context,
            IEnumerable <IIssue> issues,
            IPullRequestSystem pullRequestSystem,
            ReportIssuesToPullRequestSettings settings)
        {
            context.NotNull(nameof(context));
            pullRequestSystem.NotNull(nameof(pullRequestSystem));
            settings.NotNull(nameof(settings));

            // ReSharper disable once PossibleMultipleEnumeration
            issues.NotNullOrEmptyElement(nameof(issues));

            var orchestrator =
                new Orchestrator(
                    context.Log,
                    pullRequestSystem,
                    settings);

            // ReSharper disable once PossibleMultipleEnumeration
            return(orchestrator.Run(issues));
        }