Beispiel #1
0
def maybe_add_automerge_warning_comment(pull_request: PullRequest):
    """Adds comment warnings if automerge label is enabled"""

    if SGTM_FEATURE__AUTOMERGE_ENABLED:
        owner = pull_request.repository_owner_handle()
        repo_name = pull_request.repository_name()
        pr_number = pull_request.number()

        # if a PR has an automerge label and doesn't contain a comment warning, we want to maybe add a warning comment
        # only add warning comment if it's set to auto-merge after approval and hasn't yet been approved to limit noise

        if (
            (
                pull_request_has_label(
                    pull_request, AutomergeLabel.AFTER_TESTS_AND_APPROVAL.value
                )
                or pull_request_has_label(
                    pull_request, AutomergeLabel.AFTER_APPROVAL.value
                )
            )
            and not _pull_request_has_automerge_comment(pull_request)
            and not pull_request.is_approved()
        ):

            github_client.add_pr_comment(
                owner, repo_name, pr_number, AUTOMERGE_COMMENT_WARNING
            )
Beispiel #2
0
def assign_pull_request_to_author(pull_request: PullRequest):
    owner = pull_request.repository_owner_handle()
    new_assignee = pull_request.author_handle()
    github_client.set_pull_request_assignee(owner,
                                            pull_request.repository_name(),
                                            pull_request.number(),
                                            new_assignee)
    # so we don't have to re-query the PR
    pull_request.set_assignees([new_assignee])
Beispiel #3
0
def _add_asana_task_to_pull_request(pull_request: PullRequest, task_id: str):
    owner = pull_request.repository_owner_handle()
    task_url = asana_helpers.task_url_from_task_id(task_id)
    new_body = github_logic.inject_asana_task_into_pull_request_body(
        pull_request.body(), task_url)
    github_client.edit_pr_description(owner, pull_request.repository_name(),
                                      pull_request.number(), new_body)

    # Update the PullRequest object to represent the new body, so we don't have
    # to query it again
    pull_request.set_body(new_body)
Beispiel #4
0
def maybe_automerge_pull_request(pull_request: PullRequest) -> bool:
    if _is_pull_request_ready_for_automerge(pull_request):
        logger.info(
            f"Pull request {pull_request.id()} is able to be automerged, automerging now"
        )
        github_client.merge_pull_request(
            pull_request.repository_owner_handle(),
            pull_request.repository_name(),
            pull_request.number(),
            pull_request.title(),
            pull_request.body(),
        )
        return True
    else:
        return False