<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def hook():
 """Install or remove GitHub webhook."""

    repo_id = request.json['id']

    github = GitHubAPI(user_id=current_user.id)
    repos = github.account.extra_data['repos']

    if repo_id not in repos:
        abort(404)

    if request.method == 'DELETE':
        try:
            if github.remove_hook(repo_id, repos[repo_id]['full_name']):
                db.session.commit()
                return '', 204
            else:
                abort(400)
        except Exception:
            abort(403)
    elif request.method == 'POST':
        try:
            if github.create_hook(repo_id, repos[repo_id]['full_name']):
                db.session.commit()
                return '', 201
            else:
                abort(400)
        except Exception:
            abort(403)
    else:
        abort(400)