예제 #1
0
def test_get_merge_body_include_coauthors_invalid_body_style() -> None:
    """
    We only include trailers for MergeBodyStyle.pull_request_body and MergeBodyStyle.empty. Verify we don't add coauthor trailers for MergeBodyStyle.github_default.
    """
    pull_request = create_pull_request()
    pull_request.body = "hello world"
    config = create_config()
    config.merge.message.include_coauthors = True
    config.merge.message.body = MergeBodyStyle.github_default
    actual = get_merge_body(
        config=config,
        pull_request=pull_request,
        merge_method=MergeMethod.merge,
        commits=[
            create_commit(database_id=9023904,
                          name="",
                          login="******",
                          type="User"),
            create_commit(database_id=590434,
                          name="Maeve Millay",
                          login="******",
                          type="Bot"),
        ],
    )
    expected = MergeBody(merge_method="merge", commit_message=None)
    assert actual == expected
예제 #2
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
예제 #3
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
예제 #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
예제 #5
0
def test_pr_get_merge_body_empty() -> None:
    pull_request = create_pull_request()
    actual = get_merge_body(
        config=V1(version=1),
        pull_request=pull_request,
        merge_method=MergeMethod.squash,
        commits=[],
    )
    expected = MergeBody(merge_method="squash")
    assert actual == expected
예제 #6
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
예제 #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
예제 #8
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
예제 #9
0
def test_get_merge_body_include_pull_request_author_invalid_body_style(
) -> None:
    """
    We only include trailers MergeBodyStyle.pull_request_body and
    MergeBodyStyle.empty. Verify we don't include trailers for
    MergeBodyStyle.github_default.
    """
    pull_request = create_pull_request()
    pull_request.body = "hello world"
    config = create_config()
    config.merge.message.include_pull_request_author = True

    config.merge.message.body = MergeBodyStyle.github_default
    actual = get_merge_body(
        config=config,
        pull_request=pull_request,
        merge_method=MergeMethod.merge,
        commits=[],
    )
    expected = MergeBody(merge_method="merge", commit_message=None)
    assert actual == expected
예제 #10
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
예제 #11
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
예제 #12
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
예제 #13
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
예제 #14
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
예제 #15
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
예제 #16
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
예제 #17
0
def test_get_merge_body_include_coauthors_include_pr_author() -> None:
    """
    We should include the pull request author when configured.
    """
    pull_request = create_pull_request()
    pull_request.body = "hello world"
    config = create_config()
    config.merge.message.body = MergeBodyStyle.pull_request_body
    config.merge.message.include_coauthors = True
    config.merge.message.include_pull_request_author = True

    actual = get_merge_body(
        config=config,
        merge_method=MergeMethod.merge,
        pull_request=pull_request,
        commits=[
            create_commit(database_id=9023904,
                          name="Bernard Lowe",
                          login="******",
                          type="User"),
            # we should ignore a duplicate entry for the PR author when
            # include_pull_request_author is enabled.
            create_commit(
                database_id=pull_request.author.databaseId,
                name=pull_request.author.name,
                login=pull_request.author.login,
                type=pull_request.author.type,
            ),
        ],
    )
    expected = MergeBody(
        merge_method="merge",
        commit_message=
        f"hello world\n\nCo-authored-by: {pull_request.author.name} <{pull_request.author.databaseId}+{pull_request.author.login}@users.noreply.github.com>\nCo-authored-by: Bernard Lowe <*****@*****.**>",
    )
    assert actual == expected
예제 #18
0
def test_get_merge_body_include_coauthors() -> None:
    """
    Verify we include coauthor trailers for MergeBodyStyle.pull_request_body.
    """
    pull_request = create_pull_request()
    pull_request.body = "hello world"
    config = create_config()
    config.merge.message.body = MergeBodyStyle.pull_request_body
    config.merge.message.include_coauthors = True
    config.merge.message.include_pull_request_author = False

    actual = get_merge_body(
        config=config,
        merge_method=MergeMethod.merge,
        pull_request=pull_request,
        commits=[
            create_commit(database_id=9023904,
                          name="Bernard Lowe",
                          login="******",
                          type="User"),
            create_commit(database_id=590434,
                          name="Maeve Millay",
                          login="******",
                          type="Bot"),
            # we default to the login when name is None.
            create_commit(database_id=771233,
                          name=None,
                          login="******",
                          type="Bot"),
            # without a databaseID the commit author will be ignored.
            create_commit(database_id=None,
                          name=None,
                          login="******",
                          type="User"),
            # duplicate should be ignored.
            create_commit(database_id=9023904,
                          name="Bernard Lowe",
                          login="******",
                          type="User"),
            # merge commits should be ignored. merge commits will have more than
            # one parent.
            create_commit(
                database_id=1,
                name="Arnold Weber",
                login="******",
                type="User",
                parents=2,
            ),
            # pull request author should be ignored when
            # include_pull_request_author is not enabled
            create_commit(
                database_id=pull_request.author.databaseId,
                name="Joe PR Author",
                login="******",
                type="User",
            ),
        ],
    )
    expected = MergeBody(
        merge_method="merge",
        commit_message=
        "hello world\n\nCo-authored-by: Bernard Lowe <*****@*****.**>\nCo-authored-by: Maeve Millay <590434+maeve-m[bot]@users.noreply.github.com>\nCo-authored-by: d-abernathy[bot] <771233+d-abernathy[bot]@users.noreply.github.com>",
    )
    assert actual == expected