(
    config: V1,
    merge_method: MergeMethod,
    pull_request: PullRequest,
    commits: List[Commit],
)
return merge_body
Get merge options for a pull request to call GitHub API.
Get merge options for a pull request to call GitHub API.
Get merge options for a pull request to call GitHub API .
def get_merge_body(
    config: V1,
    merge_method: MergeMethod,
    pull_request: PullRequest,
    commits: List[Commit],
) -> MergeBody:
    """
    Get merge options for a pull request to call GitHub API.
    """
    merge_body = MergeBody(merge_method=merge_method)
    if config.merge.message.body == MergeBodyStyle.pull_request_body:
        body = get_body_content(
            body_type=config.merge.message.body_type,
            strip_html_comments=config.merge.message.strip_html_comments,
            cut_body_and_text=config.merge.message.cut_body_and_text,
            cut_body_before=config.merge.message.cut_body_before,
            cut_body_after=config.merge.message.cut_body_after,
            pull_request=pull_request,
        )
        merge_body.commit_message = body
    if config.merge.message.body == MergeBodyStyle.empty:
        merge_body.commit_message = EMPTY_STRING
    if config.merge.message.title == MergeTitleStyle.pull_request_title:
        merge_body.commit_title = pull_request.title
    if config.merge.message.include_pr_number and merge_body.commit_title is not None:
        merge_body.commit_title += f" (#{pull_request.number})"

    # MergeBodyStyle.github_default overrides these settings so we can ensure that GitHub generates the commit body.
    if config.merge.message.body in (
        MergeBodyStyle.pull_request_body,
        MergeBodyStyle.empty,
    ):

        # we share coauthor logic between include_pull_request_author and
        # include_coauthors.
        coauthors = []  # type: List[PullRequestCommitUser]
        if config.merge.message.include_pull_request_author:
            coauthors.append(
                PullRequestCommitUser(
                    login=pull_request.author.login,
                    databaseId=pull_request.author.databaseId,
                    name=pull_request.author.name,
                    type=pull_request.author.type,
                )
            )
        if config.merge.message.include_coauthors:
            for commit in commits:
                if (
                    # only use commits that have identified authors.
                    commit.author is None
                    or commit.author.user is None
                    # ignore merge commits. They will have more than one parent.
                    or commit.parents.totalCount > 1
                ):
                    continue
                coauthors.append(commit.author.user)

        coauthor_trailers = get_coauthor_trailers(
            coauthors=coauthors,
            include_pull_request_author=config.merge.message.include_pull_request_author,
            pull_request_author_id=pull_request.author.databaseId,
        )

        trailer_block = ""
        if config.merge.message.include_pull_request_url:
            trailer_block += f"PR-URL: {pull_request.url}"

        if coauthor_trailers:
            if trailer_block:
                trailer_block += "\n"
            trailer_block += "\n".join(coauthor_trailers)

        if merge_body.commit_message:
            if trailer_block:
                merge_body.commit_message += "\n\n" + trailer_block
        else:
            merge_body.commit_message = trailer_block

    return merge_body
def get_merge_body ( config : V1 , merge_method : MergeMethod , pull_request : PullRequest , commits : List [ Commit ] , ) -> MergeBody : merge_body = MergeBody ( merge_method = merge_method ) if config . merge . message . body == MergeBodyStyle . pull_request_body : body = get_body_content ( body_type = config . merge . message . body_type , strip_html_comments = config . merge . message . strip_html_comments , cut_body_and_text = config . merge . message . cut_body_and_text , cut_body_before = config . merge . message . cut_body_before , cut_body_after = config . merge . message . cut_body_after , pull_request = pull_request , ) merge_body . commit_message = body if config . merge . message . body == MergeBodyStyle . empty : merge_body . commit_message = EMPTY_STRING if config . merge . message . title == MergeTitleStyle . pull_request_title : merge_body . commit_title = pull_request . title if config . merge . message . include_pr_number and merge_body . commit_title is not None : merge_body . commit_title += f" (#{pull_request.number})" # MergeBodyStyle.github_default overrides these settings so we can ensure that GitHub generates the commit body. if config . merge . message . body in ( MergeBodyStyle . pull_request_body , MergeBodyStyle . empty , ) : # we share coauthor logic between include_pull_request_author and # include_coauthors. coauthors = [ ] # type: List[PullRequestCommitUser] if config . merge . message . include_pull_request_author : coauthors . append ( PullRequestCommitUser ( login = pull_request . author . login , databaseId = pull_request . author . databaseId , name = pull_request . author . name , type = pull_request . author . type , ) ) if config . merge . message . include_coauthors : for commit in commits : if ( # only use commits that have identified authors. commit . author is None or commit . author . user is None # ignore merge commits. They will have more than one parent. or commit . parents . totalCount > 1 ) : continue coauthors . append ( commit . author . user ) coauthor_trailers = get_coauthor_trailers ( coauthors = coauthors , include_pull_request_author = config . merge . message . include_pull_request_author , pull_request_author_id = pull_request . author . databaseId , ) trailer_block = "" if config . merge . message . include_pull_request_url : trailer_block += f"PR-URL: {pull_request.url}" if coauthor_trailers : if trailer_block : trailer_block += "\n" trailer_block += "\n" . join ( coauthor_trailers ) if merge_body . commit_message : if trailer_block : merge_body . commit_message += "\n\n" + trailer_block else : merge_body . commit_message = trailer_block return merge_body