예제 #1
0
def trigger_build(project, version=None, record=True, force=False, basic=False):
    """
    An API to wrap the triggering of a build.
    """
    # Avoid circular import
    from readthedocs.projects.tasks import update_docs

    if project.skip:
        return None

    if not version:
        version = project.versions.get(slug=LATEST)

    if record:
        build = Build.objects.create(
            project=project,
            version=version,
            type='html',
            state='triggered',
            success=True,
        )
        update_docs.delay(pk=project.pk, version_pk=version.pk, record=record,
                          force=force, basic=basic, build_pk=build.pk)
    else:
        build = None
        update_docs.delay(pk=project.pk, version_pk=version.pk, record=record,
                          force=force, basic=basic)

    return build
예제 #2
0
def trigger_build(project, version=None, record=True, force=False, basic=False):
    """
    An API to wrap the triggering of a build.
    """
    # Avoid circular import
    from readthedocs.projects.tasks import update_docs

    if project.skip:
        return None

    if not version:
        version = project.versions.get(slug=LATEST)

    if record:
        build = Build.objects.create(
            project=project,
            version=version,
            type='html',
            state='triggered',
            success=True,
        )
        update_docs.delay(pk=project.pk, version_pk=version.pk, record=record,
                          force=force, basic=basic, build_pk=build.pk)
    else:
        build = None
        update_docs.delay(pk=project.pk, version_pk=version.pk, record=record,
                          force=force, basic=basic)

    return build
예제 #3
0
    def save(self, *args, **kwargs):
        # save the project
        project = super(ImportProjectForm, self).save(*args, **kwargs)

        # kick off the celery job
        update_docs.delay(pk=project.pk)

        return project
예제 #4
0
 def save_version(self, version):
     new_value = self.cleaned_data.get('version-%s' % version.slug, None)
     privacy_level = self.cleaned_data.get('privacy-%s' % version.slug, None)
     if (new_value is None or new_value == version.active) and (privacy_level is None or privacy_level == version.privacy_level):
         return
     version.active = new_value
     version.privacy_level = privacy_level
     version.save()
     if version.active and not version.built and not version.uploaded:
         update_docs.delay(self.project.pk, record=True, version_pk=version.pk)
예제 #5
0
def bitbucket_build(request):
    if request.method == 'POST':
        obj = json.loads(request.POST['payload'])
        rep = obj['repository']
        name = rep['name']
        url = "%s%s" % ("bitbucket.org", rep['absolute_url'].rstrip('/'))
        log.info("(Bitbucket Build) %s" % (url))
        try:
            project = Project.objects.filter(repo__contains=url)[0]
            update_docs.delay(pk=project.pk, force=True)
            return HttpResponse('Build Started')
        except Exception, e:
            log.error("(Github Build) Failed: %s:%s" % (name, e))
            return HttpResponseNotFound('Build Failed')
예제 #6
0
def bitbucket_build(request):
    if request.method == 'POST':
        obj = json.loads(request.POST['payload'])
        rep = obj['repository']
        name = rep['name']
        url = "%s%s" % ("bitbucket.org",  rep['absolute_url'].rstrip('/'))
        log.info("(Bitbucket Build) %s" % (url))
        try:
            project = Project.objects.filter(repo__contains=url)[0]
            update_docs.delay(pk=project.pk, force=True)
            return HttpResponse('Build Started')
        except Exception, e:
            log.error("(Github Build) Failed: %s:%s" % (name, e))
            return HttpResponseNotFound('Build Failed')
예제 #7
0
def generic_build(request, pk):
    project = Project.objects.get(pk=pk)
    context = {'built': False, 'project': project}
    if request.method == 'POST':
        context['built'] = True
        slug = request.POST.get('version_slug', None)
        if slug:
            version = project.versions.get(slug=slug)
            update_docs.delay(pk=pk, version_pk=version.pk, force=True)
        else:
            update_docs.delay(pk=pk, force=True)
        #return HttpResponse('Build Started')
        return render_to_response('post_commit.html', context,
                context_instance=RequestContext(request))
    return render_to_response('post_commit.html', context,
            context_instance=RequestContext(request))
예제 #8
0
def generic_build(request, pk):
    project = Project.objects.get(pk=pk)
    context = {'built': False, 'project': project}
    if request.method == 'POST':
        context['built'] = True
        slug = request.POST.get('version_slug', None)
        if slug:
            version = project.versions.get(slug=slug)
            update_docs.delay(pk=pk, version_pk=version.pk, force=True)
        else:
            update_docs.delay(pk=pk, force=True)
        #return HttpResponse('Build Started')
        return render_to_response('post_commit.html',
                                  context,
                                  context_instance=RequestContext(request))
    return render_to_response('post_commit.html',
                              context,
                              context_instance=RequestContext(request))
예제 #9
0
def github_build(request):
    """
    A post-commit hook for github.
    """
    if request.method == 'POST':
        obj = json.loads(request.POST['payload'])
        name = obj['repository']['name']
        url = obj['repository']['url']
        ghetto_url = url.replace('http://', '').replace('https://', '')
        branch = obj['ref'].replace('refs/heads/', '')
        log.info("(Github Build) %s:%s" % (ghetto_url, branch))
        version_pk = None
        version_slug = branch
        try:
            projects = Project.objects.filter(repo__contains=ghetto_url)
            for project in projects:
                version = project.version_from_branch_name(branch)
                if version:
                    log.info("(Github Build) Processing %s:%s" %
                             (project.slug, version.slug))
                    default = project.default_branch or project.vcs_repo(
                    ).fallback_branch
                    if branch == default:
                        #Shortcircuit versions that are default
                        #These will build at "latest", and thus won't be active
                        version = project.versions.get(slug='latest')
                        version_pk = version.pk
                        version_slug = version.slug
                        log.info("(Github Build) Building %s:%s" %
                                 (project.slug, version.slug))
                    elif version in project.versions.exclude(active=True):
                        log.info("(Github Build) Not building %s" %
                                 version.slug)
                        return HttpResponseNotFound('Not Building: %s' %
                                                    branch)
                    else:
                        version_pk = version.pk
                        version_slug = version.slug
                        log.info("(Github Build) Building %s:%s" %
                                 (project.slug, version.slug))
                else:
                    version_slug = 'latest'
                    branch = 'latest'
                    log.info("(Github Build) Building %s:latest" %
                             project.slug)
                #version_pk being None means it will use "latest"
                update_docs.delay(pk=project.pk,
                                  version_pk=version_pk,
                                  force=True)
            return HttpResponse('Build Started: %s' % version_slug)
        except Exception, e:
            log.error("(Github Build) Failed: %s:%s" % (name, e))
            #handle new repos
            project = Project.objects.filter(repo__contains=ghetto_url)
            if not len(project):
                project = Project.objects.filter(name__icontains=name)
                if len(project):
                    #Bail if we think this thing exists
                    return HttpResponseNotFound('Build Failed')
            #create project
            try:
                email = obj['repository']['owner']['email']
                desc = obj['repository']['description']
                homepage = obj['repository']['homepage']
                repo = obj['repository']['url']
                user = User.objects.get(email=email)
                proj = Project.objects.create(
                    name=name,
                    description=desc,
                    project_url=homepage,
                    repo=repo,
                )
                proj.users.add(user)
                log.error("Created new project %s" % (proj))
            except Exception, e:
                log.error("Error creating new project %s: %s" % (name, e))
                return HttpResponseNotFound('Build Failed')

            return HttpResponseNotFound('Build Failed')
예제 #10
0
def github_build(request):
    """
    A post-commit hook for github.
    """
    if request.method == 'POST':
        obj = json.loads(request.POST['payload'])
        name = obj['repository']['name']
        url = obj['repository']['url']
        ghetto_url = url.replace('http://', '').replace('https://', '')
        branch = obj['ref'].replace('refs/heads/', '')
        log.info("(Github Build) %s:%s" % (ghetto_url, branch))
        version_pk = None
        version_slug = branch
        try:
            projects = Project.objects.filter(repo__contains=ghetto_url)
            for project in projects:
                version = project.version_from_branch_name(branch)
                if version:
                    log.info("(Github Build) Processing %s:%s" % (project.slug, version.slug))
                    default = project.default_branch or project.vcs_repo().fallback_branch
                    if branch == default:
                        #Shortcircuit versions that are default
                        #These will build at "latest", and thus won't be active
                        version = project.versions.get(slug='latest')
                        version_pk = version.pk
                        version_slug = version.slug
                        log.info("(Github Build) Building %s:%s" % (project.slug, version.slug))
                    elif version in project.versions.exclude(active=True):
                        log.info("(Github Build) Not building %s" % version.slug)
                        return HttpResponseNotFound('Not Building: %s' % branch)
                    else:
                        version_pk = version.pk
                        version_slug = version.slug
                        log.info("(Github Build) Building %s:%s" % (project.slug, version.slug))
                else:
                    version_slug = 'latest'
                    branch = 'latest'
                    log.info("(Github Build) Building %s:latest" % project.slug)
                #version_pk being None means it will use "latest"
                update_docs.delay(pk=project.pk, version_pk=version_pk, force=True)
            return HttpResponse('Build Started: %s' % version_slug)
        except Exception, e:
            log.error("(Github Build) Failed: %s:%s" % (name, e))
            #handle new repos
            project = Project.objects.filter(repo__contains=ghetto_url)
            if not len(project):
                project = Project.objects.filter(name__icontains=name)
                if len(project):
                    #Bail if we think this thing exists
                    return HttpResponseNotFound('Build Failed')
            #create project
            try:
                email = obj['repository']['owner']['email']
                desc = obj['repository']['description']
                homepage = obj['repository']['homepage']
                repo = obj['repository']['url']
                user = User.objects.get(email=email)
                proj = Project.objects.create(
                    name=name,
                    description=desc,
                    project_url=homepage,
                    repo=repo,
                )
                proj.users.add(user)
                log.error("Created new project %s" % (proj))
            except Exception, e:
                log.error("Error creating new project %s: %s" % (name, e))
                return HttpResponseNotFound('Build Failed')

            return HttpResponseNotFound('Build Failed')