async def gen_summary( ctxt: context.Context, pull_request_rules: rules.PullRequestRules, match: rules.RulesEvaluator, ) -> typing.Tuple[str, str]: summary = "" summary += get_already_merged_summary(ctxt, match) summary += await gen_summary_rules(ctxt, match.faulty_rules, show_actions_rules=True) summary += await gen_summary_rules(ctxt, match.matching_rules, show_actions_rules=True) ignored_rules = len( list(filter(lambda x: not x.hidden, match.ignored_rules))) if not ctxt.subscription.active: summary += constants.MERGIFY_OPENSOURCE_SPONSOR_DOC summary += "<hr />\n" if ignored_rules > 0: summary += "<details>\n" if ignored_rules == 1: summary += f"<summary>{ignored_rules} not applicable rule</summary>\n\n" else: summary += f"<summary>{ignored_rules} not applicable rules</summary>\n\n" summary += await gen_summary_rules(ctxt, match.ignored_rules) summary += "</details>\n" completed_rules = len( list(filter(lambda x: not x.missing_conditions, match.matching_rules))) potential_rules = len(match.matching_rules) - completed_rules faulty_rules = len(match.faulty_rules) if pull_request_rules.has_user_rules(): summary_title = [] if faulty_rules == 1: summary_title.append(f"{potential_rules} faulty rule") elif faulty_rules > 1: summary_title.append(f"{potential_rules} faulty rules") if completed_rules == 1: summary_title.append(f"{completed_rules} rule matches") elif completed_rules > 1: summary_title.append(f"{completed_rules} rules match") if potential_rules == 1: summary_title.append(f"{potential_rules} potential rule") elif potential_rules > 1: summary_title.append(f"{potential_rules} potential rules") if completed_rules == 0 and potential_rules == 0 and faulty_rules == 0: summary_title.append("no rules match, no planned actions") else: summary_title = ["no rules setuped, just listening for commands"] return " and ".join(summary_title), summary
def handle(pull_request_rules: rules.PullRequestRules, ctxt: context.Context) -> None: match = pull_request_rules.get_pull_request_rule(ctxt) checks = dict((c["name"], c) for c in ctxt.pull_engine_check_runs) summary_check = checks.get(ctxt.SUMMARY_NAME) previous_conclusions = load_conclusions(ctxt, summary_check) conclusions = run_actions(ctxt, match, checks, previous_conclusions) post_summary(ctxt, match, summary_check, conclusions, previous_conclusions)
async def gen_summary( ctxt: context.Context, pull_request_rules: rules.PullRequestRules, match: rules.RulesEvaluator, ) -> typing.Tuple[str, str]: summary = "" summary += await get_already_merged_summary(ctxt, match) if ctxt.configuration_changed: summary += "⚠️ The configuration has been changed, *queue* and *merge* actions are ignored. ⚠️\n\n" summary += await gen_summary_rules(ctxt, match.faulty_rules) summary += await gen_summary_rules(ctxt, match.matching_rules) ignored_rules = len(list(filter(lambda x: not x.hidden, match.ignored_rules))) if ctxt.subscription.has_feature(subscription.Features.SHOW_SPONSOR): summary += constants.MERGIFY_OPENSOURCE_SPONSOR_DOC summary += "<hr />\n" if ignored_rules > 0: summary += "<details>\n" if ignored_rules == 1: summary += f"<summary>{ignored_rules} not applicable rule</summary>\n\n" else: summary += f"<summary>{ignored_rules} not applicable rules</summary>\n\n" summary += await gen_summary_rules(ctxt, match.ignored_rules) summary += "</details>\n" completed_rules = len( list(filter(lambda rule: rule.conditions.match, match.matching_rules)) ) potential_rules = len(match.matching_rules) - completed_rules faulty_rules = len(match.faulty_rules) if pull_request_rules.has_user_rules(): summary_title = [] if faulty_rules == 1: summary_title.append(f"{potential_rules} faulty rule") elif faulty_rules > 1: summary_title.append(f"{potential_rules} faulty rules") if completed_rules == 1: summary_title.append(f"{completed_rules} rule matches") elif completed_rules > 1: summary_title.append(f"{completed_rules} rules match") if potential_rules == 1: summary_title.append(f"{potential_rules} potential rule") elif potential_rules > 1: summary_title.append(f"{potential_rules} potential rules") if completed_rules == 0 and potential_rules == 0 and faulty_rules == 0: summary_title.append("no rules match, no planned actions") else: summary_title = ["no rules configured, just listening for commands"] title = " and ".join(summary_title) if ctxt.configuration_changed: title = f"Configuration changed. This pull request must be merged manually — {title}" return title, summary