private async Task <bool> ShouldMergePrAsync(IRemote darc, string url, MergePolicy policy) { IList <Check> checks = await darc.GetPullRequestChecksAsync(url); if (checks.Count == 0) { return(false); // Don't auto merge anything that has no checks. } if (checks.All(c => c.Status == CheckState.Success)) { return(true); // If every check succeeded merge the pr } return(false); }
public override async Task <MergePolicyEvaluationResult> EvaluateAsync(IPullRequest pr, IRemote darc) { IEnumerable <Check> checks = await darc.GetPullRequestChecksAsync(pr.Url); IEnumerable <Check> notIgnoredChecks = checks.Where(c => !_ignoreChecks.Contains(c.Name) && !c.IsMaestroMergePolicy); if (!notIgnoredChecks.Any()) { return(Pending("Waiting for checks.")); } ILookup <CheckState, Check> statuses = notIgnoredChecks.ToLookup( c => { // unify the check statuses to success, pending, and error switch (c.Status) { case CheckState.Success: case CheckState.Pending: return(c.Status); default: return(CheckState.Error); } }); int ListChecksCount(CheckState state) { return(statuses[state].Select(c => c.Name).Count()); } if (statuses.Contains(CheckState.Error)) { return(Fail($"Unsuccessful checks: {ListChecksCount(CheckState.Error)}")); } if (statuses.Contains(CheckState.Pending)) { return(Pending($"Waiting on checks: {ListChecksCount(CheckState.Pending)}")); } return(Succeed($"Successful checks: {ListChecksCount(CheckState.Success)}")); }