Пример #1
0
def config_converter():
    try:
        data = yaml.safe_load(flask.request.files['data'].stream)
    except Exception as e:
        flask.abort(400, str(e))

    if "rules" not in data:
        flask.abort(400, "file does not contains v1 configuration")

    new_config = yaml.dump(
        {"pull_request_rules": convert.convert_config(data.get("rules", {}))},
        default_flow_style=False),
    return flask.Response(new_config, mimetype="text/plain")
Пример #2
0
def test_convert_with_some_none():
    old_rules = {
        'rules': {
            'default': None,
            'branches': {
                '^stable/.*': {
                    'protection': None,
                    'merge_strategy': {
                        'method': 'rebase',
                        'rebase_fallback': "merge",
                    },
                },
                '^unstable/.*': {
                    'required_pull_request_reviews': None,
                    'required_status_checks': None,
                },
            },
        },
    }
    converted = convert.convert_config(old_rules["rules"])
    assert converted == [{
        "name":
        "^stable/.* branch",
        "conditions": ["base~=^stable/.*", "label!=no-mergify"],
        "actions": {
            "merge": {
                "method": "rebase",
                "rebase_fallback": "merge",
            },
        },
    }, {
        "name":
        "^unstable/.* branch",
        "conditions":
        ["base~=^unstable/.*", "label!=no-mergify", '#approved-reviews-by>=1'],
        "actions": {
            "merge": {
                "method": "merge",
                "rebase_fallback": "merge",
            },
        }
    }]
    # Validate generated conf with the schema
    rules.PullRequestRules(converted)
Пример #3
0
def test_null_branch():
    old_rules = {
        'rules': {
            'default': {
                'protection': {
                    'required_pull_request_reviews': {
                        'required_approving_review_count': 1
                    },
                    'required_status_checks': {
                        'contexts': ['continuous-integration/travis-ci'],
                    }
                },
                'merge_strategy': {
                    'method': 'rebase',
                }
            },
            'branches': {
                'gh-pages': None,
            },
        },
    }
    converted = convert.convert_config(old_rules["rules"])
    assert converted == [
        {
            "name":
            "default",
            "conditions": [
                "-base=gh-pages", "label!=no-mergify",
                "#approved-reviews-by>=1",
                "status-success=continuous-integration/travis-ci"
            ],
            "actions": {
                "merge": {
                    "method": "rebase",
                    "rebase_fallback": "merge",
                },
            },
        },
    ]
    # Validate generated conf with the schema
    rules.PullRequestRules(converted)
Пример #4
0
def test_convert_simple():
    old_rules = {
        'rules': {
            'default': {
                'automated_backport_labels': {
                    'backport-to-3.1': 'stable/3.1',
                    'backport-to-3.0': 'stable/3.0',
                },
                'protection': {
                    'required_pull_request_reviews': {
                        'required_approving_review_count': 2
                    },
                    'required_status_checks': {
                        'contexts': ['continuous-integration/travis-ci'],
                        'strict': True
                    }
                },
                'merge_strategy': {
                    'method': 'rebase'
                }
            },
            'branches': {
                '^stable/.*': {
                    'protection': {
                        'required_pull_request_reviews': {
                            'required_approving_review_count': 1
                        }
                    }
                }
            }
        }
    }
    converted = convert.convert_config(old_rules["rules"])
    assert converted == [
        {
            "name":
            "default",
            "conditions": [
                "-base~=^stable/.*", "label!=no-mergify",
                "#approved-reviews-by>=2",
                "status-success=continuous-integration/travis-ci"
            ],
            "actions": {
                "merge": {
                    "method": "rebase",
                    "rebase_fallback": "merge",
                    "strict": True,
                },
            },
        },
        {
            "name":
            "backport stable/3.0",
            "conditions": [
                "-base~=^stable/.*", "label!=no-mergify",
                "label=backport-to-3.0"
            ],
            "actions": {
                "backport": {
                    "branches": ["stable/3.0"],
                },
            },
        },
        {
            "name":
            "backport stable/3.1",
            "conditions": [
                "-base~=^stable/.*", "label!=no-mergify",
                "label=backport-to-3.1"
            ],
            "actions": {
                "backport": {
                    "branches": ["stable/3.1"],
                },
            },
        },
        {
            "name":
            "^stable/.* branch",
            "conditions": [
                "base~=^stable/.*", "label!=no-mergify",
                "#approved-reviews-by>=1",
                "status-success=continuous-integration/travis-ci"
            ],
            "actions": {
                "merge": {
                    "method": "rebase",
                    "rebase_fallback": "merge",
                    "strict": True,
                },
            },
        },
        {
            "name":
            "backport stable/3.0 from ^stable/.*",
            "conditions":
            ["base~=^stable/.*", "label!=no-mergify", "label=backport-to-3.0"],
            "actions": {
                "backport": {
                    "branches": ["stable/3.0"],
                },
            }
        },
        {
            "name":
            "backport stable/3.1 from ^stable/.*",
            "conditions":
            ["base~=^stable/.*", "label!=no-mergify", "label=backport-to-3.1"],
            "actions": {
                "backport": {
                    "branches": ["stable/3.1"],
                },
            },
        },
    ]
    # Validate generated conf with the schema
    rules.PullRequestRules(converted)
Пример #5
0
def test_convert_rebase_fallback():
    old_rules = {
        'rules': {
            'default': {
                'protection': {
                    'required_pull_request_reviews': {
                        'required_approving_review_count': 2
                    },
                    'required_status_checks': {
                        'contexts': ['continuous-integration/travis-ci'],
                        'strict': True
                    }
                },
                'merge_strategy': {
                    'method': 'rebase',
                    'rebase_fallback': "none",
                }
            },
            'branches': {
                '^stable/.*': {
                    'merge_strategy': {
                        'method': 'rebase',
                        'rebase_fallback': "merge",
                    },
                },
                '^unstable/.*': {
                    'merge_strategy': {
                        'method': 'rebase',
                        'rebase_fallback': "none",
                    },
                },
            },
        },
    }
    converted = convert.convert_config(old_rules["rules"])
    assert converted == [
        {
            "name":
            "default",
            "conditions": [
                "-base~=^stable/.*", "-base~=^unstable/.*",
                "label!=no-mergify", "#approved-reviews-by>=2",
                "status-success=continuous-integration/travis-ci"
            ],
            "actions": {
                "merge": {
                    "method": "rebase",
                    "rebase_fallback": None,
                    "strict": True,
                },
            },
        },
        {
            "name":
            "^stable/.* branch",
            "conditions": [
                "base~=^stable/.*", "label!=no-mergify",
                "#approved-reviews-by>=2",
                "status-success=continuous-integration/travis-ci"
            ],
            "actions": {
                "merge": {
                    "method": "rebase",
                    "rebase_fallback": "merge",
                    "strict": True,
                },
            },
        },
        {
            "name":
            "^unstable/.* branch",
            "conditions": [
                "base~=^unstable/.*", "label!=no-mergify",
                "#approved-reviews-by>=2",
                "status-success=continuous-integration/travis-ci"
            ],
            "actions": {
                "merge": {
                    "method": "rebase",
                    "rebase_fallback": None,
                    "strict": True,
                },
            },
        },
    ]
    # Validate generated conf with the schema
    rules.PullRequestRules(converted)