Refactor jobfilters to separate file
Make things easier to document and parse. Change-Id: I35ce23b307970bbd05380d669efabcb68f6f4980 Signed-off-by: Thanh Ha <zxiiro@linux.com>
This commit is contained in:
parent
e6398cf373
commit
c3539a3172
211
jenkins_jobs/modules/view_jobfilters.py
Normal file
211
jenkins_jobs/modules/view_jobfilters.py
Normal file
@ -0,0 +1,211 @@
|
||||
# Copyright 2015 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.
|
||||
|
||||
import xml.etree.ElementTree as XML
|
||||
import jenkins_jobs.modules.helpers as helpers
|
||||
|
||||
|
||||
def build_duration(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.BuildDurationFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
('build-duration-type', 'buildCountTypeString', 'Latest'),
|
||||
('amount-type', 'amountTypeString', 'Hours'),
|
||||
('amount', 'amount', '0'),
|
||||
('less-than', 'lessThan', True),
|
||||
('build-duration-minutes', 'buildDurationMinutes', '0'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def build_status(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.BuildStatusFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
('never-built', 'neverBuilt', False),
|
||||
('building', 'building', False),
|
||||
('in-build-queue', 'inBuildQueue', False),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def build_trend(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.BuildTrendFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
('build-trend-type', 'buildCountTypeString', 'Latest'),
|
||||
('amount-type', 'amountTypeString', 'Hours'),
|
||||
('amount', 'amount', '0'),
|
||||
('status', 'statusTypeString', 'Completed'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def fallback(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.AddRemoveFallbackFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('fallback-type', 'fallbackTypeString', 'REMOVE_ALL_IF_ALL_INCLUDED'),
|
||||
('fallback-type', 'fallbackType', 'REMOVE_ALL_IF_ALL_INCLUDED'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def job_status(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.JobStatusFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
('unstable', 'unstable', False),
|
||||
('failed', 'failed', False),
|
||||
('aborted', 'aborted', False),
|
||||
('disabled', 'disabled', False),
|
||||
('stable', 'stable', False),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def job_type(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.JobTypeFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
('job-type', 'jobType', 'hudson.model.FreeStyleProject'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def most_recent(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.MostRecentJobsFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('max-to-include', 'maxToInclude', '0'),
|
||||
('check-start-time', 'checkStartTime', False),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def other_views(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.OtherViewsFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
('view-name', 'otherViewName',
|
||||
'<select a view other than this one>'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def parameter(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.ParameterFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
('name', 'nameRegex', ''),
|
||||
('value', 'valueRegex', ''),
|
||||
('description', 'descriptionRegex', ''),
|
||||
('use-default', 'useDefaultValue', False),
|
||||
('match-builds-in-progress', 'matchBuildsInProgress', False),
|
||||
('match-all-builds', 'matchAllBuilds', False),
|
||||
('max-builds-to-match', 'maxBuildsToMatch', 0),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def scm(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.ScmTypeFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
('scm-type', 'scmType', 'hudson.scm.NullSCM'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def secured_job(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.SecuredJobsFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def regex_job(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.RegExJobFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
('regex-name', 'valueTypeString', ''),
|
||||
('regex', 'regex', ''),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def unclassified(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.UnclassifiedJobsFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def upstream_downstream(xml_parent, data):
|
||||
xml = XML.SubElement(
|
||||
xml_parent, 'hudson.views.UpstreamDownstreamJobsFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('include-upstream', 'includeUpstream', False),
|
||||
('include-downstream', 'includeDownstream', False),
|
||||
('recursive', 'recursive', False),
|
||||
('exclude-originals', 'excludeOriginals', False),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def user_permissions(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.SecurityFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
('configure', 'configure', False),
|
||||
('build', 'build', False),
|
||||
('workspace', 'workspace', False),
|
||||
('permission-check', 'permissionCheckType', 'MustMatchAll'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def user_relevence(xml_parent, data):
|
||||
xml = XML.SubElement(xml_parent, 'hudson.views.UserRelevanceFilter')
|
||||
xml.set('plugin', 'view-job-filters')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString', 'includeMatched'),
|
||||
('build-count', 'buildCountTypeString', 'AtLeastOne'),
|
||||
('amount-type', 'amountTypeString', 'Hours'),
|
||||
('amount', 'amount', '0'),
|
||||
('match-user-id', 'matchUserId', False),
|
||||
('match-user-fullname', 'matchUserFullName', False),
|
||||
('ignore-case', 'ignoreCase', False),
|
||||
('ignore-whitespace', 'ignoreWhitespace', False),
|
||||
('ignore-non-alphaNumeric', 'ignoreNonAlphaNumeric', False),
|
||||
('match-builder', 'matchBuilder', False),
|
||||
('match-email', 'matchEmail', False),
|
||||
('match-scm-changes', 'matchScmChanges', False),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
|
@ -224,6 +224,7 @@ Example:
|
||||
import xml.etree.ElementTree as XML
|
||||
import jenkins_jobs.modules.base
|
||||
import jenkins_jobs.modules.helpers as helpers
|
||||
import jenkins_jobs.modules.view_jobfilters as view_jobfilters
|
||||
|
||||
COLUMN_DICT = {
|
||||
'status': 'hudson.views.StatusColumn',
|
||||
@ -333,254 +334,8 @@ class List(jenkins_jobs.modules.base.Base):
|
||||
jobfilters = data.get('job-filters', [])
|
||||
|
||||
for jobfilter in jobfilters:
|
||||
if jobfilter == 'most-recent':
|
||||
mr_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.MostRecentJobsFilter')
|
||||
mr_xml.set('plugin', 'view-job-filters')
|
||||
mr_data = jobfilters.get('most-recent')
|
||||
mapping = [
|
||||
('max-to-include', 'maxToInclude', '0'),
|
||||
('check-start-time', 'checkStartTime', False),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(mr_xml, mr_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'build-duration':
|
||||
bd_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.BuildDurationFilter')
|
||||
bd_xml.set('plugin', 'view-job-filters')
|
||||
bd_data = jobfilters.get('build-duration')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
('build-duration-type', 'buildCountTypeString', 'Latest'),
|
||||
('amount-type', 'amountTypeString', 'Hours'),
|
||||
('amount', 'amount', '0'),
|
||||
('less-than', 'lessThan', True),
|
||||
('build-duration-minutes', 'buildDurationMinutes', '0'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(bd_xml, bd_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'build-trend':
|
||||
bt_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.BuildTrendFilter')
|
||||
bt_xml.set('plugin', 'view-job-filters')
|
||||
bt_data = jobfilters.get('build-trend')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
('build-trend-type', 'buildCountTypeString', 'Latest'),
|
||||
('amount-type', 'amountTypeString', 'Hours'),
|
||||
('amount', 'amount', '0'),
|
||||
('status', 'statusTypeString', 'Completed'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(bt_xml, bt_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'job-status':
|
||||
js_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.JobStatusFilter')
|
||||
js_xml.set('plugin', 'view-job-filters')
|
||||
js_data = jobfilters.get('job-status')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
('unstable', 'unstable', False),
|
||||
('failed', 'failed', False),
|
||||
('aborted', 'aborted', False),
|
||||
('disabled', 'disabled', False),
|
||||
('stable', 'stable', False),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(js_xml, js_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'upstream-downstream':
|
||||
ud_xml = XML.SubElement(
|
||||
job_filter_xml,
|
||||
'hudson.views.UpstreamDownstreamJobsFilter'
|
||||
)
|
||||
ud_xml.set('plugin', 'view-job-filters')
|
||||
ud_data = jobfilters.get('upstream-downstream')
|
||||
mapping = [
|
||||
('include-upstream', 'includeUpstream',
|
||||
False),
|
||||
('include-downstream', 'includeDownstream', False),
|
||||
('recursive', 'recursive', False),
|
||||
('exclude-originals', 'excludeOriginals', False),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(ud_xml, ud_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'fallback':
|
||||
fb_xml = XML.SubElement(
|
||||
job_filter_xml,
|
||||
'hudson.views.AddRemoveFallbackFilter'
|
||||
)
|
||||
fb_xml.set('plugin', 'view-job-filters')
|
||||
fb_data = jobfilters.get('fallback')
|
||||
mapping = [
|
||||
('fallback-type', 'fallbackTypeString',
|
||||
'REMOVE_ALL_IF_ALL_INCLUDED'),
|
||||
('fallback-type', 'fallbackType',
|
||||
'REMOVE_ALL_IF_ALL_INCLUDED'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(fb_xml, fb_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'build-status':
|
||||
bs_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.BuildStatusFilter')
|
||||
bs_xml.set('plugin', 'view-job-filters')
|
||||
bs_data = jobfilters.get('build-status')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
('never-built', 'neverBuilt', False),
|
||||
('building', 'building', False),
|
||||
('in-build-queue', 'inBuildQueue', False),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(bs_xml, bs_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'user-relevence':
|
||||
ur_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.UserRelevanceFilter')
|
||||
ur_xml.set('plugin', 'view-job-filters')
|
||||
ur_data = jobfilters.get('user-relevence')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
('build-count', 'buildCountTypeString', 'AtLeastOne'),
|
||||
('amount-type', 'amountTypeString', 'Hours'),
|
||||
('amount', 'amount', '0'),
|
||||
('match-user-id', 'matchUserId', False),
|
||||
('match-user-fullname', 'matchUserFullName', False),
|
||||
('ignore-case', 'ignoreCase', False),
|
||||
('ignore-whitespace', 'ignoreWhitespace', False),
|
||||
('ignore-non-alphaNumeric', 'ignoreNonAlphaNumeric',
|
||||
False),
|
||||
('match-builder', 'matchBuilder', False),
|
||||
('match-email', 'matchEmail', False),
|
||||
('match-scm-changes', 'matchScmChanges', False),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(ur_xml, ur_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'regex-job':
|
||||
rj_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.RegExJobFilter')
|
||||
rj_xml.set('plugin', 'view-job-filters')
|
||||
rj_data = jobfilters.get('regex-job')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
('regex-name', 'valueTypeString', ''),
|
||||
('regex', 'regex', ''),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(rj_xml, rj_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'job-type':
|
||||
jt_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.JobTypeFilter')
|
||||
jt_xml.set('plugin', 'view-job-filters')
|
||||
jt_data = jobfilters.get('job-type')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
('job-type', 'jobType', 'hudson.model.FreeStyleProject'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(jt_xml, jt_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'parameter':
|
||||
pr_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.ParameterFilter')
|
||||
pr_xml.set('plugin', 'view-job-filters')
|
||||
pr_data = jobfilters.get('parameter')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
('name', 'nameRegex', ''),
|
||||
('value', 'valueRegex', ''),
|
||||
('description', 'descriptionRegex', ''),
|
||||
('use-default', 'useDefaultValue', False),
|
||||
('match-builds-in-progress', 'matchBuildsInProgress',
|
||||
False),
|
||||
('match-all-builds', 'matchAllBuilds', False),
|
||||
('max-builds-to-match', 'maxBuildsToMatch', 0),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(pr_xml, pr_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'other-views':
|
||||
ov_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.OtherViewsFilter')
|
||||
ov_xml.set('plugin', 'view-job-filters')
|
||||
ov_data = jobfilters.get('other-views')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
('view-name', 'otherViewName',
|
||||
'<select a view other than this one>'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(ov_xml, ov_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'scm':
|
||||
st_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.ScmTypeFilter')
|
||||
st_xml.set('plugin', 'view-job-filters')
|
||||
st_data = jobfilters.get('scm')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
('scm-type', 'scmType', 'hudson.scm.NullSCM'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(st_xml, st_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'secured-job':
|
||||
sj_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.SecuredJobsFilter')
|
||||
sj_xml.set('plugin', 'view-job-filters')
|
||||
sj_data = jobfilters.get('secured-job')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(sj_xml, sj_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'user-permissions':
|
||||
up_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.SecurityFilter')
|
||||
up_xml.set('plugin', 'view-job-filters')
|
||||
up_data = jobfilters.get('user-permissions')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
('configure', 'configure', False),
|
||||
('build', 'build', False),
|
||||
('workspace', 'workspace', False),
|
||||
('permission-check', 'permissionCheckType',
|
||||
'MustMatchAll'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(up_xml, up_data, mapping,
|
||||
fail_required=True)
|
||||
|
||||
if jobfilter == 'unclassified':
|
||||
uc_xml = XML.SubElement(job_filter_xml,
|
||||
'hudson.views.UnclassifiedJobsFilter')
|
||||
uc_xml.set('plugin', 'view-job-filters')
|
||||
uc_data = jobfilters.get('unclassified')
|
||||
mapping = [
|
||||
('match-type', 'includeExcludeTypeString',
|
||||
'includeMatched'),
|
||||
]
|
||||
helpers.convert_mapping_to_xml(uc_xml, uc_data, mapping,
|
||||
fail_required=True)
|
||||
filter = getattr(view_jobfilters, jobfilter.replace('-', '_'))
|
||||
filter(job_filter_xml, jobfilters.get(jobfilter))
|
||||
|
||||
c_xml = XML.SubElement(root, 'columns')
|
||||
columns = data.get('columns', DEFAULT_COLUMNS)
|
||||
|
Loading…
x
Reference in New Issue
Block a user