# Buggy code
def build_message_from_gitlog(
    user_profile,
    name,
    ref,
    commits,
    before,
    after,
    url,
    pusher,
    forced=None,
    created=None,
):
    # type: (UserProfile, Text, Text, List[Dict[str, str]], Text, Text, Text, Text, Optional[Text], Optional[Text]) -> Tuple[Text, Text]
    short_ref = re.sub(r"^refs/heads/", "", ref)
    subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)

    if re.match(r"^0+$", after):
        content = get_remove_branch_event_message(pusher, short_ref)
    # 'created' and 'forced' are github flags; the second check is for beanstalk
    elif (forced and not created) or (forced is None and len(commits) == 0):
        content = get_force_push_commits_event_message(
            pusher, url, short_ref, after[:7]
        )
    else:
        commits = _transform_commits_list_to_common_format(commits)
        content = get_push_commits_event_message(pusher, url, short_ref, commits)

    return subject, content


# 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 build_message_from_gitlog(
    user_profile,
    name,
    ref,
    commits,
    before,
    after,
    url,
    pusher,
    forced=None,
    created=None,
    deleted=False,
):
    # type: (UserProfile, Text, Text, List[Dict[str, str]], Text, Text, Text, Text, Optional[Text], Optional[Text], Optional[bool]) -> Tuple[Text, Text]
    short_ref = re.sub(r"^refs/heads/", "", ref)
    subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)

    if re.match(r"^0+$", after):
        content = get_remove_branch_event_message(pusher, short_ref)
    # 'created' and 'forced' are github flags; the second check is for beanstalk
    elif (forced and not created) or (forced is None and len(commits) == 0):
        content = get_force_push_commits_event_message(
            pusher, url, short_ref, after[:7]
        )
    else:
        commits = _transform_commits_list_to_common_format(commits)
        content = get_push_commits_event_message(
            pusher, url, short_ref, commits, deleted=deleted
        )

    return subject, content