References:
        https://developer.github.com/v3/issues/events/#list-events-for-an-issue

def check_collaborator_has_write(repo: GithubRepository, username: str
                                 ) -> Optional[CannotAutomergeError]:
    """
    References:
        https://developer.github.com/v3/issues/events/#list-events-for-an-issue
    """
    url = ("https://api.github.com/repos/{}/{}/collaborators/{}/permission"
           "?access_token={}".format(repo.organization,
                                     repo.name,
                                     username,
                                     repo.access_token))

    response = requests.get(url)

    if response.status_code != 200:
        raise RuntimeError(
            'Collaborator check failed. Code: {}. Content: {}.'.format(
                response.status_code, response.content))

    payload = json.JSONDecoder().decode(response.content.decode())
    if payload['permission'] not in ['admin', 'write']:
        return CannotAutomergeError(
            'Only collaborators with write permission can use automerge.')

    return None