Example #1
0
    def update_stable_version(self):
        """
        Returns the version that was promoted to be the new stable version.

        Return ``None`` if no update was mode or if there is no version on the
        project that can be considered stable.
        """
        versions = self.versions.all()
        new_stable = determine_stable_version(versions)
        if new_stable:
            current_stable = self.get_stable_version()
            if current_stable:
                identifier_updated = (new_stable.identifier !=
                                      current_stable.identifier)
                if identifier_updated and current_stable.active and current_stable.machine:
                    log.info(
                        'Update stable version: {project}:{version}'.format(
                            project=self.slug, version=new_stable.identifier))
                    current_stable.identifier = new_stable.identifier
                    current_stable.save()
                    return new_stable
            else:
                log.info(
                    'Creating new stable version: {project}:{version}'.format(
                        project=self.slug, version=new_stable.identifier))
                current_stable = self.versions.create_stable(
                    type=new_stable.type, identifier=new_stable.identifier)
                return new_stable
Example #2
0
 def ref(self):
     if self.slug == STABLE:
         stable = determine_stable_version(
             self.project.versions(manager=INTERNAL).all()
         )
         if stable:
             return stable.slug
Example #3
0
 def update_stable_version(self):
     """
     Returns the version that was promoited to be the new stable version.
     It will return ``None`` if no update was mode or if there is no
     version on the project that can be considered stable.
     """
     versions = self.versions.all()
     new_stable = determine_stable_version(versions)
     if new_stable:
         current_stable = self.get_stable_version()
         if current_stable:
             identifier_updated = (
                 new_stable.identifier != current_stable.identifier)
             if identifier_updated and current_stable.machine:
                 log.info(
                     "Update stable version: {project}:{version}".format(
                         project=self.slug,
                         version=new_stable.identifier))
                 current_stable.identifier = new_stable.identifier
                 current_stable.save()
                 return new_stable
         else:
             log.info(
                 "Creating new stable version: {project}:{version}".format(
                     project=self.slug,
                     version=new_stable.identifier))
             current_stable = self.versions.create_stable(
                 type=new_stable.type,
                 identifier=new_stable.identifier)
             return new_stable
    def sync_versions(self, request, **kwargs):
        """
        Sync the version data in the repo (on the build server) with what we have in the database.

        Returns the identifiers for the versions that have been deleted.
        """
        project = get_object_or_404(
            Project.objects.api(self.request.user), pk=kwargs['pk'])

        # If the currently highest non-prerelease version is active, then make
        # the new latest version active as well.
        old_highest_version = determine_stable_version(project.versions.all())
        if old_highest_version is not None:
            activate_new_stable = old_highest_version.active
        else:
            activate_new_stable = False

        try:
            # Update All Versions
            data = request.DATA
            added_versions = set()
            if 'tags' in data:
                ret_set = api_utils.sync_versions(
                    project=project, versions=data['tags'], type=TAG)
                added_versions.update(ret_set)
            if 'branches' in data:
                ret_set = api_utils.sync_versions(
                    project=project, versions=data['branches'], type=BRANCH)
                added_versions.update(ret_set)
            deleted_versions = api_utils.delete_versions(project, data)
        except Exception, e:
            log.exception("Sync Versions Error: %s" % e.message)
            return Response({'error': e.message}, status=status.HTTP_400_BAD_REQUEST)
Example #5
0
    def update_stable_version(self):
        """
        Returns the version that was promoted to be the new stable version.

        Return ``None`` if no update was made or if there is no version on the
        project that can be considered stable.
        """
        versions = self.versions.all()
        new_stable = determine_stable_version(versions)
        if new_stable:
            current_stable = self.get_stable_version()
            if current_stable:
                identifier_updated = (new_stable.identifier !=
                                      current_stable.identifier)
                if identifier_updated and current_stable.machine:
                    log.info('Update stable version: %(project)s:%(version)s',
                             {
                                 'project': self.slug,
                                 'version': new_stable.identifier,
                             })
                    current_stable.identifier = new_stable.identifier
                    current_stable.save()
                    return new_stable
            else:
                log.info(
                    'Creating new stable version: %(project)s:%(version)s', {
                        'project': self.slug,
                        'version': new_stable.identifier,
                    })
                current_stable = self.versions.create_stable(
                    type=new_stable.type,
                    identifier=new_stable.identifier,
                )
                return new_stable
    def sync_versions(self, request, **kwargs):
        """
        Sync the version data in the repo (on the build server) with what we have in the database.

        Returns the identifiers for the versions that have been deleted.
        """
        project = get_object_or_404(
            Project.objects.api(self.request.user), pk=kwargs['pk'])

        # If the currently highest non-prerelease version is active, then make
        # the new latest version active as well.
        old_highest_version = determine_stable_version(project.versions.all())
        if old_highest_version is not None:
            activate_new_stable = old_highest_version.active
        else:
            activate_new_stable = False

        try:
            # Update All Versions
            data = request.data
            added_versions = set()
            if 'tags' in data:
                ret_set = api_utils.sync_versions(
                    project=project, versions=data['tags'], type=TAG)
                added_versions.update(ret_set)
            if 'branches' in data:
                ret_set = api_utils.sync_versions(
                    project=project, versions=data['branches'], type=BRANCH)
                added_versions.update(ret_set)
            deleted_versions = api_utils.delete_versions(project, data)
        except Exception, e:
            log.exception("Sync Versions Error: %s" % e.message)
            return Response({'error': e.message}, status=status.HTTP_400_BAD_REQUEST)
    def sync_versions(self, request, **kwargs):  # noqa: D205
        """
        Sync the version data in the repo (on the build server) with what we
        have in the database.

        Returns the identifiers for the versions that have been deleted.
        """
        project = get_object_or_404(Project.objects.api(request.user),
                                    pk=kwargs['pk'])

        # If the currently highest non-prerelease version is active, then make
        # the new latest version active as well.
        old_highest_version = determine_stable_version(project.versions.all())
        if old_highest_version is not None:
            activate_new_stable = old_highest_version.active
        else:
            activate_new_stable = False

        try:
            # Update All Versions
            data = request.data
            added_versions = set()
            if 'tags' in data:
                ret_set = api_utils.sync_versions(project=project,
                                                  versions=data['tags'],
                                                  type=TAG)
                added_versions.update(ret_set)
            if 'branches' in data:
                ret_set = api_utils.sync_versions(project=project,
                                                  versions=data['branches'],
                                                  type=BRANCH)
                added_versions.update(ret_set)
            deleted_versions = api_utils.delete_versions(project, data)
        except Exception as e:
            log.exception("Sync Versions Error: %s", e.message)
            return Response({'error': e.message},
                            status=status.HTTP_400_BAD_REQUEST)

        promoted_version = project.update_stable_version()
        if promoted_version:
            new_stable = project.get_stable_version()
            log.info("Triggering new stable build: {project}:{version}".format(
                project=project.slug, version=new_stable.identifier))
            trigger_build(project=project, version=new_stable)

            # Marking the tag that is considered the new stable version as
            # active and building it if it was just added.
            if (activate_new_stable
                    and promoted_version.slug in added_versions):
                promoted_version.active = True
                promoted_version.save()
                trigger_build(project=project, version=promoted_version)

        return Response({
            'added_versions': added_versions,
            'deleted_versions': deleted_versions,
        })
Example #8
0
    def sync_versions(self, request, **kwargs):  # noqa: D205
        """
        Sync the version data in the repo (on the build server) with what we
        have in the database.

        Returns the identifiers for the versions that have been deleted.
        """
        project = get_object_or_404(
            Project.objects.api(request.user), pk=kwargs['pk'])

        # If the currently highest non-prerelease version is active, then make
        # the new latest version active as well.
        old_highest_version = determine_stable_version(project.versions.all())
        if old_highest_version is not None:
            activate_new_stable = old_highest_version.active
        else:
            activate_new_stable = False

        try:
            # Update All Versions
            data = request.data
            added_versions = set()
            if 'tags' in data:
                ret_set = api_utils.sync_versions(
                    project=project, versions=data['tags'], type=TAG)
                added_versions.update(ret_set)
            if 'branches' in data:
                ret_set = api_utils.sync_versions(
                    project=project, versions=data['branches'], type=BRANCH)
                added_versions.update(ret_set)
            deleted_versions = api_utils.delete_versions(project, data)
        except Exception as e:
            log.exception("Sync Versions Error: %s", e.message)
            return Response({'error': e.message}, status=status.HTTP_400_BAD_REQUEST)

        promoted_version = project.update_stable_version()
        if promoted_version:
            new_stable = project.get_stable_version()
            log.info(
                "Triggering new stable build: {project}:{version}".format(
                    project=project.slug,
                    version=new_stable.identifier))
            trigger_build(project=project, version=new_stable)

            # Marking the tag that is considered the new stable version as
            # active and building it if it was just added.
            if (
                    activate_new_stable and
                    promoted_version.slug in added_versions):
                promoted_version.active = True
                promoted_version.save()
                trigger_build(project=project, version=promoted_version)

        return Response({
            'added_versions': added_versions,
            'deleted_versions': deleted_versions,
        })
    def update_stable_version(self):
        """
        Returns the version that was promoted to be the new stable version.

        Return ``None`` if no update was mode or if there is no version on the
        project that can be considered stable.
        """
        versions = self.versions.all()
        new_stable = determine_stable_version(versions)
        if new_stable:
            current_stable = self.get_stable_version()
            if current_stable:
                identifier_updated = (
                    new_stable.identifier != current_stable.identifier
                )
                if identifier_updated and current_stable.machine:
                    log.info(
                        'Update stable version: %(project)s:%(version)s',
                        {
                            'project': self.slug,
                            'version': new_stable.identifier,
                        }
                    )
                    current_stable.identifier = new_stable.identifier
                    current_stable.save()
                    return new_stable
            else:
                log.info(
                    'Creating new stable version: %(project)s:%(version)s',
                    {
                        'project': self.slug,
                        'version': new_stable.identifier,
                    }
                )
                current_stable = self.versions.create_stable(
                    type=new_stable.type,
                    identifier=new_stable.identifier,
                )
                return new_stable
Example #10
0
    def sync_versions(self, request, **kwargs):  # noqa: D205
        """
        Sync the version data in the repo (on the build server).

        Version data in the repo is synced with what we have in the database.

        :returns: the identifiers for the versions that have been deleted.
        """
        project = get_object_or_404(
            Project.objects.api(request.user),
            pk=kwargs['pk'],
        )

        # If the currently highest non-prerelease version is active, then make
        # the new latest version active as well.
        old_highest_version = determine_stable_version(project.versions.all())
        if old_highest_version is not None:
            activate_new_stable = old_highest_version.active
        else:
            activate_new_stable = False

        try:
            # Update All Versions
            data = request.data
            added_versions = set()
            if 'tags' in data:
                ret_set = sync_versions_to_db(
                    project=project,
                    versions=data['tags'],
                    type=TAG,
                )
                added_versions.update(ret_set)
            if 'branches' in data:
                ret_set = sync_versions_to_db(
                    project=project,
                    versions=data['branches'],
                    type=BRANCH,
                )
                added_versions.update(ret_set)
            deleted_versions = delete_versions_from_db(project, data)
            deleted_active_versions = get_deleted_active_versions(
                project, data)
        except Exception as e:
            log.exception('Sync Versions Error')
            return Response(
                {
                    'error': str(e),
                },
                status=status.HTTP_400_BAD_REQUEST,
            )

        try:
            # The order of added_versions isn't deterministic.
            # We don't track the commit time or any other metadata.
            # We usually have one version added per webhook.
            run_automation_rules(project, added_versions,
                                 deleted_active_versions)
        except Exception:
            # Don't interrupt the request if something goes wrong
            # in the automation rules.
            log.exception('Failed to execute automation rules for [%s]: %s',
                          project.slug, added_versions)

        # TODO: move this to an automation rule
        promoted_version = project.update_stable_version()
        new_stable = project.get_stable_version()
        if promoted_version and new_stable and new_stable.active:
            log.info('Triggering new stable build: %(project)s:%(version)s', {
                'project': project.slug,
                'version': new_stable.identifier,
            })
            trigger_build(project=project, version=new_stable)

            # Marking the tag that is considered the new stable version as
            # active and building it if it was just added.
            if (activate_new_stable
                    and promoted_version.slug in added_versions):
                promoted_version.active = True
                promoted_version.save()
                trigger_build(project=project, version=promoted_version)

        return Response({
            'added_versions': added_versions,
            'deleted_versions': deleted_versions,
        })
Example #11
0
 def ref(self):
     if self.slug == STABLE:
         stable = determine_stable_version(self.project.versions.all())
         if stable:
             return stable.slug