Exemple #1
0
        //
        // Gets the results of a review request
        //
        private static ReviewStatistics GetPropertiesOfReview(CommitReview review, string workingDirectory, Simple credentials, Logging logger)
        {
            // Get the API
            string reviewId   = ExtractReviewId(review.Review);
            string apiRequest = string.Format(@"/review-requests/{0}", reviewId);

            // Try this review code
            JObject result = MakeApiCall(credentials, workingDirectory, apiRequest, logger);

            if (result == null)
            {
                logger.Log("API called failed, returning no statistics");
                return(new ReviewStatistics(review, State.NotFound));
            }

            // If it's an empty review it's pending because we couldn't access
            if (result == EmptyReview)
            {
                logger.Log("API called failed with Empty Review, assuming a pending review");
                return(new ReviewStatistics(review, State.Pending));
            }

            // We have the review information so process
            Tuple <int, int, int> reviewsAndShipitsAndReplies = GetReviewsAndShipItsAndReplies(workingDirectory, reviewId, credentials, logger);

            // Get the state of this review
            State reviewState = GetReviewState(result, logger);

            // Return our properties
            return(new ReviewStatistics(review, reviewState, reviewsAndShipitsAndReplies.Item1, reviewsAndShipitsAndReplies.Item3, reviewsAndShipitsAndReplies.Item2));
        }
Exemple #2
0
            // Constructor
            public ReviewStatistics(CommitReview commit, State state, int reviews, int replies, int shipIts)
            {
                Commit = commit;

                State = state;

                Reviews = reviews;
                Replies = replies;

                ShipIts = shipIts;
            }
Exemple #3
0
        //
        // Counts the type of reviews in a set of commits
        //
        public static GetCommitStatsResult GetCommitStatistics(SvnLogs.Log[] svnLogs, Logging logger, StatisticGenerated statGenerated)
        {
            // We need to track the types of reviews
            Object writeLock      = new Object();
            int    logCount       = 0;
            int    unknownReviews = 0;

            int[] commitCounts = new int[Enum.GetNames(typeof(RB_Tools.Shared.Review.Properties.Level)).Length];

            // Keep track of the reviews we find
            var reviews = new List <CommitReview>();

            // Spin through them all and parse the log message
            logger.Log("Starting to pull out the commit statistics from the SVN logs");
            ParallelLoopResult result = Parallel.ForEach(svnLogs, new ParallelOptions {
                MaxDegreeOfParallelism = 16
            }, (thisLog, loopState) =>
            {
                // Get the line with the review state in it
                string reviewStateLine = thisLog.Message.FirstOrDefault(line =>
                {
                    Match regExMatch = Regex.Match(line, @".*\[Review State.*:.*\]");
                    return(regExMatch.Success);
                });

                // Identify what we have
                logger.Log(@"* Found the review state line '{0}' in revision {1}", reviewStateLine, thisLog.Revision);

                // Do we have anything
                bool unknownReview = false;
                if (string.IsNullOrEmpty(reviewStateLine) == true)
                {
                    unknownReview = true;
                }

                // Get the type of review if we need to
                int commitType           = -1;
                CommitReview commitToAdd = null;
                if (unknownReview == false)
                {
                    try
                    {
                        // Get the type of review string
                        string[] reviewTypeSplit = reviewStateLine.Split(':');
                        string reviewType        = reviewTypeSplit[1].Replace("]", "").Trim();

                        // Find the review type this is
                        for (int i = 0; i < commitCounts.Length; ++i)
                        {
                            string thisEnumName = ((RB_Tools.Shared.Review.Properties.Level)i).GetSplitName();
                            if (thisEnumName.Equals(reviewType, StringComparison.InvariantCultureIgnoreCase) == true)
                            {
                                // Let us know what type of review we found
                                logger.Log(@"* Found review type '{0}'", ((RB_Tools.Shared.Review.Properties.Level)i).ToString());

                                // If this is a review, pull out the review
                                if (i == (int)RB_Tools.Shared.Review.Properties.Level.FullReview)
                                {
                                    string reviewUrl = GetReviewUrl(thisLog.Message);
                                    if (string.IsNullOrEmpty(reviewUrl) == false)
                                    {
                                        commitToAdd = new CommitReview(thisLog, reviewUrl);
                                    }
                                }

                                // Track the number of reviews
                                commitType = i;
                                break;
                            }
                        }
                    }
                    catch
                    {
                        // Something has gone wrong
                        loopState.Stop();
                    }
                }

                // Only bother if we need to
                if (loopState.IsStopped == false)
                {
                    // Update our information
                    lock (writeLock)
                    {
                        // Update
                        logger.Log("Updating the review type counts");

                        // Update the view type
                        if (unknownReview == true)
                        {
                            ++unknownReviews;
                        }
                        else if (commitType >= 0)
                        {
                            ++commitCounts[commitType];
                        }

                        // Store if needed
                        if (commitToAdd != null)
                        {
                            reviews.Add(commitToAdd);
                        }

                        // Another one done
                        statGenerated(++logCount);
                    }
                }
            });

            // Did we fail
            if (result.IsCompleted == false)
            {
                logger.Log("The commit statistics completed unsuccessfully");
                return(null);
            }

            // Update what we found
            logger.Log("The following review types were found");
            logger.Log("* Commit count: {0}", commitCounts);
            logger.Log("* Unknown reviews: {0}", unknownReviews);
            for (int i = 0; i < reviews.Count; ++i)
            {
                logger.Log("* {0}: {1}", ((RB_Tools.Shared.Review.Properties.Level)i).ToString(), reviews[i]);
            }

            // Return our reviews
            return(new GetCommitStatsResult(commitCounts, unknownReviews, reviews.ToArray()));
        }
Exemple #4
0
 // Constructor
 public ReviewStatistics(CommitReview commit, State state) : this(commit, state, 0, 0, 0)
 {
 }