public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/tinderbox-cluster:master commit in: buildbot_gentoo_ci/db/, sql/, buildbot_gentoo_ci/steps/
@ 2023-06-26 21:39 Magnus Granberg
  0 siblings, 0 replies; only message in thread
From: Magnus Granberg @ 2023-06-26 21:39 UTC (permalink / raw
  To: gentoo-commits

commit:     2639fe0cd81fc82c4f9717daf756013cea6a86ca
Author:     Magnus Granberg <zorry <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 26 21:38:57 2023 +0000
Commit:     Magnus Granberg <zorry <AT> gentoo <DOT> org>
CommitDate: Mon Jun 26 21:38:57 2023 +0000
URL:        https://gitweb.gentoo.org/proj/tinderbox-cluster.git/commit/?id=2639fe0c

Add bug id to builds data in db

Signed-off-by: Magnus Granberg <zorry <AT> gentoo.org>

 buildbot_gentoo_ci/db/builds.py  | 56 +++++++++++++++++++++++++++++++++++++---
 buildbot_gentoo_ci/db/model.py   |  1 +
 buildbot_gentoo_ci/steps/logs.py |  7 +++++
 sql/gentoo_ci_schema.sql         |  1 +
 4 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/buildbot_gentoo_ci/db/builds.py b/buildbot_gentoo_ci/db/builds.py
index 1cf2439..21adcc0 100644
--- a/buildbot_gentoo_ci/db/builds.py
+++ b/buildbot_gentoo_ci/db/builds.py
@@ -15,7 +15,7 @@
 # Copyright Buildbot Team Members
 # Origins: buildbot.db.*
 # Modifyed by Gentoo Authors.
-# Copyright 2021 Gentoo Authors
+# Copyright 2023 Gentoo Authors
 
 import uuid
 import sqlalchemy as sa
@@ -44,7 +44,9 @@ class BuildsConnectorComponent(base.DBConnectorComponent):
                                          requested=project_build_data['requested'],
                                          created_at=created_at,
                                          buildbot_build_id=0,
-                                         build_id=new_number))
+                                         build_id=new_number,
+                                         bug_id=0
+                                         ))
             except (sa.exc.IntegrityError, sa.exc.ProgrammingError):
                 id = None
                 new_number = None
@@ -57,7 +59,6 @@ class BuildsConnectorComponent(base.DBConnectorComponent):
     def setStatusBuilds(self, id, status):
         updated_at = int(self.master.reactor.seconds())
         def thd(conn, no_recurse=False):
-        
                 tbl = self.db.model.projects_builds
                 q = tbl.update()
                 q = q.where(tbl.c.id == id)
@@ -69,10 +70,57 @@ class BuildsConnectorComponent(base.DBConnectorComponent):
     def setBuildbotBuildIdBuilds(self, id, buildbot_build_id):
         updated_at = int(self.master.reactor.seconds())
         def thd(conn, no_recurse=False):
-        
                 tbl = self.db.model.projects_builds
                 q = tbl.update()
                 q = q.where(tbl.c.id == id)
                 conn.execute(q, updated_at=updated_at,
                                 buildbot_build_id=buildbot_build_id)
         yield self.db.pool.do(thd)
+
+    @defer.inlineCallbacks
+    def setBugIdBuilds(self, id, bug_id):
+        updated_at = int(self.master.reactor.seconds())
+        def thd(conn, no_recurse=False):
+                tbl = self.db.model.projects_builds
+                q = tbl.update()
+                q = q.where(tbl.c.id == id)
+                conn.execute(q, updated_at=updated_at, bug_id=bug_id)
+        yield self.db.pool.do(thd)
+
+    @defer.inlineCallbacks
+    def getBuildsByVersionUuid(self, uuid):
+        def thd(conn):
+            tbl = self.db.model.projects_builds
+            q = tbl.select()
+            q = q.where(tbl.c.version_uuid == uuid)
+            res = conn.execute(q)
+            row = res.fetchone()
+            return [self._row2dict(conn, row)
+                for row in conn.execute(q).fetchall()]
+        res = yield self.db.pool.do(thd)
+        return res
+
+    @defer.inlineCallbacks
+    def removeBuild(self, id):
+        def thd(conn, no_recurse=False):
+                tbl = self.db.model.projects_builds
+                q = tbl.delete()
+                q = q.where(tbl.c.id == id)
+                conn.execute(q)
+        yield self.db.pool.do(thd)
+
+    def _row2dict(self, conn, row):
+        return dict(
+            id=row.id,
+            build_id=row.build_id,
+            project_uuid=row.project_uuid,
+            version_uuid=row.version_uuid,
+            buildbot_build_id=row.buildbot_build_id,
+            bug_id=row.bug_id,
+            status=row.status,
+            requested=row.requested,
+            created_at=row.created_at,
+            updated_at=row.updated_at,
+            deleted=row.deleted,
+            deleted_at=row.deleted_at
+            )

diff --git a/buildbot_gentoo_ci/db/model.py b/buildbot_gentoo_ci/db/model.py
index b80281e..3ae4f92 100644
--- a/buildbot_gentoo_ci/db/model.py
+++ b/buildbot_gentoo_ci/db/model.py
@@ -243,6 +243,7 @@ class Model(base.DBConnectorComponent):
                   sa.ForeignKey('versions.uuid', ondelete='CASCADE'),
                   nullable=False),
         sa.Column('buildbot_build_id', sa.Integer),
+        sa.Column('bug_id', sa.Integer, nullable=False, default=0),
         sa.Column('status', sa.Enum('failed','completed','in-progress','waiting', 'warning'), nullable=False),
         sa.Column('requested', sa.Boolean, default=False),
         sa.Column('created_at', sa.Integer, nullable=True),

diff --git a/buildbot_gentoo_ci/steps/logs.py b/buildbot_gentoo_ci/steps/logs.py
index ee11166..47112e0 100644
--- a/buildbot_gentoo_ci/steps/logs.py
+++ b/buildbot_gentoo_ci/steps/logs.py
@@ -529,6 +529,13 @@ class setBuildStatus(BuildStep):
     def run(self):
         self.gentooci = self.master.namedServices['services'].namedServices['gentooci']
         project_build_data = self.getProperty('project_build_data')
+        bugid = 0
+        if self.getProperty('bgo'):
+            bugid = self.getProperty('bgo')['id']
+        yield self.gentooci.db.builds.setBugIdBuilds(
+                                                    project_build_data['id'],
+                                                    bugid
+                                                    )
         yield self.gentooci.db.builds.setStatusBuilds(
                                                     project_build_data['id'],
                                                     self.getProperty('status')

diff --git a/sql/gentoo_ci_schema.sql b/sql/gentoo_ci_schema.sql
index b166150..ee89db8 100644
--- a/sql/gentoo_ci_schema.sql
+++ b/sql/gentoo_ci_schema.sql
@@ -512,6 +512,7 @@ CREATE TABLE public.projects_builds (
     version_uuid character varying(36),
     build_id integer NOT NULL,
     buildbot_build_id integer DEFAULT 0,
+    bug_id integer DEFAULT 0,
     status public.projects_builds_status,
     requested boolean,
     created_at integer,


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-26 21:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-26 21:39 [gentoo-commits] proj/tinderbox-cluster:master commit in: buildbot_gentoo_ci/db/, sql/, buildbot_gentoo_ci/steps/ Magnus Granberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox