示例#1
0
class Build(ProjectBoundMixin, StandardAttributes, db.Model):
    """
    A single build linked to a source.

    Each Build contains many Jobs.
    """
    source_id = db.Column(
        GUID, db.ForeignKey('source.id', ondelete='CASCADE'), nullable=False, index=True
    )
    number = db.Column(db.Integer, nullable=False)
    label = db.Column(db.String, nullable=False)
    status = db.Column(Enum(Status), nullable=False, default=Status.unknown)
    result = db.Column(Enum(Result), nullable=False, default=Result.unknown)
    date_started = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    date_finished = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    data = db.Column(JSONEncodedDict, nullable=True)
    provider = db.Column(db.String, nullable=True)
    external_id = db.Column(db.String(64), nullable=True)

    source = db.relationship('Source')
    stats = db.relationship(
        'ItemStat',
        foreign_keys='[ItemStat.item_id]',
        primaryjoin='ItemStat.item_id == Build.id',
        lazy='subquery',
        viewonly=True,
        uselist=True
    )

    __tablename__ = 'build'
    __table_args__ = (
        db.UniqueConstraint('project_id', 'number', name='unq_build_number'),
        db.UniqueConstraint('project_id', 'provider', 'external_id', name='unq_build_provider')
    )
    __repr__ = model_repr('number', 'status', 'result')
示例#2
0
class ChangeRequest(RepositoryBoundMixin, StandardAttributes, db.Model):
    number = db.Column(db.Integer, nullable=False)
    # the parent revision is our base commit that this change request applies to
    parent_revision_sha = db.Column(db.String(40), nullable=False)
    # for branch-style change requests (e.g. GitHub Pull Requests) we capture
    # the 'current revision' in addition to the 'parent revision'
    head_revision_sha = db.Column(db.String(40), nullable=True)
    message = db.Column(db.String, nullable=False)
    author_id = db.Column(GUID,
                          db.ForeignKey("author.id"),
                          index=True,
                          nullable=True)
    provider = db.Column(db.String, nullable=True)
    external_id = db.Column(db.String(64), nullable=True)
    url = db.Column(db.String, nullable=True)
    data = db.Column(JSONEncodedDict, nullable=True)
    date_updated = db.Column(db.TIMESTAMP(timezone=True),
                             nullable=True,
                             onupdate=timezone.now)

    head_revision = db.relationship(
        "Revision",
        foreign_keys=
        "[ChangeRequest.repository_id, ChangeRequest.head_revision_sha]",
        viewonly=True,
    )
    parent_revision = db.relationship(
        "Revision",
        foreign_keys=
        "[ChangeRequest.repository_id, ChangeRequest.parent_revision_sha]",
        viewonly=True,
    )
    author = db.relationship("Author")

    __tablename__ = "change_request"
    __table_args__ = (
        db.ForeignKeyConstraint(
            ("repository_id", "parent_revision_sha"),
            ("revision.repository_id", "revision.sha"),
        ),
        db.ForeignKeyConstraint(
            ("repository_id", "head_revision_sha"),
            ("revision.repository_id", "revision.sha"),
        ),
        db.Index("idx_cr_parent_revision", "repository_id",
                 "parent_revision_sha"),
        db.Index("idx_cr_head_revision", "repository_id", "head_revision_sha"),
        db.UniqueConstraint("repository_id", "number", name="unq_cr_number"),
        db.UniqueConstraint("repository_id",
                            "provider",
                            "external_id",
                            name="unq_cr_provider"),
    )
    __repr__ = model_repr("repository_id", "parent_revision_sha")

    @property
    def subject(self):
        return self.message.splitlines()[0]
示例#3
0
class Job(RepositoryBoundMixin, StandardAttributes, db.Model):
    """
    A single job, which is the actual execution unit for a build.
    """

    id = db.Column(GUID, primary_key=True, default=GUID.default_value)
    build_id = db.Column(GUID,
                         db.ForeignKey("build.id", ondelete="CASCADE"),
                         nullable=False,
                         index=True)
    number = db.Column(db.Integer, nullable=False)
    label = db.Column(db.String, nullable=True)
    status = db.Column(Enum(Status), nullable=False, default=Status.unknown)
    result = db.Column(Enum(Result), nullable=False, default=Result.unknown)
    allow_failure = db.Column(db.Boolean,
                              nullable=False,
                              default=False,
                              server_default="0")
    date_started = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    date_updated = db.Column(db.TIMESTAMP(timezone=True),
                             nullable=True,
                             onupdate=timezone.now)
    date_finished = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    data = db.Column(JSONEncodedDict, nullable=True)
    provider = db.Column(db.String, nullable=True)
    external_id = db.Column(db.String(64), nullable=True)
    url = db.Column(db.String, nullable=True)

    build = db.relationship("Build",
                            backref=db.backref("jobs",
                                               order_by="Job.date_created"),
                            innerjoin=True)
    stats = db.relationship(
        "ItemStat",
        foreign_keys="[ItemStat.item_id]",
        primaryjoin="ItemStat.item_id == Job.id",
        viewonly=True,
        uselist=True,
    )
    failures = db.relationship(
        "FailureReason",
        foreign_keys="[FailureReason.job_id]",
        primaryjoin="FailureReason.job_id == Job.id",
        viewonly=True,
        uselist=True,
    )

    __tablename__ = "job"
    __table_args__ = (
        db.UniqueConstraint("build_id", "number", name="unq_job_number"),
        db.UniqueConstraint("build_id",
                            "provider",
                            "external_id",
                            name="unq_job_provider"),
    )
    __repr__ = model_repr("build_id", "number", "status", "result")
示例#4
0
class Build(RepositoryBoundMixin, StandardAttributes, db.Model):
    """
    A single build linked to a source.

    Each Build contains many Jobs.
    """

    source_id = db.Column(GUID,
                          db.ForeignKey("source.id", ondelete="CASCADE"),
                          nullable=False,
                          index=True)
    number = db.Column(db.Integer, nullable=False)
    label = db.Column(db.String, nullable=False)
    status = db.Column(Enum(Status), nullable=False, default=Status.unknown)
    result = db.Column(Enum(Result), nullable=False, default=Result.unknown)
    date_created = db.Column(
        db.TIMESTAMP(timezone=True),
        nullable=False,
        default=timezone.now,
        server_default=func.now(),
        index=True,
    )
    date_started = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    date_finished = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    data = db.Column(JSONEncodedDict, nullable=True)
    provider = db.Column(db.String, nullable=True)
    external_id = db.Column(db.String(64), nullable=True)
    url = db.Column(db.String, nullable=True)

    source = db.relationship("Source", innerjoin=True)
    stats = db.relationship(
        "ItemStat",
        foreign_keys="[ItemStat.item_id]",
        primaryjoin="ItemStat.item_id == Build.id",
        viewonly=True,
        uselist=True,
    )

    __tablename__ = "build"
    __table_args__ = (
        db.UniqueConstraint("repository_id", "number",
                            name="unq_build_number"),
        db.UniqueConstraint("repository_id",
                            "provider",
                            "external_id",
                            name="unq_build_provider"),
    )
    __repr__ = model_repr("number", "status", "result")
示例#5
0
class FailureReason(RepositoryBoundMixin, StandardAttributes, db.Model):
    class Reason(enum.Enum):
        failing_tests = "failing_tests"
        missing_tests = "missing_tests"
        no_jobs = "no_jobs"
        unresolvable_ref = "unresolvable_ref"

    build_id = db.Column(GUID,
                         db.ForeignKey("build.id", ondelete="CASCADE"),
                         nullable=True)
    job_id = db.Column(GUID,
                       db.ForeignKey("job.id", ondelete="CASCADE"),
                       nullable=True)
    reason = db.Column(StrEnum(Reason), nullable=False)

    build = db.relationship("Build")
    job = db.relationship("Job")

    __tablename__ = "failurereason"
    __table_args__ = (
        db.UniqueConstraint("build_id",
                            "job_id",
                            "reason",
                            name="unq_failurereason_key"),
        db.Index(
            "unq_failurereason_buildonly",
            build_id,
            reason,
            unique=True,
            postgresql_where=job_id.is_(None),
        ),
    )
    __repr__ = model_repr("reason")
示例#6
0
文件: job.py 项目: pombredanne/zeus
class Job(RepositoryBoundMixin, StandardAttributes, db.Model):
    """
    A single job, which is the actual execution unit for a build.
    """
    id = db.Column(GUID, primary_key=True, default=GUID.default_value)
    build_id = db.Column(GUID,
                         db.ForeignKey('build.id', ondelete='CASCADE'),
                         nullable=False,
                         index=True)
    number = db.Column(db.Integer, nullable=False)
    label = db.Column(db.String, nullable=True)
    status = db.Column(Enum(Status), nullable=False, default=Status.unknown)
    result = db.Column(Enum(Result), nullable=False, default=Result.unknown)
    date_started = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    date_finished = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    data = db.Column(JSONEncodedDict, nullable=True)
    provider = db.Column(db.String, nullable=True)
    external_id = db.Column(db.String(64), nullable=True)
    url = db.Column(db.String, nullable=True)

    build = db.relationship('Build',
                            backref=db.backref('jobs',
                                               order_by='Job.date_created'),
                            innerjoin=True)
    stats = db.relationship('ItemStat',
                            foreign_keys='[ItemStat.item_id]',
                            primaryjoin='ItemStat.item_id == Job.id',
                            viewonly=True,
                            uselist=True)
    failures = db.relationship(
        'FailureReason',
        foreign_keys='[FailureReason.job_id]',
        primaryjoin='FailureReason.job_id == Job.id',
        viewonly=True,
        uselist=True,
    )

    __tablename__ = 'job'
    __table_args__ = (db.UniqueConstraint('build_id',
                                          'number',
                                          name='unq_job_number'),
                      db.UniqueConstraint('build_id',
                                          'provider',
                                          'external_id',
                                          name='unq_job_provider'))
    __repr__ = model_repr('build_id', 'number', 'status', 'result')
示例#7
0
class Repository(OrganizationBoundMixin, StandardAttributes, db.Model):
    """
    Represents a single repository.
    """
    query_class = RepositoryAccessBoundQuery

    provider = db.Column(StrEnum(RepositoryProvider),
                         default=RepositoryProvider.native,
                         nullable=False)
    external_id = db.Column(db.String(64))
    url = db.Column(db.String(200), nullable=False)
    backend = db.Column(Enum(RepositoryBackend),
                        default=RepositoryBackend.unknown,
                        nullable=False)
    status = db.Column(Enum(RepositoryStatus),
                       default=RepositoryStatus.inactive,
                       nullable=False)
    data = db.Column(JSONEncodedDict, nullable=True)
    last_update = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    last_update_attempt = db.Column(db.TIMESTAMP(timezone=True), nullable=True)

    options = db.relationship(
        'ItemOption',
        foreign_keys='[ItemOption.item_id]',
        primaryjoin='ItemOption.item_id == Repository.id',
        lazy='subquery',
        viewonly=True,
        uselist=True)

    __tablename__ = 'repository'
    __table_args__ = (db.UniqueConstraint('organization_id',
                                          'provider',
                                          'external_id',
                                          name='unq_external_id'), )
    __repr__ = model_repr('url', 'provider', 'external_id')

    def get_vcs(self):
        from zeus.models import ItemOption
        from zeus.vcs.git import GitVcs

        options = dict(
            db.session.query(ItemOption.name, ItemOption.value).filter(
                ItemOption.item_id == self.id,
                ItemOption.name.in_([
                    'auth.username',
                ])))

        kwargs = {
            'path': os.path.join(current_app.config['REPO_ROOT'], self.id.hex),
            'url': self.url,
            'username': options.get('auth.username'),
        }

        if self.backend == RepositoryBackend.git:
            return GitVcs(**kwargs)
        else:
            raise NotImplementedError('Invalid backend: {}'.format(
                self.backend))
示例#8
0
文件: itemstat.py 项目: robopsi/zeus
class ItemStat(db.Model):
    id = db.Column(GUID, primary_key=True, default=GUID.default_value)
    item_id = db.Column(GUID, nullable=False)
    name = db.Column(db.String(64), nullable=False)
    value = db.Column(db.Integer, nullable=False)

    __tablename__ = "itemstat"
    __table_args__ = (db.UniqueConstraint("item_id", "name", name="unq_itemstat_name"),)
    __repr__ = model_repr("item_id", "name")
示例#9
0
class Source(RepositoryBoundMixin, StandardAttributes, db.Model):
    """
    A source represents the canonical parameters that a build is running against.
    """

    patch_id = db.Column(GUID,
                         db.ForeignKey("patch.id", ondelete="CASCADE"),
                         unique=True,
                         nullable=True)
    revision_sha = db.Column(db.String(40), nullable=False)
    data = db.Column(JSONEncodedDict, nullable=True)
    author_id = db.Column(GUID,
                          db.ForeignKey("author.id", ondelete="SET NULL"),
                          index=True,
                          nullable=True)

    author = db.relationship("Author")
    patch = db.relationship("Patch")
    revision = db.relationship(
        "Revision",
        foreign_keys="[Source.repository_id, Source.revision_sha]",
        viewonly=True,
    )

    __tablename__ = "source"
    __table_args__ = (
        db.ForeignKeyConstraint(
            ("repository_id", "revision_sha"),
            ("revision.repository_id", "revision.sha"),
        ),
        db.Index("idx_source_repo_sha", "repository_id", "revision_sha"),
        db.UniqueConstraint("repository_id",
                            "revision_sha",
                            "patch_id",
                            name="unq_source_revision"),
    )
    __repr__ = model_repr("repository_id", "revision_sha", "patch_id")

    def is_commit(self):
        return self.patch_id is None and self.revision_sha

    def generate_diff(self):
        if self.patch:
            return self.patch.diff

        try:
            vcs = self.repository.get_vcs()
        except UnknownRepositoryBackend:
            return None

        try:
            return vcs.export(self.revision_sha)
        except Exception:
            # TODO
            pass
示例#10
0
class Revision(db.Model):
    # XXX(dcramer): the primary_key doesnt include repo_id at the moment, which is wrong, but
    # we need to deal w/ that in a followup change
    repository_id = db.Column(
        GUID, db.ForeignKey("repository.id", ondelete="CASCADE"), primary_key=True
    )
    sha = db.Column(db.String(40), primary_key=True)
    author_id = db.Column(
        GUID, db.ForeignKey("author.id", ondelete="SET NULL"), index=True, nullable=True
    )
    committer_id = db.Column(
        GUID, db.ForeignKey("author.id", ondelete="SET NULL"), index=True, nullable=True
    )
    message = db.Column(db.Text, nullable=True)
    parents = db.Column(ARRAY(db.String(40)), nullable=True)
    # TODO: remove this column, we dont use it and its wrong
    branches = db.Column(ARRAY(db.String(128)), nullable=True)
    date_created = db.Column(
        db.TIMESTAMP(timezone=True),
        default=timezone.now,
        server_default=func.now(),
        nullable=False,
    )
    date_committed = db.Column(
        db.TIMESTAMP(timezone=True),
        default=timezone.now,
        server_default=func.now(),
        nullable=False,
    )

    authors = db.relationship(
        "Author", secondary=revision_author_table, backref="revisions"
    )
    committer = db.relationship("Author", foreign_keys=[committer_id])
    repository = db.relationship("Repository", foreign_keys=[repository_id])

    query_class = RepositoryBoundQuery

    __tablename__ = "revision"
    # XXX(dcramer): the primary_key doesnt include repo_id at the moment, which is wrong, but
    # we need to deal w/ that in a followup change
    __table_args__ = (db.UniqueConstraint("repository_id", "sha", name="unq_revision"),)
    __repr__ = model_repr("repository_id", "sha", "subject")

    @property
    def subject(self):
        return self.message.splitlines()[0]

    def generate_diff(self):
        from zeus.vcs import vcs_client

        try:
            return vcs_client.export(self.repository_id, self.sha)
        except Exception:
            current_app.logger.exception("generate_diff failure")
示例#11
0
class ItemOption(db.Model):
    id = db.Column(GUID, primary_key=True, default=GUID.default_value)
    item_id = db.Column(GUID, nullable=False)
    name = db.Column(db.String(64), nullable=False)
    value = db.Column(db.Text, nullable=False)

    __tablename__ = 'itemoption'
    __table_args__ = (db.UniqueConstraint('item_id',
                                          'name',
                                          name='unq_itemoption_name'), )
    __repr__ = model_repr('item_id', 'name')
示例#12
0
class Project(RepositoryBoundMixin, StandardAttributes, db.Model):
    """
    Represents a single project.
    """
    name = db.Column(db.String(200), nullable=False)

    __tablename__ = 'project'
    __table_args__ = (db.UniqueConstraint('organization_id',
                                          'name',
                                          name='unq_project_name'), )
    __repr__ = model_repr('name')
示例#13
0
class Bundle(RepositoryBoundMixin, StandardAttributes, db.Model):
    job_id = db.Column(GUID,
                       db.ForeignKey('job.id', ondelete='CASCADE'),
                       nullable=False)
    name = db.Column(db.Text, nullable=False)

    job = db.relationship('Job')
    assets = db.relationship('BundleAsset', lazy='subquery')

    __tablename__ = 'bundle'
    __table_args__ = (db.UniqueConstraint('job_id', 'name',
                                          name='unq_bundle'), )
    __repr__ = model_repr('repository_id', 'job_id', 'name')
示例#14
0
class Bundle(RepositoryBoundMixin, StandardAttributes, db.Model):
    job_id = db.Column(GUID,
                       db.ForeignKey("job.id", ondelete="CASCADE"),
                       nullable=False)
    name = db.Column(db.Text, nullable=False)

    job = db.relationship("Job")
    assets = db.relationship("BundleAsset", lazy="subquery")

    __tablename__ = "bundle"
    __table_args__ = (db.UniqueConstraint("job_id", "name",
                                          name="unq_bundle"), )
    __repr__ = model_repr("repository_id", "job_id", "name")
示例#15
0
class Author(OrganizationBoundMixin, db.Model):
    """
    The author of a source. Generally used for things like commit authors.

    This is different than User, which indicates a known authenticatable user.
    """
    id = db.Column(GUID, primary_key=True, default=GUID.default_value)
    name = db.Column(db.String(128), nullable=False)
    email = db.Column(db.String(128), nullable=True)

    __tablename__ = 'author'
    __table_args__ = (db.UniqueConstraint('organization_id', 'email', name='unq_author_email'), )
    __repr__ = model_repr('organization_id', 'name', 'email')
示例#16
0
文件: author.py 项目: robopsi/zeus
class Author(RepositoryBoundMixin, db.Model):
    """
    The author of a source. Generally used for things like commit authors.

    This is different than User, which indicates a known authenticatable user.
    """
    id = db.Column(GUID, primary_key=True, default=GUID.default_value)
    name = db.Column(db.String(128), nullable=False)
    email = db.Column(db.String(128), nullable=True)

    __tablename__ = "author"
    __table_args__ = (db.UniqueConstraint("repository_id",
                                          "email",
                                          name="unq_author_email"), )
    __repr__ = model_repr("repository_id", "name", "email")
示例#17
0
class Source(RepositoryBoundMixin, StandardAttributes, db.Model):
    """
    A source represents the canonical parameters that a build is running against.
    """
    patch_id = db.Column(GUID,
                         db.ForeignKey('patch.id'),
                         unique=True,
                         nullable=True)
    revision_sha = db.Column(db.String(40), nullable=False)
    data = db.Column(JSONEncodedDict, nullable=True)
    author_id = db.Column(GUID, db.ForeignKey('author.id'), index=True)

    author = db.relationship('Author')
    patch = db.relationship('Patch', )
    revision = db.relationship(
        'Revision',
        foreign_keys='[Source.repository_id, Source.revision_sha]',
        viewonly=True)

    __tablename__ = 'source'
    __table_args__ = (
        db.ForeignKeyConstraint(('repository_id', 'revision_sha'),
                                ('revision.repository_id', 'revision.sha')),
        db.Index('idx_source_repo_sha', 'repository_id', 'revision_sha'),
        db.UniqueConstraint(
            'repository_id',
            'revision_sha',
            'patch_id',
            name='unq_source_revision',
        ),
    )
    __repr__ = model_repr('repository_id', 'revision_sha', 'patch_id')

    def is_commit(self):
        return self.patch_id is None and self.revision_sha

    def generate_diff(self):
        if self.patch:
            return self.patch.diff

        vcs = self.repository.get_vcs()
        if vcs:
            try:
                return vcs.export(self.revision_sha)
            except Exception:
                pass

        return None
示例#18
0
class FailureReason(RepositoryBoundMixin, StandardAttributes, db.Model):
    __tablename__ = 'failurereason'
    __table_args__ = (db.UniqueConstraint('job_id',
                                          'reason',
                                          name='unq_failurereason_key'), )

    class Reason(enum.Enum):
        failing_tests = 'failing_tests'
        missing_tests = 'missing_tests'

    job_id = db.Column(GUID,
                       db.ForeignKey('job.id', ondelete="CASCADE"),
                       nullable=False)
    reason = db.Column(StrEnum(Reason), nullable=False)

    job = db.relationship('Job')
示例#19
0
class FailureReason(RepositoryBoundMixin, StandardAttributes, db.Model):
    __tablename__ = "failurereason"
    __table_args__ = (db.UniqueConstraint("job_id",
                                          "reason",
                                          name="unq_failurereason_key"), )

    class Reason(enum.Enum):
        failing_tests = "failing_tests"
        missing_tests = "missing_tests"

    job_id = db.Column(GUID,
                       db.ForeignKey("job.id", ondelete="CASCADE"),
                       nullable=False)
    reason = db.Column(StrEnum(Reason), nullable=False)

    job = db.relationship("Job")
示例#20
0
class FileCoverage(ProjectBoundMixin, db.Model):
    id = db.Column(GUID, nullable=False, primary_key=True, default=GUID.default_value)
    job_id = db.Column(GUID, db.ForeignKey('job.id', ondelete='CASCADE'), nullable=False)
    filename = db.Column(db.String(256), nullable=False, primary_key=True)
    data = db.Column(db.Text, nullable=False)

    lines_covered = db.Column(db.Integer, nullable=False)
    lines_uncovered = db.Column(db.Integer, nullable=False)
    diff_lines_covered = db.Column(db.Integer, nullable=False)
    diff_lines_uncovered = db.Column(db.Integer, nullable=False)

    job = db.relationship('Job', innerjoin=True, uselist=False)

    __tablename__ = 'filecoverage'
    __table_args__ = (db.UniqueConstraint('job_id', 'filename', name='unq_job_filname'), )
    __repr__ = model_repr('job_id', 'filename')
示例#21
0
class Email(StandardAttributes, db.Model):
    """
    An email address associated with a user.
    """
    user_id = db.Column(GUID,
                        db.ForeignKey('user.id', ondelete="CASCADE"),
                        nullable=False,
                        index=True)
    email = db.Column(db.String(128), nullable=False)
    verified = db.Column(db.Boolean, default=False, nullable=False)

    user = db.relationship('User')

    __tablename__ = 'email'
    __table_args__ = (db.UniqueConstraint('user_id',
                                          'email',
                                          name='unq_user_email'), )
    __repr__ = model_repr('user_id', 'email', 'verified')
示例#22
0
class Identity(StandardAttributes, db.Model):
    """
    Identities associated with a user. Primarily used for Single Sign-On.
    """
    user_id = db.Column(
        GUID, db.ForeignKey('user.id', ondelete="CASCADE"), nullable=False, index=True
    )
    external_id = db.Column(db.String(64), unique=True, nullable=False)
    provider = db.Column(db.String(32), nullable=False)
    config = db.Column(JSONEncodedDict, nullable=False)
    scopes = db.Column(ARRAY(db.String(64)), nullable=True)

    user = db.relationship('User')

    __tablename__ = 'identity'
    __table_args__ = (db.UniqueConstraint(
        'user_id', 'provider', name='unq_identity_user'), )
    __repr__ = model_repr('user_id', 'provider', 'external_id')
示例#23
0
class BundleAsset(RepositoryBoundMixin, StandardAttributes, db.Model):
    bundle_id = db.Column(GUID,
                          db.ForeignKey("bundle.id", ondelete="CASCADE"),
                          nullable=False)
    job_id = db.Column(GUID,
                       db.ForeignKey("job.id", ondelete="CASCADE"),
                       nullable=False,
                       index=True)
    name = db.Column(db.Text, nullable=False)
    size = db.Column(db.Integer, nullable=True)

    job = db.relationship("Job")
    bundle = db.relationship("Bundle")

    __tablename__ = "bundle_asset"
    __table_args__ = (db.UniqueConstraint("bundle_id",
                                          "name",
                                          name="unq_bundle_asset"), )
    __repr__ = model_repr("repository_id", "job_id", "bundle_id", "name")
示例#24
0
class TestCase(RepositoryBoundMixin, db.Model):
    """
    A single run of a single test.
    """

    id = db.Column(GUID,
                   nullable=False,
                   primary_key=True,
                   default=GUID.default_value)
    job_id = db.Column(GUID,
                       db.ForeignKey("job.id", ondelete="CASCADE"),
                       nullable=False)
    hash = db.Column(db.String(40), nullable=False)
    name = db.Column(db.Text, nullable=False)
    result = db.Column(Enum(Result), default=Result.unknown, nullable=False)
    # duration, in milliseconds
    duration = db.Column(db.Integer, default=0, nullable=True)
    message = db.deferred(db.Column(db.Text, nullable=True))

    job = db.relationship("Job")

    __tablename__ = "testcase"
    __table_args__ = (db.UniqueConstraint("job_id",
                                          "hash",
                                          name="unq_testcase_hash"), )
    __repr__ = model_repr("repository_id", "job_id", "name", "result")

    @classmethod
    def calculate_sha(self, name):
        assert name
        return sha1(name.encode("utf-8")).hexdigest()

    @property
    def sep(self):
        name = self.name
        # handle the case where it might begin with some special character
        if not re.match(r"^[a-zA-Z0-9]", name):
            return "/"

        elif "/" in name:
            return "/"

        return "."
示例#25
0
class TestCase(ProjectBoundMixin, db.Model):
    """
    A single run of a single test.
    """
    id = db.Column(GUID,
                   nullable=False,
                   primary_key=True,
                   default=GUID.default_value)
    job_id = db.Column(GUID,
                       db.ForeignKey('job.id', ondelete="CASCADE"),
                       nullable=False)
    hash = db.Column(db.String(40), nullable=False)
    name = db.Column(db.Text, nullable=False)
    result = db.Column(Enum(Result), default=Result.unknown, nullable=False)
    # duration, in milliseconds
    duration = db.Column(db.Integer, default=0, nullable=True)
    message = db.deferred(db.Column(db.Text, nullable=True))

    job = db.relationship('Job')

    __tablename__ = 'testcase'
    __table_args__ = (db.UniqueConstraint('job_id',
                                          'hash',
                                          name='unq_testcase_hash'), )
    __repr__ = model_repr('job_id', 'name', 'result')

    @classmethod
    def calculate_sha(self, name):
        assert name
        return sha1(name.encode('utf-8')).hexdigest()

    @property
    def sep(self):
        name = self.name
        # handle the case where it might begin with some special character
        if not re.match(r'^[a-zA-Z0-9]', name):
            return '/'
        elif '/' in name:
            return '/'
        return '.'
示例#26
0
class Revision(RepositoryBoundMixin, db.Model):
    sha = db.Column(db.String(40), primary_key=True)
    author_id = db.Column(GUID,
                          db.ForeignKey("author.id"),
                          index=True,
                          nullable=True)
    committer_id = db.Column(GUID,
                             db.ForeignKey("author.id"),
                             index=True,
                             nullable=True)
    message = db.Column(db.Text, nullable=True)
    parents = db.Column(ARRAY(db.String(40)), nullable=True)
    branches = db.Column(ARRAY(db.String(128)), nullable=True)
    date_created = db.Column(
        db.TIMESTAMP(timezone=True),
        default=timezone.now,
        server_default=func.now(),
        nullable=False,
    )
    date_committed = db.Column(
        db.TIMESTAMP(timezone=True),
        default=timezone.now,
        server_default=func.now(),
        nullable=False,
    )

    author = db.relationship("Author", foreign_keys=[author_id])
    committer = db.relationship("Author", foreign_keys=[committer_id])

    __tablename__ = "revision"
    __table_args__ = (db.UniqueConstraint("repository_id",
                                          "sha",
                                          name="unq_revision"), )
    __repr__ = model_repr("repository_id", "sha", "subject")

    @property
    def subject(self):
        return self.message.splitlines()[0]
示例#27
0
class FileCoverage(RepositoryBoundMixin, db.Model):
    id = db.Column(GUID,
                   nullable=False,
                   primary_key=True,
                   default=GUID.default_value)
    build_id = db.Column(GUID,
                         db.ForeignKey("build.id", ondelete="CASCADE"),
                         nullable=False,
                         index=True)
    filename = db.Column(db.String(256), nullable=False, primary_key=True)
    data = db.Column(db.Text, nullable=False)

    lines_covered = db.Column(db.Integer, nullable=False)
    lines_uncovered = db.Column(db.Integer, nullable=False)
    diff_lines_covered = db.Column(db.Integer, nullable=False)
    diff_lines_uncovered = db.Column(db.Integer, nullable=False)

    build = db.relationship("Build", innerjoin=True, uselist=False)

    __tablename__ = "filecoverage"
    __table_args__ = (db.UniqueConstraint("build_id",
                                          "filename",
                                          name="unq_coverage_filname"), )
    __repr__ = model_repr("repository_id", "build_id", "filename")
示例#28
0
class Repository(StandardAttributes, db.Model):
    """
    Represents a single repository.
    """
    # TODO(dcramer): we dont want to be coupled to GitHub (the concept of orgs)
    # but right now we simply dont care, and this can be refactored later (URLs
    # are tricky)
    owner_name = db.Column(db.String(200), nullable=False)
    name = db.Column(db.String(200), nullable=False)
    url = db.Column(db.String(200), nullable=False)
    backend = db.Column(Enum(RepositoryBackend),
                        default=RepositoryBackend.unknown,
                        nullable=False)
    status = db.Column(Enum(RepositoryStatus),
                       default=RepositoryStatus.inactive,
                       nullable=False)
    provider = db.Column(StrEnum(RepositoryProvider), nullable=False)
    external_id = db.Column(db.String(64))
    data = db.Column(JSONEncodedDict, nullable=True)
    last_update = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    last_update_attempt = db.Column(db.TIMESTAMP(timezone=True), nullable=True)

    options = db.relationship(
        'ItemOption',
        foreign_keys='[ItemOption.item_id]',
        primaryjoin='ItemOption.item_id == Repository.id',
        viewonly=True,
        uselist=True)

    query_class = RepositoryAccessBoundQuery

    __tablename__ = 'repository'
    __table_args__ = (
        db.UniqueConstraint('provider',
                            'external_id',
                            name='unq_repo_external_id'),
        db.UniqueConstraint('provider',
                            'owner_name',
                            'name',
                            name='unq_repo_name'),
    )
    __repr__ = model_repr('name', 'url', 'provider')

    def get_vcs(self):
        from zeus.models import ItemOption
        from zeus.vcs.git import GitVcs

        options = dict(
            db.session.query(ItemOption.name, ItemOption.value).filter(
                ItemOption.item_id == self.id,
                ItemOption.name.in_([
                    'auth.username',
                ])))

        kwargs = {
            'path': os.path.join(current_app.config['REPO_ROOT'], self.id.hex),
            'id': self.id.hex,
            'url': self.url,
            'username': options.get('auth.username'),
        }

        if self.backend == RepositoryBackend.git:
            return GitVcs(**kwargs)
        else:
            raise NotImplementedError('Invalid backend: {}'.format(
                self.backend))

    def get_full_name(self):
        return '{}/{}/{}'.format(self.provider, self.owner_name, self.name)
示例#29
0
class Build(RepositoryBoundMixin, StandardAttributes, db.Model):
    """
    A single build.

    Each Build contains many Jobs.
    """

    ref = db.Column(db.String, nullable=True)
    revision_sha = db.Column(db.String(40), nullable=True)

    number = db.Column(db.Integer, nullable=False)
    label = db.Column(db.String, nullable=True)
    status = db.Column(Enum(Status), nullable=False, default=Status.unknown)
    result = db.Column(Enum(Result), nullable=False, default=Result.unknown)
    date_created = db.Column(
        db.TIMESTAMP(timezone=True),
        nullable=False,
        default=timezone.now,
        server_default=func.now(),
        index=True,
    )
    date_started = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    date_finished = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    data = db.Column(JSONEncodedDict, nullable=True)
    provider = db.Column(db.String, nullable=True)
    external_id = db.Column(db.String(64), nullable=True)
    hook_id = db.Column(GUID,
                        db.ForeignKey("hook.id", ondelete="CASCADE"),
                        nullable=True,
                        index=True)
    url = db.Column(db.String, nullable=True)
    author_id = db.Column(
        GUID,
        db.ForeignKey("author.id", ondelete="SET NULL"),
        index=False,
        nullable=True,
    )

    authors = db.relationship("Author",
                              secondary=build_author_table,
                              backref="builds")
    revision = db.relationship(
        "Revision",
        foreign_keys="[Build.repository_id, Build.revision_sha]",
        viewonly=True,
    )
    hook = db.relationship("Hook")
    stats = db.relationship(
        "ItemStat",
        foreign_keys="[ItemStat.item_id]",
        primaryjoin="ItemStat.item_id == Build.id",
        viewonly=True,
        uselist=True,
    )
    failures = db.relationship(
        "FailureReason",
        foreign_keys="[FailureReason.build_id]",
        primaryjoin="FailureReason.build_id == Build.id",
        viewonly=True,
        uselist=True,
    )

    __tablename__ = "build"
    __table_args__ = (
        db.UniqueConstraint("repository_id", "number",
                            name="unq_build_number"),
        db.UniqueConstraint("repository_id",
                            "provider",
                            "external_id",
                            name="unq_build_provider"),
        db.ForeignKeyConstraint(
            ("repository_id", "revision_sha"),
            ("revision.repository_id", "revision.sha"),
        ),
        db.Index("idx_build_repo_sha", "repository_id", "revision_sha"),
        db.Index("idx_build_author_date", "author_id", "date_created"),
        db.Index("idx_build_outcomes", "repository_id", "status", "result",
                 "date_created"),
    )
    __repr__ = model_repr("number", "status", "result")
示例#30
0
class Repository(StandardAttributes, db.Model):
    """
    Represents a single repository.
    """
    # TODO(dcramer): we dont want to be coupled to GitHub (the concept of orgs)
    # but right now we simply dont care, and this can be refactored later (URLs
    # are tricky)
    owner_name = db.Column(db.String(200), nullable=False)
    name = db.Column(db.String(200), nullable=False)
    url = db.Column(db.String(200), nullable=False)
    backend = db.Column(
        Enum(RepositoryBackend), default=RepositoryBackend.unknown, nullable=False
    )
    status = db.Column(
        Enum(RepositoryStatus), default=RepositoryStatus.inactive, nullable=False
    )
    provider = db.Column(StrEnum(RepositoryProvider), nullable=False)
    external_id = db.Column(db.String(64))
    data = db.Column(JSONEncodedDict, nullable=True)
    public = db.Column(
        db.Boolean, default=False, server_default="false", nullable=False, index=True
    )
    last_update = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    last_update_attempt = db.Column(db.TIMESTAMP(timezone=True), nullable=True)

    options = db.relationship(
        "ItemOption",
        foreign_keys="[ItemOption.item_id]",
        primaryjoin="ItemOption.item_id == Repository.id",
        viewonly=True,
        uselist=True,
    )

    query_class = RepositoryAccessBoundQuery

    __tablename__ = "repository"
    __table_args__ = (
        db.UniqueConstraint("provider", "external_id", name="unq_repo_external_id"),
        db.UniqueConstraint("provider", "owner_name", "name", name="unq_repo_name"),
    )
    __repr__ = model_repr("name", "url", "provider")

    def get_vcs(self):
        from zeus.models import ItemOption
        from zeus.vcs.git import GitVcs

        options = dict(
            db.session.query(ItemOption.name, ItemOption.value).filter(
                ItemOption.item_id == self.id, ItemOption.name.in_(["auth.username"])
            )
        )

        kwargs = {
            "path": os.path.join(current_app.config["REPO_ROOT"], self.id.hex),
            "id": self.id.hex,
            "url": self.url,
            "username": options.get("auth.username"),
        }

        if self.backend == RepositoryBackend.git:
            return GitVcs(**kwargs)

        else:
            raise NotImplementedError("Invalid backend: {}".format(self.backend))

    def get_full_name(self):
        return "{}/{}/{}".format(self.provider, self.owner_name, self.name)