コード例 #1
0
        void ProcessCodeReviewChangedEvent(string message)
        {
            CodeReviewChangeEvent e =
                ParseEvent.Parse <CodeReviewChangeEvent>(message);

            if (!ShouldBeProcessed(
                    e.Repository,
                    e.BranchFullName,
                    mMultilinerBotConfig.Repository,
                    mMultilinerBotConfig.BranchPrefix))
            {
                return;
            }

            Review review = new Review(
                e.Repository, e.CodeReviewId, e.BranchId, e.CodeReviewStatus, e.CodeReviewTitle);

            if (review.IsDeleted())
            {
                ReviewsStorage.DeleteReview(review, mCodeReviewsTrackedFilePath);

                if (!mMultilinerBotConfig.Plastic.IsBranchAttrFilterEnabled)
                {
                    List <Review> remainingBranchReviews = ReviewsStorage.GetBranchReviews(
                        e.Repository, e.BranchId, mCodeReviewsTrackedFilePath);

                    if (remainingBranchReviews != null && remainingBranchReviews.Count > 0)
                    {
                        return;
                    }

                    lock (mSyncLock)
                    {
                        BranchesQueueStorage.RemoveBranch(
                            e.Repository, e.BranchId, mBranchesQueueFilePath);
                    }
                }
                return;
            }

            ReviewsStorage.WriteReview(review, mCodeReviewsTrackedFilePath);

            if (mMultilinerBotConfig.Plastic.IsBranchAttrFilterEnabled)
            {
                return;
            }

            lock (mSyncLock)
            {
                EnqueueBranch(
                    mBranchesQueueFilePath,
                    e.Repository,
                    e.BranchId,
                    e.BranchFullName,
                    e.BranchOwner,
                    e.BranchComment);

                Monitor.Pulse(mSyncLock);
            }
        }
コード例 #2
0
        internal void LoadBranchesToProcess()
        {
            mLog.Info("Retrieving branches to process...");

            if (mMultilinerBotConfig.Plastic.IsApprovedCodeReviewFilterEnabled)
            {
                List <BranchWithReview> branchesWithReviews =
                    FindQueries.FindPendingBranchesWithReviews(
                        mRestApi,
                        mMultilinerBotConfig.Repository,
                        mMultilinerBotConfig.BranchPrefix ?? string.Empty,
                        mMultilinerBotConfig.Plastic.StatusAttribute.Name,
                        mMultilinerBotConfig.Plastic.StatusAttribute.MergedValue);

                HashSet <string> branchIdsProcessed = new HashSet <string>();
                List <Branch>    branchesToEnqueue  = new List <Branch>();

                foreach (BranchWithReview branchWithReview in branchesWithReviews)
                {
                    ReviewsStorage.WriteReview(
                        branchWithReview.Review,
                        mCodeReviewsTrackedFilePath);

                    if (mMultilinerBotConfig.Plastic.IsBranchAttrFilterEnabled)
                    {
                        continue;
                    }

                    if (branchIdsProcessed.Contains(branchWithReview.Branch.Id))
                    {
                        continue;
                    }

                    branchIdsProcessed.Add(branchWithReview.Branch.Id);
                    branchesToEnqueue.Add(branchWithReview.Branch);
                }

                BranchesQueueStorage.WriteQueuedBranches(
                    branchesToEnqueue, mBranchesQueueFilePath);
            }

            if (!mMultilinerBotConfig.Plastic.IsBranchAttrFilterEnabled)
            {
                return;
            }

            List <Branch> branches = FindQueries.FindResolvedBranches(
                mRestApi,
                mMultilinerBotConfig.Repository,
                mMultilinerBotConfig.BranchPrefix ?? string.Empty,
                mMultilinerBotConfig.Plastic.StatusAttribute.Name,
                mMultilinerBotConfig.Plastic.StatusAttribute.ResolvedValue);

            BranchesQueueStorage.WriteQueuedBranches(branches, mBranchesQueueFilePath);
        }
コード例 #3
0
        static void SetBranchReviewsAsPending(
            IRestApi restApi,
            string repoName,
            string branchId,
            string codeReviewsStorageFile)
        {
            List <Review> branchReviews = ReviewsStorage.GetBranchReviews(
                repoName, branchId, codeReviewsStorageFile);

            foreach (Review review in branchReviews)
            {
                MultilinerMergebotApi.CodeReviews.Update(
                    restApi,
                    repoName,
                    review.ReviewId,
                    Review.PENDING_STATUS_ID,
                    review.ReviewTitle);
            }
        }
コード例 #4
0
        internal static Result SetTaskAsMerged(
            IRestApi restApi,
            Branch branch,
            string taskNumber,
            MultilinerBotConfiguration botConfig,
            string codeReviewsStorageFile)
        {
            Result result = new Result();

            result.IsSuccessful = true;

            try
            {
                if (botConfig.Plastic.IsApprovedCodeReviewFilterEnabled)
                {
                    ReviewsStorage.DeleteBranchReviews(
                        branch.Repository, branch.Id, codeReviewsStorageFile);
                }

                MultilinerMergebotApi.ChangeBranchAttribute(
                    restApi, branch.Repository, branch.FullName,
                    botConfig.Plastic.StatusAttribute.Name,
                    botConfig.Plastic.StatusAttribute.MergedValue);

                if (taskNumber != null && botConfig.Issues != null)
                {
                    MultilinerMergebotApi.Issues.SetIssueField(
                        restApi, botConfig.Issues.Plug, botConfig.Issues.ProjectKey,
                        taskNumber, botConfig.Issues.StatusField.Name,
                        botConfig.Issues.StatusField.MergedValue);
                }
            }
            catch (Exception ex)
            {
                result.IsSuccessful = false;
                result.ErrorMessage = BuildExceptionErrorMsg(
                    branch.FullName,
                    botConfig.Plastic.StatusAttribute.MergedValue,
                    ex.Message);
            }

            return(result);
        }
コード例 #5
0
        static bool AreAllCodeReviewsApprovedAtLeastOne(
            string branchRepository, string branchId, string codeReviewsStorageFile)
        {
            List <Review> branchReviews =
                ReviewsStorage.GetBranchReviews(branchRepository, branchId, codeReviewsStorageFile);

            if (branchReviews == null || branchReviews.Count == 0)
            {
                return(false);
            }

            foreach (Review branchReview in branchReviews)
            {
                if (!branchReview.IsApproved())
                {
                    return(false);
                }
            }

            return(true);
        }