Ejemplo n.º 1
0
        public List <BranchPolicyFailure> EvaluatePendingCheckin(BranchPattern branchPattern, Microsoft.TeamFoundation.VersionControl.Client.IPendingCheckin pendingCheckin)
        {
            List <BranchPolicyFailure> branchPolicyFailures = new List <BranchPolicyFailure>();

            // Evaluate LockPolicy
            if (WorkItemRequired)
            {
                bool foundWorkItems = false;
                foreach (WorkItemCheckinInfo item in pendingCheckin.WorkItems.CheckedWorkItems)
                {
                    foundWorkItems = true;
                }
                if (!foundWorkItems)
                {
                    branchPolicyFailures.Add(new BranchPolicyFailure(String.Format(
                                                                         "{0} Check-in policy [{1}] ({2}):\n" +
                                                                         "You must associate at least one work item with the check-in.",
                                                                         Name, branchPattern.Name, branchPattern.Pattern)));
                }
            }
            return(branchPolicyFailures);
        }
        public List <BranchPolicyFailure> EvaluatePendingCheckin(BranchPattern branchPattern, Microsoft.TeamFoundation.VersionControl.Client.IPendingCheckin pendingCheckin)
        {
            List <BranchPolicyFailure> branchPolicyFailures = new List <BranchPolicyFailure>();

            if (CodeReviewRequired)
            {
                bool foundCodeReviewWorkItem = false;
                bool allCodeReviewsApproved  = false;

                foreach (WorkItemCheckinInfo wiInfo in pendingCheckin.WorkItems.CheckedWorkItems)
                {
                    if (wiInfo.WorkItem.Type.Name == "Code Review Request")
                    {
                        foundCodeReviewWorkItem = true;
                        if (wiInfo.WorkItem.State == "Closed" || wiInfo.WorkItem.State == "Resolved")
                        {
                            allCodeReviewsApproved = true;
                            foreach (WorkItemLink item in wiInfo.WorkItem.WorkItemLinks)
                            {
                                WorkItem child = wiInfo.WorkItem.Type.Store.GetWorkItem(item.TargetId);
                                if (child.Type.Name == "Code Review Response")
                                {
                                    string closedStatus = child.Fields["Closed Status"].Value.ToString();
                                    if (closedStatus != "Looks Good" && closedStatus != "Removed")
                                    {
                                        allCodeReviewsApproved = false;
                                    }
                                }
                            }
                        }
                    }
                }

                if (!allCodeReviewsApproved)
                {
                    if (foundCodeReviewWorkItem)
                    {
                        branchPolicyFailures.Add(new BranchPolicyFailure(string.Format(
                                                                             "{0} Check-in policy [{1}] ({2}):\n" +
                                                                             "All Code Reviews associated with the check-in must be Approved ('Looks Good').",
                                                                             Name, branchPattern.Name, branchPattern.Pattern)));
                    }
                    else
                    {
                        branchPolicyFailures.Add(new BranchPolicyFailure(string.Format(
                                                                             "{0} Check-in policy [{1}] ({2}):\n" +
                                                                             "Check-in must be associated with at least one Code Review.\n" +
                                                                             "All Code Reviews associated with the check-in must be Approved ('Looks Good').",
                                                                             Name, branchPattern.Name, branchPattern.Pattern)));
                    }
                }
            }
            return(branchPolicyFailures);
        }