Example #1
0
 public async Task <MergePolicyEvaluationResult> EvaluateAsync(MergePolicyEvaluationContext context)
 {
     using (context.Logger.BeginScope("Evaluating Merge Policy {policyName}", Name))
     {
         return(await DoEvaluateAsync(context));
     }
 }
Example #2
0
        protected override async Task <MergePolicyEvaluationResult> DoEvaluateAsync(MergePolicyEvaluationContext context)
        {
            var requiredChecks = new HashSet <string>(context.Get <List <string> >("checks"));

            Dictionary <string, Check> checks =
                (await context.Darc.GetPullRequestChecksAsync(context.PullRequestUrl)).ToDictionary(c => c.Name);

            var missingChecks = new List <string>();
            var failedChecks  = new List <Check>();

            foreach (string requiredCheck in requiredChecks)
            {
                if (checks.TryGetValue(requiredCheck, out Check check))
                {
                    if (check.Status != CheckState.Success)
                    {
                        failedChecks.Add(check);
                    }
                }
                else
                {
                    missingChecks.Add(requiredCheck);
                }
            }

            if (missingChecks.Count < 1 && failedChecks.Count < 1)
            {
                return(context.Success());
            }

            var parts = new List <string>();

            if (failedChecks.Any())
            {
                parts.Add($"Unsuccessful checks: {string.Join(", ", failedChecks.Select(c => c.Name))}");
            }

            if (missingChecks.Any())
            {
                parts.Add($"Missing checks: {string.Join(", ", missingChecks)}");
            }

            return(context.Fail(string.Join("; ", parts)));
        }
Example #3
0
        protected override async Task <MergePolicyEvaluationResult> DoEvaluateAsync(MergePolicyEvaluationContext context)
        {
            var ignoreChecks = new HashSet <string>(context.Get <string[]>("ignoreChecks") ?? Array.Empty <string>());

            IList <Check> checks = await context.Darc.GetPullRequestChecksAsync(context.PullRequestUrl);

            List <Check> notIgnoredChecks = checks.Where(c => !ignoreChecks.Contains(c.Name)).ToList();

            if (notIgnoredChecks.Count < 1)
            {
                return(context.Fail("No unignored checks."));
            }

            List <Check> failedChecks = notIgnoredChecks.Where(c => c.Status != CheckState.Success).ToList();

            if (failedChecks.Count < 1)
            {
                return(context.Success());
            }

            return(context.Fail($"Unsuccessful checks: {string.Join(", ", failedChecks.Select(c => c.Name))}"));
        }
Example #4
0
 protected override Task <MergePolicyEvaluationResult> DoEvaluateAsync(MergePolicyEvaluationContext context)
 {
     return(Task.FromResult(context.Fail("Merge Policy Not Yet Implemented.")));
 }
Example #5
0
 protected abstract Task <MergePolicyEvaluationResult> DoEvaluateAsync(MergePolicyEvaluationContext context);