summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2019-11-04 19:58:27 +0000
committerGerrit Code Review <review@openstack.org>2019-11-04 19:58:27 +0000
commit57e0ab29425866f4e03b31d7d6df7b91ce2c5490 (patch)
tree386291162bc7aaf056771f4198aa8e6aab8bd851
parenta830f19e2a5ef4e08517e08c0293580a71ad2eb3 (diff)
parent35d4da29d38b1f6326dcbb7236e9658db5d81bbc (diff)
downloadpython-jenkins-job-builder-57e0ab29425866f4e03b31d7d6df7b91ce2c5490.tar.gz
python-jenkins-job-builder-57e0ab29425866f4e03b31d7d6df7b91ce2c5490.tar.xz
python-jenkins-job-builder-57e0ab29425866f4e03b31d7d6df7b91ce2c5490.zip
Merge "Support sectioned views"
-rw-r--r--jenkins_jobs/modules/view_list.py46
-rw-r--r--jenkins_jobs/modules/view_sectioned.py102
-rw-r--r--setup.cfg1
-rw-r--r--tests/base.py3
-rw-r--r--tests/views/fixtures/view_sectioned.xml34
-rw-r--r--tests/views/fixtures/view_sectioned.yaml14
-rw-r--r--tests/views/test_views.py7
7 files changed, 192 insertions, 15 deletions
diff --git a/jenkins_jobs/modules/view_list.py b/jenkins_jobs/modules/view_list.py
index 2931cc4b..8ad7658c 100644
--- a/jenkins_jobs/modules/view_list.py
+++ b/jenkins_jobs/modules/view_list.py
@@ -310,18 +310,27 @@ DEFAULT_COLUMNS = [
class List(jenkins_jobs.modules.base.Base):
sequence = 0
- def root_xml(self, data):
- root = XML.Element("hudson.model.ListView")
-
- mapping = [
- ("name", "name", None),
- ("description", "description", ""),
- ("filter-executors", "filterExecutors", False),
- ("filter-queue", "filterQueue", False),
- ]
+ def root_xml(self, data, sectioned=False):
+ name = "hudson.model.ListView"
+ if sectioned:
+ name = "hudson.plugins.sectioned__view.ListViewSection"
+ root = XML.Element(name)
+
+ mapping = [("name", "name", None)]
+ if not sectioned:
+ mapping.extend(
+ [
+ ("description", "description", ""),
+ ("filter-executors", "filterExecutors", False),
+ ("filter-queue", "filterQueue", False),
+ ]
+ )
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
- XML.SubElement(root, "properties", {"class": "hudson.model.View$PropertyList"})
+ if not sectioned:
+ XML.SubElement(
+ root, "properties", {"class": "hudson.model.View$PropertyList"}
+ )
jn_xml = XML.SubElement(root, "jobNames")
jobnames = data.get("job-name", None)
@@ -341,6 +350,13 @@ class List(jenkins_jobs.modules.base.Base):
filter = getattr(view_jobfilters, jobfilter.replace("-", "_"))
filter(job_filter_xml, jobfilters.get(jobfilter))
+ if sectioned:
+ mapping = [
+ ("width", "width", "FULL", ["FULL", "HALF", "THIRD", "TWO_THIRDS"]),
+ ("alignment", "alignment", "CENTER", ["CENTER", "LEFT", "RIGHT"]),
+ ]
+ helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
+
c_xml = XML.SubElement(root, "columns")
columns = data.get("columns", DEFAULT_COLUMNS)
@@ -369,11 +385,11 @@ class List(jenkins_jobs.modules.base.Base):
x.append(XML.fromstring(tag))
else:
XML.SubElement(c_xml, COLUMN_DICT[column])
- mapping = [
- ("regex", "includeRegex", None),
- ("recurse", "recurse", False),
- ("status-filter", "statusFilter", None),
- ]
+ mapping = [("regex", "includeRegex", None)]
+ if not sectioned:
+ mapping.extend(
+ [("recurse", "recurse", False), ("status-filter", "statusFilter", None)]
+ )
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=False)
return root
diff --git a/jenkins_jobs/modules/view_sectioned.py b/jenkins_jobs/modules/view_sectioned.py
new file mode 100644
index 00000000..50a0dec1
--- /dev/null
+++ b/jenkins_jobs/modules/view_sectioned.py
@@ -0,0 +1,102 @@
+# Copyright 2019 Openstack Foundation
+
+# 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.
+
+"""
+The view sectioned module handles creating Jenkins Sectioned views.
+
+To create a sectioned view specify ``sectioned`` in the ``view-type`` attribute
+to the :ref:`view_sectioned` definition.
+
+:View Parameters:
+ * **name** (`str`): The name of the view.
+ * **view-type** (`str`): The type of view.
+ * **description** (`str`): A description of the view. (default '')
+ * **filter-executors** (`bool`): Show only executors that can
+ execute the included views. (default false)
+ * **filter-queue** (`bool`): Show only included jobs in builder
+ queue. (default false)
+ * **sections** (`list`): The views to show in sections.
+
+Example:
+
+ .. literalinclude::
+ /../../tests/views/fixtures/view_sectioned.yaml
+
+"""
+
+import xml.etree.ElementTree as XML
+import jenkins_jobs.modules.base
+import jenkins_jobs.modules.helpers as helpers
+from jenkins_jobs.modules import view_list
+
+
+class Sectioned(jenkins_jobs.modules.base.Base):
+ def root_xml(self, data):
+ root = XML.Element("hudson.plugins.sectioned__view.SectionedView")
+
+ mapping = [
+ ("name", "name", None),
+ ("description", "description", ""),
+ ("filter-executors", "filterExecutors", False),
+ ("filter-queue", "filterQueue", False),
+ ]
+ helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
+
+ XML.SubElement(root, "properties", {"class": "hudson.model.View$PropertyList"})
+
+ s_xml = XML.SubElement(root, "sections")
+ sections = data.get("sections", [])
+
+ for section in sections:
+ if "view-type" not in section:
+ raise KeyError("This sectioned view is missing a view-type.", section)
+ if section["view-type"] == "list":
+ project = view_list.List(self.registry)
+ elif section["view-type"] == "text":
+ project = SectionedText(self.registry)
+ else:
+ raise ValueError(
+ "Nested view-type %s is not known. Supported types: list, text."
+ % section["view-type"]
+ )
+ xml_project = project.root_xml(section, sectioned=True)
+ s_xml.append(xml_project)
+
+ return root
+
+
+class SectionedText(jenkins_jobs.modules.base.Base):
+ def root_xml(self, data, sectioned=False):
+ assert sectioned
+
+ root = XML.Element("hudson.plugins.sectioned__view.TextSection")
+
+ # these are in the XML and look like from view_list,
+ # but the UI has no controls for them
+ jn_xml = XML.SubElement(root, "jobNames")
+ XML.SubElement(
+ jn_xml, "comparator", {"class": "hudson.util.CaseInsensitiveComparator"}
+ )
+ XML.SubElement(root, "jobFilters")
+
+ mapping = [
+ ("name", "name", ""),
+ ("width", "width", "FULL", ["FULL", "HALF", "THIRD", "TWO_THIRDS"]),
+ ("alignment", "alignment", "CENTER", ["CENTER", "LEFT", "RIGHT"]),
+ ("text", "text", None),
+ ("style", "style", "NONE", ["NONE", "NOTE", "INFO", "WARNING", "TIP"]),
+ ]
+ helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
+
+ return root
diff --git a/setup.cfg b/setup.cfg
index 89f9a494..71d17459 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -66,6 +66,7 @@ jenkins_jobs.views =
list=jenkins_jobs.modules.view_list:List
nested=jenkins_jobs.modules.view_nested:Nested
pipeline=jenkins_jobs.modules.view_pipeline:Pipeline
+ sectioned=jenkins_jobs.modules.view_sectioned:Sectioned
jenkins_jobs.builders =
raw=jenkins_jobs.modules.general:raw
jenkins_jobs.reporters =
diff --git a/tests/base.py b/tests/base.py
index f828c773..910133f4 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -49,6 +49,7 @@ from jenkins_jobs.modules import view_all
from jenkins_jobs.modules import view_list
from jenkins_jobs.modules import view_nested
from jenkins_jobs.modules import view_pipeline
+from jenkins_jobs.modules import view_sectioned
from jenkins_jobs.parser import YamlParser
from jenkins_jobs.registry import ModuleRegistry
from jenkins_jobs.xml_config import XmlJob
@@ -242,6 +243,8 @@ class BaseScenariosTestCase(testscenarios.TestWithScenarios, BaseTestCase):
project = view_nested.Nested(registry)
elif yaml_content["view-type"] == "pipeline":
project = view_pipeline.Pipeline(registry)
+ elif yaml_content["view-type"] == "sectioned":
+ project = view_sectioned.Sectioned(registry)
else:
raise InvalidAttributeError("view-type", yaml_content["view-type"])
diff --git a/tests/views/fixtures/view_sectioned.xml b/tests/views/fixtures/view_sectioned.xml
new file mode 100644
index 00000000..47ee86c5
--- /dev/null
+++ b/tests/views/fixtures/view_sectioned.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<hudson.plugins.sectioned__view.SectionedView>
+ <name>SectionedViewTest</name>
+ <description/>
+ <filterExecutors>false</filterExecutors>
+ <filterQueue>false</filterQueue>
+ <properties class="hudson.model.View$PropertyList"/>
+ <sections>
+ <hudson.plugins.sectioned__view.ListViewSection>
+ <name>testName</name>
+ <jobNames>
+ <comparator class="hudson.util.CaseInsensitiveComparator"/>
+ <string>testJobName</string>
+ </jobNames>
+ <jobFilters/>
+ <width>HALF</width>
+ <alignment>LEFT</alignment>
+ <columns>
+ <hudson.views.JobColumn/>
+ </columns>
+ </hudson.plugins.sectioned__view.ListViewSection>
+ <hudson.plugins.sectioned__view.TextSection>
+ <jobNames>
+ <comparator class="hudson.util.CaseInsensitiveComparator"/>
+ </jobNames>
+ <jobFilters/>
+ <name/>
+ <width>FULL</width>
+ <alignment>CENTER</alignment>
+ <text>test text</text>
+ <style>INFO</style>
+ </hudson.plugins.sectioned__view.TextSection>
+ </sections>
+</hudson.plugins.sectioned__view.SectionedView>
diff --git a/tests/views/fixtures/view_sectioned.yaml b/tests/views/fixtures/view_sectioned.yaml
new file mode 100644
index 00000000..aa4c7567
--- /dev/null
+++ b/tests/views/fixtures/view_sectioned.yaml
@@ -0,0 +1,14 @@
+name: SectionedViewTest
+view-type: sectioned
+sections:
+ - name: testName
+ job-name:
+ - testJobName
+ columns:
+ - job
+ view-type: list
+ width: HALF
+ alignment: LEFT
+ - text: test text
+ style: INFO
+ view-type: text
diff --git a/tests/views/test_views.py b/tests/views/test_views.py
index 62435590..fb506310 100644
--- a/tests/views/test_views.py
+++ b/tests/views/test_views.py
@@ -17,6 +17,7 @@ from jenkins_jobs.modules import view_all
from jenkins_jobs.modules import view_list
from jenkins_jobs.modules import view_nested
from jenkins_jobs.modules import view_pipeline
+from jenkins_jobs.modules import view_sectioned
from tests import base
@@ -42,3 +43,9 @@ class TestCaseModuleViewPipeline(base.BaseScenariosTestCase):
fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = view_pipeline.Pipeline
+
+
+class TestCaseModuleViewSectioned(base.BaseScenariosTestCase):
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
+ scenarios = base.get_scenarios(fixtures_path)
+ klass = view_sectioned.Sectioned