# -*- coding: utf-8 -*-
from flask import jsonify
from flask.views import MethodView
from app import app, github
import git


@app.route('/repos/<org_name>/', endpoint="rest_repos1")
@app.route('/repos/', endpoint="rest_repos2")
def rest_repos(org_name=None):
    if not org_name:
        repos = github.get("user/repos")
    else:
        repos = github.get("orgs/%s/repos" % org_name)

    return jsonify(items=[git.repo_to_dict(repo) for repo in repos])
