void ProcessCodeReviewChangedEvent(string message) { CodeReviewChangeEvent e = ParseEvent.Parse <CodeReviewChangeEvent>(message); if (!ShouldBeProcessed( e.Repository, e.BranchFullName, mTrunkBotConfig.Repository, mTrunkBotConfig.BranchPrefix)) { return; } Review review = new Review( e.Repository, e.CodeReviewId, e.BranchId, e.CodeReviewStatus, e.CodeReviewTitle); if (review.IsDeleted()) { ReviewsStorage.DeleteReview(review, mCodeReviewsTrackedFilePath); if (!mTrunkBotConfig.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 (mTrunkBotConfig.Plastic.IsBranchAttrFilterEnabled) { return; } lock (mSyncLock) { EnqueueBranch( mBranchesQueueFilePath, e.Repository, e.BranchId, e.BranchFullName, e.BranchOwner, e.BranchComment); Monitor.Pulse(mSyncLock); } }
static void SetBranchReviewsAsPending( RestApi restApi, string repoName, string branchId, string codeReviewsStorageFile) { List <Review> branchReviews = ReviewsStorage.GetBranchReviews( repoName, branchId, codeReviewsStorageFile); foreach (Review review in branchReviews) { TrunkMergebotApi.CodeReviews.Update( restApi, repoName, review.ReviewId, Review.PENDING_STATUS_ID, review.ReviewTitle); } }
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); }