示例#1
0
    def test_branch_disabled(self):
        old_rule = {
            "protection": {
                "required_status_checks": {
                    "strict": True,
                    "contexts": ["continuous-integration/no-ci"],
                },
                "required_pull_request_reviews": {
                    "dismiss_stale_reviews": True,
                    "require_code_owner_reviews": False,
                    "required_approving_review_count": 1,
                },
                "restrictions": None,
                "enforce_admins": False,
            }
        }
        branch_protection.protect(self.r_main, "disabled", old_rule)

        config = rules.get_mergify_config(self.r_main)
        rule = rules.get_branch_rule(config['rules'], "disabled")
        self.assertEqual(None, rule)
        data = branch_protection.get_protection(self.r_main, "disabled")
        self.assertFalse(
            branch_protection.is_configured(self.r_main, "disabled", rule,
                                            data))

        self.create_pr("disabled")
        self.assertEqual([], self.processor._get_cached_branches())
        self.assertEqual([], self._get_queue("disabled"))

        data = branch_protection.get_protection(self.r_main, "disabled")
        self.assertTrue(
            branch_protection.is_configured(self.r_main, "disabled", rule,
                                            data))
示例#2
0
    def test_merge_branch_protection_strict(self):
        rules = {'pull_request_rules': [
            {"name": "merge",
             "conditions": [
                 "base=master",
                 "status-success=continuous-integration/fake-ci",
             ], "actions": {
                 "merge": {}
             }},
        ]}

        self.setup_repo(yaml.dump(rules))

        # Check policy of that branch is the expected one
        rule = {
            "protection": {
                "required_status_checks": {
                    "strict": True,
                    "contexts": ["continuous-integration/fake-ci"],
                },
                "required_pull_request_reviews": None,
                "restrictions": None,
                "enforce_admins": False,
            }
        }

        p1, _ = self.create_pr(check="success")
        p2, _ = self.create_pr(check="success")

        p1.merge()

        branch_protection.protect(self.r_main, "master", rule)

        self.push_events([
            ("pull_request", {"action": "closed"}),
            ("check_suite", {"action": "requested"}),
        ], ordered=False)

        self.create_status_and_push_event(p2)

        self.push_events([
            # Summary
            ("check_run", {"check_run": {"conclusion": "success"}}),
            # FIXME(sileht): Why twice ??
            # Merge
            ("check_run", {"check_run": {"conclusion": "failure"}}),
            # Merge
            ("check_run", {"check_run": {"conclusion": "failure"}}),
            ("check_suite", {"action": "completed"}),
        ], ordered=False)

        checks = list(check_api.get_checks(p2, {
            "check_name": "Mergify — Rule: merge (merge)"}))
        self.assertEqual("failure", checks[0].conclusion)
        self.assertIn("Branch protection setting 'strict' conflicts with "
                      "Mergify configuration",
                      checks[0].output['title'])
示例#3
0
    def test_merge_branch_protection_ci(self):
        rules = {
            'pull_request_rules': [
                {
                    "name": "merge",
                    "conditions": [
                        "base=master",
                    ],
                    "actions": {
                        "merge": {}
                    }
                },
            ]
        }

        self.setup_repo(yaml.dump(rules))

        # Check policy of that branch is the expected one
        rule = {
            "protection": {
                "required_status_checks": {
                    "strict": False,
                    "contexts": ["continuous-integration/fake-ci"],
                },
                "required_pull_request_reviews": None,
                "restrictions": None,
                "enforce_admins": False,
            }
        }

        branch_protection.protect(self.r_main, "master", rule)

        p, _ = self.create_pr(check="success")

        self.push_events([
            ("check_run", {
                "check_run": {
                    "conclusion": "failure"
                }
            }),
        ])

        checks = list(
            check_api.get_checks(
                p, {"check_name": "Mergify — Rule: merge (merge)"}))
        self.assertEqual("failure", checks[0].conclusion)
        self.assertIn(
            "Branch protection settings are blocking "
            "automatic merging", checks[0].output['title'])