Merge "sql: add buildset.branch column"
diff --git a/tests/unit/test_connection.py b/tests/unit/test_connection.py
index c45da94..bacdf8f 100644
--- a/tests/unit/test_connection.py
+++ b/tests/unit/test_connection.py
@@ -74,7 +74,7 @@
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 @@
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'])
diff --git a/zuul/driver/sql/alembic/versions/defa75d297bf_add_branch_column.py b/zuul/driver/sql/alembic/versions/defa75d297bf_add_branch_column.py
new file mode 100644
index 0000000..714975e
--- /dev/null
+++ b/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")
diff --git a/zuul/driver/sql/sqlconnection.py b/zuul/driver/sql/sqlconnection.py
index e931301..ab387a6 100644
--- a/zuul/driver/sql/sqlconnection.py
+++ b/zuul/driver/sql/sqlconnection.py
@@ -96,6 +96,7 @@
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 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 @@
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 @@
'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",
diff --git a/zuul/driver/sql/sqlreporter.py b/zuul/driver/sql/sqlreporter.py
index f9537ac..9932ff0 100644
--- a/zuul/driver/sql/sqlreporter.py
+++ b/zuul/driver/sql/sqlreporter.py
@@ -52,6 +52,7 @@
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 = []