sql: add buildset.branch column

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

Change-Id: Ia1e234f556766cc945dec84759c6a31f244084f6
This commit is contained in:
Tristan Cacqueray
2018-02-21 01:54:14 +00:00
parent ec1f54deb3
commit cb8f7e25f0
4 changed files with 46 additions and 3 deletions

View File

@@ -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")

View File

@@ -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",

View File

@@ -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 = []