Browse Source

sql: add buildset.branch column

This change adds the build's branch information to the database.

Change-Id: Ia1e234f556766cc945dec84759c6a31f244084f6
changes/68/546468/2
Tristan Cacqueray 4 years ago
parent
commit
cb8f7e25f0
  1. 3
      tests/unit/test_connection.py
  2. 39
      zuul/driver/sql/alembic/versions/defa75d297bf_add_branch_column.py
  3. 6
      zuul/driver/sql/sqlconnection.py
  4. 1
      zuul/driver/sql/sqlreporter.py

3
tests/unit/test_connection.py

@ -74,7 +74,7 @@ class TestSQLConnection(ZuulDBTestCase):
buildset_table = table_prefix + 'zuul_buildset'
build_table = table_prefix + 'zuul_build'
self.assertEqual(13, len(insp.get_columns(buildset_table)))
self.assertEqual(14, len(insp.get_columns(buildset_table)))
self.assertEqual(10, len(insp.get_columns(build_table)))
def test_sql_results(self):
@ -139,6 +139,7 @@ class TestSQLConnection(ZuulDBTestCase):
uuid=buildset0_builds[0]['uuid']),
buildset0_builds[0]['log_url'])
self.assertEqual('check', buildset1['pipeline'])
self.assertEqual('master', buildset1['branch'])
self.assertEqual('org/project', buildset1['project'])
self.assertEqual(2, buildset1['change'])
self.assertEqual('1', buildset1['patchset'])

39
zuul/driver/sql/alembic/versions/defa75d297bf_add_branch_column.py

@ -0,0 +1,39 @@
# Copyright 2018 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Add branch column
Revision ID: defa75d297bf
Revises: 19d3a3ebfe1d
Create Date: 2018-02-21 01:52:23.781875
"""
# revision identifiers, used by Alembic.
revision = 'defa75d297bf'
down_revision = '19d3a3ebfe1d'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade(table_prefix=''):
op.add_column(
table_prefix + 'zuul_buildset', sa.Column('branch', sa.String(255)))
def downgrade():
raise Exception("Downgrades not supported")

6
zuul/driver/sql/sqlconnection.py

@ -96,6 +96,7 @@ class SQLConnection(BaseConnection):
sa.Column('zuul_ref', sa.String(255)),
sa.Column('pipeline', sa.String(255)),
sa.Column('project', sa.String(255)),
sa.Column('branch', sa.String(255)),
sa.Column('change', sa.Integer, nullable=True),
sa.Column('patchset', sa.String(255), nullable=True),
sa.Column('ref', sa.String(255)),
@ -156,7 +157,7 @@ class SQLConnection(BaseConnection):
class SqlWebHandler(BaseWebHandler):
log = logging.getLogger("zuul.web.SqlHandler")
filters = ("project", "pipeline", "change", "patchset", "ref",
filters = ("project", "pipeline", "change", "branch", "patchset", "ref",
"result", "uuid", "job_name", "voting", "node_name", "newrev")
def __init__(self, connection, zuul_web, method, path):
@ -168,6 +169,7 @@ class SqlWebHandler(BaseWebHandler):
buildset = self.connection.zuul_buildset_table
query = select([
buildset.c.project,
buildset.c.branch,
buildset.c.pipeline,
buildset.c.change,
buildset.c.patchset,
@ -222,7 +224,7 @@ class SqlWebHandler(BaseWebHandler):
'skip': 0,
}
for k, v in urllib.parse.parse_qsl(request.rel_url.query_string):
if k in ("tenant", "project", "pipeline", "change",
if k in ("tenant", "project", "pipeline", "change", "branch",
"patchset", "ref", "newrev"):
args['buildset_filters'].setdefault(k, []).append(v)
elif k in ("uuid", "job_name", "voting", "node_name",

1
zuul/driver/sql/sqlreporter.py

@ -52,6 +52,7 @@ class SQLReporter(BaseReporter):
message=self._formatItemReport(
item, with_jobs=False),
tenant=item.pipeline.layout.tenant.name,
branch=item.change.branch,
)
buildset_ins_result = conn.execute(buildset_ins)
build_inserts = []

Loading…
Cancel
Save