コード例 #1
0
ファイル: views.py プロジェクト: KernelPanicAUS/hasdocs.com
def import_from_heroku(request):
    """Imports a project from a Heroku app."""
    if request.method == 'POST':
        logger.info('Importing an app from Heroku')
        api_key = request.user.get_profile().heroku_api_key
        r = requests.get('%s/apps/%s' % (
            settings.HEROKU_API_URL, request.POST['app_name']
        ), auth=('', api_key))
        app = r.json()
        # Creates a new project based on the Heroku app
        language = Language.objects.get(
            name=app['buildpack_provided_description'])
        # TODO: generator must be detected from project data
        generator = Generator.objects.get(name='Sphinx')
        project = Project(owner=request.user, name=app['name'],
                          url=app['web_url'], git_url=app['git_url'],
                          private=True, language=language, generator=generator)
        project.save()
        logger.info('Imported %s app from Heroku.' % project.name)
        # Creates a post-receive webhook at GitHub
        create_hook_heroku(request)
        # Build docs for the first time
        update_docs(project)
        return HttpResponseRedirect(
            reverse('project_detail', args=[request.user, project]))
    else:
        raise Http404
コード例 #2
0
def import_from_heroku(request):
    """Imports a project from a Heroku app."""
    if request.method == 'POST':
        logger.info('Importing an app from Heroku')
        api_key = request.user.get_profile().heroku_api_key
        r = requests.get('%s/apps/%s' %
                         (settings.HEROKU_API_URL, request.POST['app_name']),
                         auth=('', api_key))
        app = r.json()
        # Creates a new project based on the Heroku app
        language = Language.objects.get(
            name=app['buildpack_provided_description'])
        # TODO: generator must be detected from project data
        generator = Generator.objects.get(name='Sphinx')
        project = Project(owner=request.user,
                          name=app['name'],
                          url=app['web_url'],
                          git_url=app['git_url'],
                          private=True,
                          language=language,
                          generator=generator)
        project.save()
        logger.info('Imported %s app from Heroku.' % project.name)
        # Creates a post-receive webhook at GitHub
        create_hook_heroku(request)
        # Build docs for the first time
        update_docs(project)
        return HttpResponseRedirect(
            reverse('project_detail', args=[request.user, project]))
    else:
        raise Http404
コード例 #3
0
def sync_org_repos_github(org, payload):
    """Syncs all the repositories of an organization with GitHub."""
    logger.info('Syncing organization repos for %s with GitHub' % org)
    repos = github_api_get('/orgs/%s/repos' % org, payload)
    for repo in repos:
        project = Project.from_kwargs(**repo)
        logger.info('Project %s has been synced' % project.name)
    logger.info('Organization repos have been synced for %s' % org)
コード例 #4
0
def sync_user_repos_github(user, payload):
    """Sync the repositories of a user with GitHub."""
    logger.info('Syncing repositories for %s with GitHub' % user)
    repos = github_api_get('/user/repos?type=owner', params=payload)
    for repo in repos:
        project = Project.from_kwargs(**repo)
        logger.info('Project %s has been synced' % project.name)
    logger.info('Repositories have been synced for %s' % user)