# Buggy code
def get_push_commits_event_message(
    user_name, compare_url, branch_name, commits_data, is_truncated=False
):
    # type: (Text, Optional[Text], Text, List[Dict[str, Any]], Optional[bool]) -> Text
    pushed_message_template = (
        PUSH_PUSHED_TEXT_WITH_URL if compare_url else PUSH_PUSHED_TEXT_WITHOUT_URL
    )

    pushed_text_message = pushed_message_template.format(
        compare_url=compare_url,
        number_of_commits=len(commits_data),
        commit_or_commits=COMMIT_OR_COMMITS.format(
            "s" if len(commits_data) > 1 else ""
        ),
    )

    committers_items = get_all_committers(commits_data)  # type: List[Tuple[str, int]]
    if len(committers_items) == 1 and user_name == committers_items[0][0]:
        return PUSH_COMMITS_MESSAGE_TEMPLATE_WITHOUT_COMMITTERS.format(
            user_name=user_name,
            pushed_text=pushed_text_message,
            branch_name=branch_name,
            commits_data=get_commits_content(commits_data, is_truncated),
        ).rstrip()
    else:
        committers_details = "{} ({})".format(*committers_items[0])

        for name, number_of_commits in committers_items[1:-1]:
            committers_details = "{}, {} ({})".format(
                committers_details, name, number_of_commits
            )

        if len(committers_items) > 1:
            committers_details = "{} and {} ({})".format(
                committers_details, *committers_items[-1]
            )

        return PUSH_COMMITS_MESSAGE_TEMPLATE_WITH_COMMITTERS.format(
            user_name=user_name,
            pushed_text=pushed_text_message,
            branch_name=branch_name,
            committers_details=PUSH_COMMITS_MESSAGE_EXTENSION.format(
                committers_details
            ),
            commits_data=get_commits_content(commits_data, is_truncated),
        ).rstrip()


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/zulip/deployments/2017-05-10-06-16-16/zulip-venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/zulip/deployments/2017-05-10-06-16-16/zulip-venv/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "./zerver/webhooks/github_dispatcher.py", line 15, in api_github_webhook_dispatch
return api_github_landing(request)
File "/home/zulip/deployments/2017-05-10-06-16-16/zulip-venv/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "./zerver/decorator.py", line 104, in wrapper
return func(request, *args, **kwargs)
File "./zerver/lib/request.py", line 166, in _wrapped_view_func
return view_func(request, *args, **kwargs)
File "./zerver/decorator.py", line 384, in _wrapped_func_arguments
return limited_func(request, user_profile, *args, **kwargs)
File "./zerver/decorator.py", line 664, in wrapped_func
return func(request, *args, **kwargs)
File "./zerver/lib/request.py", line 166, in _wrapped_view_func
return view_func(request, *args, **kwargs)
File "./zerver/webhooks/github/view.py", line 270, in api_github_landing
**kwargs)
File "./zerver/webhooks/github/view.py", line 175, in api_github_v2
created=payload['created'])
File "./zerver/webhooks/github/view.py", line 294, in build_message_from_gitlog
content = get_push_commits_event_message(pusher, url, short_ref, commits)
File "./zerver/lib/webhooks/git.py", line 64, in get_push_commits_event_message
committers_details = "{} ({})".format(*committers_items[0])
IndexError: list index out of range

# Fixed code
def get_push_commits_event_message(
    user_name, compare_url, branch_name, commits_data, is_truncated=False, deleted=False
):
    # type: (Text, Optional[Text], Text, List[Dict[str, Any]], Optional[bool], Optional[bool]) -> Text
    if not commits_data and deleted:
        return PUSH_DELETE_BRANCH_MESSAGE_TEMPLATE.format(
            user_name=user_name, compare_url=compare_url, branch_name=branch_name
        )

    pushed_message_template = (
        PUSH_PUSHED_TEXT_WITH_URL if compare_url else PUSH_PUSHED_TEXT_WITHOUT_URL
    )

    pushed_text_message = pushed_message_template.format(
        compare_url=compare_url,
        number_of_commits=len(commits_data),
        commit_or_commits=COMMIT_OR_COMMITS.format(
            "s" if len(commits_data) > 1 else ""
        ),
    )

    committers_items = get_all_committers(commits_data)  # type: List[Tuple[str, int]]
    if len(committers_items) == 1 and user_name == committers_items[0][0]:
        return PUSH_COMMITS_MESSAGE_TEMPLATE_WITHOUT_COMMITTERS.format(
            user_name=user_name,
            pushed_text=pushed_text_message,
            branch_name=branch_name,
            commits_data=get_commits_content(commits_data, is_truncated),
        ).rstrip()
    else:
        committers_details = "{} ({})".format(*committers_items[0])

        for name, number_of_commits in committers_items[1:-1]:
            committers_details = "{}, {} ({})".format(
                committers_details, name, number_of_commits
            )

        if len(committers_items) > 1:
            committers_details = "{} and {} ({})".format(
                committers_details, *committers_items[-1]
            )

        return PUSH_COMMITS_MESSAGE_TEMPLATE_WITH_COMMITTERS.format(
            user_name=user_name,
            pushed_text=pushed_text_message,
            branch_name=branch_name,
            committers_details=PUSH_COMMITS_MESSAGE_EXTENSION.format(
                committers_details
            ),
            commits_data=get_commits_content(commits_data, is_truncated),
        ).rstrip()