def test_jinja_with_list_attribute(): pull_request_rules = rules.UserConfigurationSchema( rules.YamlSchema(""" pull_request_rules: - name: ahah conditions: - base=master actions: comment: message: | This pull request has been approved by: {% for name in label %} @{{name}} {% endfor %} {% for name in files %} @{{name}} {% endfor %} {% for name in assignee %} @{{name}} {% endfor %} {% for name in approved_reviews_by %} @{{name}} {% endfor %} Thank you @{{author}} for your contributions! """))["pull_request_rules"] assert [rule.name for rule in pull_request_rules] == [ "ahah", ]
def test_jinja_with_wrong_syntax(): with pytest.raises(voluptuous.Invalid) as i: rules.UserConfigurationSchema( rules.YamlSchema( """pull_request_rules: - name: ahah conditions: - base=master actions: comment: message: | This pull request has been approved by: {% for name in approved_reviews_by %} Thank you @{{author}} for your contributions! """ ) ) assert str(i.value) == ( "Template syntax error @ data['pull_request_rules']" "[0]['actions']['comment']['message'][line 3]" ) with pytest.raises(voluptuous.Invalid) as i: rules.UserConfigurationSchema( rules.YamlSchema( """pull_request_rules: - name: ahah conditions: - base=master actions: comment: message: | This pull request has been approved by: {% for name in approved_reviews_by %} @{{ name }} {% endfor %} Thank you @{{foo}} for your contributions! """ ) ) assert str(i.value) == ( "Template syntax error for dictionary value @ data['pull_request_rules']" "[0]['actions']['comment']['message']" )
def test_user_binary_file(): with pytest.raises(voluptuous.Invalid) as i: rules.UserConfigurationSchema(rules.YamlSchema(chr(4))) assert str(i.value) == "Invalid YAML at []" ir = rules.InvalidRules(i.value, ".mergify.yml") assert (str(ir) == """Invalid YAML ``` unacceptable character #x0004: special characters are not allowed in "<unicode string>", position 0 ```""") assert ir.get_annotations(".mergify.yml") == []
def test_check_runs_default(): pull_request_rules = rules.UserConfigurationSchema( rules.YamlSchema(""" pull_request_rules: - name: ahah conditions: - base=master actions: post_check: {} """))["pull_request_rules"] assert [rule.name for rule in pull_request_rules] == [ "ahah", ]
def test_check_runs_custom(): pull_request_rules = rules.UserConfigurationSchema( rules.YamlSchema(""" pull_request_rules: - name: ahah conditions: - base=master actions: post_check: title: '{{ check_rule_name }} whatever' summary: | This pull request has been checked! Thank you @{{author}} for your contributions! {{ check_conditions }} """))["pull_request_rules"] assert [rule.name for rule in pull_request_rules] == [ "ahah", ]
LOG = daiquiri.getLogger(__name__) MERGIFY_BUILTIN_CONFIG_YAML = f""" pull_request_rules: - name: delete backport/copy branch (Mergify rule) hidden: true conditions: - author={config.BOT_USER_LOGIN} - head~=^mergify/(bp|copy)/ - closed actions: delete_head_branch: """ MERGIFY_BUILTIN_CONFIG = rules.UserConfigurationSchema( rules.YamlSchema(MERGIFY_BUILTIN_CONFIG_YAML)) DEFAULT_CONFIG_FILE = context.MergifyConfigFile( decoded_content=b"", type="file", content="<default>", sha=github_types.SHAType("<default>"), path="<default>", ) async def _check_configuration_changes( ctxt: context.Context, current_mergify_config_file: typing.Optional[context.MergifyConfigFile], ) -> bool: if ctxt.pull["base"]["repo"]["default_branch"] != ctxt.pull["base"]["ref"]:
def test_user_configuration_schema(): with pytest.raises(voluptuous.Invalid) as exc_info: rules.UserConfigurationSchema(rules.YamlSchema("- no\n* way")) assert str(exc_info.value) == "Invalid YAML at [line 2, column 2]" with pytest.raises(voluptuous.Invalid) as i: rules.UserConfigurationSchema( rules.YamlSchema(""" pull_request_rules: - name: ahah key: not really what we expected """)) assert (str(i.value) == "extra keys not allowed @ data['pull_request_rules'][0]['key']") ir = rules.InvalidRules(i.value, ".mergify.yml") assert str(ir) == ( "* extra keys not allowed @ pull_request_rules → item 0 → key\n" "* required key not provided @ pull_request_rules → item 0 → actions\n" "* required key not provided @ pull_request_rules → item 0 → conditions" ) assert [] == ir.get_annotations(".mergify.yml") with pytest.raises(voluptuous.Invalid) as i: rules.UserConfigurationSchema( rules.YamlSchema("""invalid: - *yaml """)) assert str(i.value) == "Invalid YAML at [line 2, column 3]" ir = rules.InvalidRules(i.value, ".mergify.yml") assert (str(ir) == """Invalid YAML @ line 2, column 3 ``` found undefined alias 'yaml' in "<unicode string>", line 2, column 3: - *yaml ^ ```""") assert [{ "annotation_level": "failure", "end_column": 3, "end_line": 2, "message": "found undefined alias 'yaml'\n" ' in "<unicode string>", line 2, column 3:\n' " - *yaml\n" " ^", "path": ".mergify.yml", "start_column": 3, "start_line": 2, "title": "Invalid YAML", }] == ir.get_annotations(".mergify.yml") with pytest.raises(voluptuous.Invalid) as i: rules.UserConfigurationSchema( rules.YamlSchema(""" pull_request_rules: """)) assert (str( i.value ) == "expected a list for dictionary value @ data['pull_request_rules']") ir = rules.InvalidRules(i.value, ".mergify.yml") assert str( ir) == "expected a list for dictionary value @ pull_request_rules" with pytest.raises(voluptuous.Invalid) as i: rules.UserConfigurationSchema(rules.YamlSchema("")) assert str(i.value) == "expected a dictionary" ir = rules.InvalidRules(i.value, ".mergify.yml") assert str(ir) == "expected a dictionary" with pytest.raises(voluptuous.Invalid) as i: rules.UserConfigurationSchema( rules.YamlSchema(""" pull_request_rules: - name: add label conditions: - conflict actions: label: add: - conflict: """)) assert ( str(i.value) == "expected str @ data['pull_request_rules'][0]['actions']['label']['add'][0]" ) ir = rules.InvalidRules(i.value, ".mergify.yml") assert ( str(ir) == "expected str @ pull_request_rules → item 0 → actions → label → add → item 0" )
batch_size: 8 batch_max_wait_time: 0 s allow_checks_interruption: False - name: regular-1x8-noint-from-fastlane-and-regular conditions: [] speculative_checks: 1 batch_size: 4 batch_max_wait_time: 0 s disallow_checks_interruption_from_queues: - regular-1x8-noint-from-fastlane-and-regular - fastlane-1x8-noint """ QUEUE_RULES = voluptuous.Schema(rules.QueueRulesSchema)( rules.YamlSchema(MERGIFY_CONFIG)["queue_rules"] ) @pytest.fixture def fake_client() -> mock.Mock: branch = {"commit": {"sha": "sha1"}} def item_call(url, *args, **kwargs): if url == "/repos/Mergifyio/mergify-engine/contents/.mergify.yml": return { "type": "file", "sha": "whatever", "content": base64.b64encode(MERGIFY_CONFIG.encode()).decode(), "path": ".mergify.yml", }