From 83592a094bfd8889e50d29019f5f7f12e225deb3 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Wed, 9 Aug 2017 14:33:24 -0400 Subject: [PATCH] Add default columns to list views This uses the default "All" view columns as the columns for any views without a columns attribute sets. This means that view definitions which don't define any columns will still end up producing a useful view. (Note that the "All" columns are not fetched from the Jenkins instance; the columns that are the default in a fresh Jenkins install are hard-coded.) Change-Id: I0a21e024be383088c6238c3fc7beb708af8c2c46 --- jenkins_jobs/modules/view_list.py | 4 ++- .../views/fixtures/view_list_defaults001.xml | 26 +++++++++++++++++++ .../views/fixtures/view_list_defaults001.yaml | 11 ++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/views/fixtures/view_list_defaults001.xml create mode 100644 tests/views/fixtures/view_list_defaults001.yaml diff --git a/jenkins_jobs/modules/view_list.py b/jenkins_jobs/modules/view_list.py index e628b390b..c4ab81dee 100644 --- a/jenkins_jobs/modules/view_list.py +++ b/jenkins_jobs/modules/view_list.py @@ -50,6 +50,8 @@ COLUMN_DICT = { 'build-button': 'hudson.views.BuildButtonColumn', 'last-stable': 'hudson.views.LastStableColumn', } +DEFAULT_COLUMNS = ['status', 'weather', 'job', 'last-success', 'last-failure', + 'last-duration', 'build-button'] class List(jenkins_jobs.modules.base.Base): @@ -78,7 +80,7 @@ class List(jenkins_jobs.modules.base.Base): XML.SubElement(root, 'jobFilters') c_xml = XML.SubElement(root, 'columns') - columns = data.get('columns', []) + columns = data.get('columns', DEFAULT_COLUMNS) for column in columns: if column in COLUMN_DICT: diff --git a/tests/views/fixtures/view_list_defaults001.xml b/tests/views/fixtures/view_list_defaults001.xml new file mode 100644 index 000000000..e5d9b87df --- /dev/null +++ b/tests/views/fixtures/view_list_defaults001.xml @@ -0,0 +1,26 @@ + + + list-view-name01 + Sample description + true + true + + + + job-name-1 + job-name-2 + job-name-3 + + + + + + + + + + + + true + false + diff --git a/tests/views/fixtures/view_list_defaults001.yaml b/tests/views/fixtures/view_list_defaults001.yaml new file mode 100644 index 000000000..a4edd893e --- /dev/null +++ b/tests/views/fixtures/view_list_defaults001.yaml @@ -0,0 +1,11 @@ +name: list-view-name01 +view-type: list +description: 'Sample description' +filter-executors: true +filter-queue: true +job-name: + - job-name-1 + - job-name-2 + - job-name-3 +recurse: true +status-filter: false