Exemple #1
0
def test_get_merge_body_includes_pull_request_url_with_coauthor() -> None:
    """
    Coauthor should appear after the pull request url
    """
    pull_request = create_pull_request()
    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(message=MergeMessage(
                body=MergeBodyStyle.pull_request_body,
                include_pull_request_url=True,
                include_pull_request_author=True,
            )),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(
        merge_method="squash",
        commit_message="""\
# some description

PR-URL: https://github.com/example_org/example_repo/pull/65
Co-authored-by: Barry Berkman <*****@*****.**>""",
    )
    assert actual == expected
Exemple #2
0
def test_get_merge_body_includes_pull_request_url() -> None:
    """
    Ensure that when the appropriate config option is set, we include the
    pull request url in the commit message.
    """
    pull_request = create_pull_request()
    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(
                message=MergeMessage(body=MergeBodyStyle.pull_request_body,
                                     include_pull_request_url=True)),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(
        merge_method="squash",
        commit_message="""\
# some description

PR-URL: https://github.com/example_org/example_repo/pull/65""",
    )
    assert actual == expected
Exemple #3
0
def test_config_parsing_opposite() -> None:
    """
    parse config with all opposite settings so we can ensure the config is
    correctly formatted.
    """
    file_path = load_config_fixture("v1-opposite.toml")
    loaded = toml.load(file_path)
    actual = V1.parse_obj(cast(Dict[Any, Any], loaded))

    expected = V1(
        version=1,
        app_id="12345",
        merge=Merge(
            automerge_label="mergeit!",
            require_automerge_label=False,
            blacklist_title_regex="",
            blacklist_labels=["wip", "block-merge"],
            method=MergeMethod.squash,
            delete_branch_on_merge=True,
            block_on_reviews_requested=True,
            notify_on_conflict=False,
            optimistic_updates=False,
            message=MergeMessage(
                title=MergeTitleStyle.pull_request_title,
                body=MergeBodyStyle.pull_request_body,
                include_pr_number=False,
                body_type=BodyText.plain_text,
                strip_html_comments=True,
            ),
        ),
    )

    assert actual == expected
Exemple #4
0
def test_get_merge_body_include_pull_request_author_mannequin() -> None:
    """
    Test case where actor is not a User and Bot to see how we handle weird cases.
    """
    pull_request = create_pull_request()
    pull_request.body = "hello world"
    pull_request.author.name = None
    pull_request.author.type = "Mannequin"

    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(message=MergeMessage(
                body=MergeBodyStyle.pull_request_body,
                include_pull_request_author=True,
            )),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(
        merge_method="squash",
        commit_message=
        "hello world\n\nCo-authored-by: barry <*****@*****.**>",
    )
    assert actual == expected
Exemple #5
0
def test_get_merge_body_empty() -> None:
    pull_request = create_pull_request()
    pull_request.body = "hello world"
    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(message=MergeMessage(body=MergeBodyStyle.empty))),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(merge_method="squash", commit_message="")
    assert actual == expected
Exemple #6
0
def test_get_merge_body_empty(pull_request: queries.PullRequest) -> None:
    pull_request.body = "hello world"
    actual = get_merge_body(
        V1(
            version=1,
            merge=Merge(
                method=MergeMethod.squash,
                message=MergeMessage(body=MergeBodyStyle.empty),
            ),
        ),
        pull_request,
    )
    expected = dict(merge_method="squash", commit_message="")
    assert actual == expected
Exemple #7
0
def test_get_merge_body_strip_html_comments() -> None:
    pull_request = create_pull_request()
    pull_request.body = "hello <!-- testing -->world"
    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(
                message=MergeMessage(body=MergeBodyStyle.pull_request_body,
                                     strip_html_comments=True)),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(merge_method="squash", commit_message="hello world")
    assert actual == expected
def test_get_merge_body_strip_html_comments(pull_request: queries.PullRequest,
                                            original: str,
                                            stripped: str) -> None:
    pull_request.body = "hello <!-- testing -->world"
    actual = get_merge_body(
        V1(
            version=1,
            merge=Merge(
                method=MergeMethod.squash,
                message=MergeMessage(body=MergeBodyStyle.pull_request_body,
                                     strip_html_comments=True),
            ),
        ),
        pull_request,
    )
    expected = dict(merge_method="squash", commit_message="hello world")
    assert actual == expected
Exemple #9
0
def test_get_merge_body_includes_pull_request_url_github_default() -> None:
    """
    We should not set a commit message when merge.body = "github_default".
    """
    pull_request = create_pull_request()
    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(
                message=MergeMessage(body=MergeBodyStyle.github_default,
                                     include_pull_request_url=True)),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(merge_method="squash", commit_message=None)
    assert actual == expected
Exemple #10
0
def test_pr_get_merge_body_full(pull_request: queries.PullRequest) -> None:
    actual = get_merge_body(
        V1(
            version=1,
            merge=Merge(
                method=MergeMethod.squash,
                message=MergeMessage(
                    title=MergeTitleStyle.pull_request_title,
                    body=MergeBodyStyle.pull_request_body,
                    include_pr_number=True,
                ),
            ),
        ),
        pull_request,
    )
    expected = dict(
        merge_method="squash",
        commit_title=pull_request.title + f" (#{pull_request.number})",
        commit_message=pull_request.body,
    )
    assert actual == expected
Exemple #11
0
def test_pr_get_merge_body_full() -> None:
    pull_request = create_pull_request()
    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(message=MergeMessage(
                title=MergeTitleStyle.pull_request_title,
                body=MergeBodyStyle.pull_request_body,
                include_pr_number=True,
            )),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(
        merge_method="squash",
        commit_title=pull_request.title + f" (#{pull_request.number})",
        commit_message=pull_request.body,
    )
    assert expected == actual
Exemple #12
0
def test_get_merge_body_cut_body_after() -> None:
    """
    Basic check of cut_body_after removing content.
    """
    pull_request = create_pull_request()
    pull_request.body = "hello <!-- testing -->world"
    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(
                message=MergeMessage(
                    body=MergeBodyStyle.pull_request_body,
                    cut_body_after="<!-- testing -->",
                )
            ),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(merge_method="squash", commit_message="hello <!-- testing -->")
    assert actual == expected
Exemple #13
0
def test_get_merge_body_include_pull_request_author_user() -> None:
    pull_request = create_pull_request()
    pull_request.body = "hello world"

    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(message=MergeMessage(
                body=MergeBodyStyle.pull_request_body,
                include_pull_request_author=True,
            )),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(
        merge_method="squash",
        commit_message=
        "hello world\n\nCo-authored-by: Barry Berkman <*****@*****.**>",
    )
    assert actual == expected
Exemple #14
0
def test_get_merge_body_cut_body_before_multiple_markers() -> None:
    """
    We should choose the first substring matching cut_body_before.
    """
    pull_request = create_pull_request()
    pull_request.body = "hello <!-- testing -->world<!-- testing --> 123"
    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(
                message=MergeMessage(
                    body=MergeBodyStyle.pull_request_body,
                    cut_body_before="<!-- testing -->",
                    strip_html_comments=True,
                )
            ),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(merge_method="squash", commit_message="world 123")
    assert actual == expected
Exemple #15
0
def test_get_merge_body_cut_body_after_strip_html() -> None:
    """
    We should be able to use strip_html_comments with cut_body_after.
    """
    pull_request = create_pull_request()
    pull_request.body = "hello <!-- testing -->world"
    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(
                message=MergeMessage(
                    body=MergeBodyStyle.pull_request_body,
                    cut_body_after="<!-- testing -->",
                    strip_html_comments=True,
                )
            ),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(merge_method="squash", commit_message="hello ")
    assert actual == expected
Exemple #16
0
def test_get_merge_body_cut_body_and_text_before() -> None:
    """
    Verify that the separator is also gone after removing content.
    """
    pull_request = create_pull_request()
    pull_request.body = "hello <!-- testing -->world"
    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(
                message=MergeMessage(
                    body=MergeBodyStyle.pull_request_body,
                    cut_body_before="<!-- testing -->",
                    cut_body_and_text=True,
                )
            ),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(merge_method="squash", commit_message="world")
    assert actual == expected
Exemple #17
0
def test_get_merge_body_cut_body_before_no_match_found() -> None:
    """
    Ensure we don't edit the message if there isn't any match found with
    cut_body_before.
    """
    pull_request = create_pull_request()
    pr_body = "hello <!-- foo -->world<!-- bar --> 123"
    pull_request.body = pr_body
    actual = get_merge_body(
        config=V1(
            version=1,
            merge=Merge(
                message=MergeMessage(
                    body=MergeBodyStyle.pull_request_body,
                    cut_body_before="<!-- buzz -->",
                )
            ),
        ),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(merge_method="squash", commit_message=pr_body)
    assert actual == expected
Exemple #18
0
             automerge_label="mergeit!",
             require_automerge_label=False,
             blacklist_title_regex="",
             blacklist_labels=["wip", "block-merge"],
             method=MergeMethod.squash,
             delete_branch_on_merge=True,
             block_on_reviews_requested=True,
             notify_on_conflict=False,
             optimistic_updates=False,
             dont_wait_on_status_checks=["ci/circleci: deploy"],
             update_branch_immediately=True,
             prioritize_ready_to_merge=True,
             message=MergeMessage(
                 title=MergeTitleStyle.pull_request_title,
                 body=MergeBodyStyle.pull_request_body,
                 include_pr_number=False,
                 body_type=BodyText.plain_text,
                 strip_html_comments=True,
             ),
         ),
     ),
 ),
 (
     "v1-opposite.2.toml",
     V1(
         version=1,
         app_id="12345",
         merge=Merge(
             automerge_label="mergeit!",
             require_automerge_label=False,
             blacklist_title_regex="",