class SignoffStep(db.Model): """ Recording signoff steps as distinct entities """ __tablename__ = 'shipit_signoff_steps' uid = sa.Column(sa.String(80), primary_key=True) # uid = sa.Column(sa.String(80), nullable=False) state = sa.Column(sa.Enum(SigningStatus), default=SigningStatus.starting) status_message = sa.Column(sa.String(200), nullable=True) created = sa.Column(sa.DateTime, default=datetime.datetime.utcnow) completed = sa.Column(sa.DateTime, nullable=True) policy = sa.Column(sa.Binary()) signatures = db.relationship('Signature') @property def policy_data(self): if not self.policy: return None return pickle.loads(self.policy) def delete(self): """ Delete step, and associated signatures """ signatures = Signature.query.filter_by(step_uid=self.uid).all() for signature in signatures: signature.delete() db.session.delete(self) db.session.commit()
class PatchStatus(db.Model): ''' Patch merge status at a specific time ''' __tablename__ = 'uplift_backend_patch_status' __table_args__ = ( sa.UniqueConstraint('bug_id', 'revision', 'revision_parent', 'branch', name='uniq_patch_status'), # noqa sa.UniqueConstraint('bug_id', 'group', 'branch', 'revision', name='uniq_patch_status_group') # noqa ) id = sa.Column(sa.Integer, primary_key=True) group = sa.Column(sa.Integer, default=1, nullable=False) bug_id = sa.Column(sa.Integer, sa.ForeignKey('uplift_backend_bug.id'), nullable=False) revision = sa.Column(sa.String(50), nullable=False) revision_parent = sa.Column(sa.String(50), nullable=False) branch = sa.Column(sa.String(50), nullable=False) message = sa.Column(sa.Text()) created = sa.Column(sa.DateTime, default=datetime.datetime.utcnow, nullable=False) status = sa.Column(sa.Enum(MergeStatus), default=MergeStatus.merged) bug = db.relationship(BugResult, backref='patch_status')
class BugContributor(db.Model): ''' M2M link between contributor & bug ''' __tablename__ = 'uplift_backend_contributor_bugs' __table_args__ = ( sa.UniqueConstraint('contributor_id', 'bug_id', name='uniq_contrib_bug'), # noqa ) id = sa.Column(sa.Integer, primary_key=True) contributor_id = sa.Column( sa.Integer, sa.ForeignKey('uplift_backend_contributor.id')) # noqa bug_id = sa.Column(sa.Integer, sa.ForeignKey('uplift_backend_bug.id')) # noqa roles = sa.Column(sa.String(250)) bug = db.relationship(BugResult, backref='contributors') contributor = db.relationship(Contributor, backref='bugs')
class BugAnalysis(db.Model): ''' A template to build some cached analysis by listing several bugs from Bugzilla, with their analysus ''' __tablename__ = 'uplift_backend_analysis' id = sa.Column(sa.Integer, primary_key=True) name = sa.Column(sa.String(80), nullable=False) version = sa.Column(sa.Integer, nullable=False) created = sa.Column(sa.DateTime, default=datetime.datetime.utcnow) bugs = db.relationship('BugResult', secondary=bugs, backref=db.backref('analysis', lazy='dynamic'), order_by='BugResult.bugzilla_id') # noqa def __init__(self, name, version=1): self.name = name self.version = version def __repr__(self): return 'Analysis {} {}'.format(self.name, self.version) @staticmethod def with_bugs(): ''' List all analysis with bugs count Uses a single sql request ''' return \ db.session \ .query( BugAnalysis, sa.func.count(bugs.c.bug_id.distinct()) ) \ .join(bugs, isouter=True) \ .group_by(BugAnalysis) def build_parameters(self): ''' Build parameters for uplift bug search ''' name = self.name.lower() if name.startswith('esr'): # Esr releases name += str(self.version) approval = 'approval-{}'.format(name) v3 = 'approval-mozilla-{}?'.format(name) else: # Normal releases approval = 'approval-mozilla-{}'.format(name) v3 = 'approval-mozilla-{}?'.format(name) parameters = { # Common parameters 'f0': 'OP', 'f1': 'OP', 'f10': 'requestees.login_name', 'f11': 'CP', 'f12': 'CP', 'f2': 'flagtypes.name', 'f3': 'flagtypes.name', 'f4': 'flagtypes.name', 'f5': 'flagtypes.name', 'f6': 'CP', 'f7': 'CP', 'f8': 'OP', 'f9': 'OP', 'j1': 'OR', 'j9': 'OR', 'o10': 'substring', 'o2': 'substring', 'o3': 'substring', 'o4': 'substring', 'o5': 'substring', 'query_format': 'advanced', # Version specific parameters 'known_name': approval, 'query_based_on': approval, 'v3': v3, } return urllib.parse.urlencode(parameters)
class BugAnalysis(db.Model): """ A template to build some cached analysis by listing several bugs from Bugzilla, with their analysus """ __tablename__ = 'shipit_uplift_analysis' id = sa.Column(sa.Integer, primary_key=True) name = sa.Column(sa.String(80), nullable=False) version = sa.Column(sa.Integer, nullable=False) created = sa.Column(sa.DateTime, default=datetime.datetime.utcnow) bugs = db.relationship('BugResult', secondary=bugs, backref=db.backref('analysis', lazy='dynamic'), order_by='BugResult.bugzilla_id') # noqa def __init__(self, name): self.name = name def __repr__(self): return 'Analysis {} {}'.format(self.name, self.version) @staticmethod def with_bugs(): """ List all analysis with bugs count Uses a single sql request """ return \ db.session \ .query( BugAnalysis, sa.func.count(bugs.c.bug_id.distinct()) ) \ .join(bugs, isouter=True) \ .group_by(BugAnalysis) def build_parameters(self): """ Build parameters for uplift bug search """ name = self.name.lower() name += name == 'esr' and str(self.version) or '' approval = 'approval-mozilla-{}'.format(name) columns = ( 'product', 'component', 'last_visit_ts', 'assigned_to', 'bug_status', 'resolution', 'short_desc', 'changeddate', ) parameters = { # Common parameters 'columnlist': ','.join(columns), 'f0': 'OP', 'f1': 'OP', 'f10': 'requestees.login_name', 'f11': 'CP', 'f12': 'CP', 'f2': 'flagtypes.name', 'f3': 'flagtypes.name', 'f4': 'flagtypes.name', 'f5': 'flagtypes.name', 'f6': 'CP', 'f7': 'CP', 'f8': 'OP', 'f9': 'OP', 'j1': 'OR', 'j9': 'OR', 'o10': 'substring', 'o2': 'substring', 'o3': 'substring', 'o4': 'substring', 'o5': 'substring', 'query_format': 'advanced', # Version specific parameters 'known_name': approval, 'query_based_on': approval, 'v3': approval + '?', } return urllib.parse.urlencode(parameters)