| 1 |
# Copyright 2015 Openstack Foundation |
| 2 |
|
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
import xml.etree.ElementTree as XML |
| 16 |
import jenkins_jobs.modules.helpers as helpers |
| 17 |
|
| 18 |
|
| 19 |
def build_duration(xml_parent, data): |
| 20 |
xml = XML.SubElement(xml_parent, "hudson.views.BuildDurationFilter") |
| 21 |
xml.set("plugin", "view-job-filters") |
| 22 |
mapping = [ |
| 23 |
("match-type", "includeExcludeTypeString", "includeMatched"), |
| 24 |
("build-duration-type", "buildCountTypeString", "Latest"), |
| 25 |
("amount-type", "amountTypeString", "Hours"), |
| 26 |
("amount", "amount", "0"), |
| 27 |
("less-than", "lessThan", True), |
| 28 |
("build-duration-minutes", "buildDurationMinutes", "0"), |
| 29 |
] |
| 30 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 31 |
|
| 32 |
|
| 33 |
def build_status(xml_parent, data): |
| 34 |
xml = XML.SubElement(xml_parent, "hudson.views.BuildStatusFilter") |
| 35 |
xml.set("plugin", "view-job-filters") |
| 36 |
mapping = [ |
| 37 |
("match-type", "includeExcludeTypeString", "includeMatched"), |
| 38 |
("never-built", "neverBuilt", False), |
| 39 |
("building", "building", False), |
| 40 |
("in-build-queue", "inBuildQueue", False), |
| 41 |
] |
| 42 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 43 |
|
| 44 |
|
| 45 |
def build_trend(xml_parent, data): |
| 46 |
xml = XML.SubElement(xml_parent, "hudson.views.BuildTrendFilter") |
| 47 |
xml.set("plugin", "view-job-filters") |
| 48 |
mapping = [ |
| 49 |
("match-type", "includeExcludeTypeString", "includeMatched"), |
| 50 |
("build-trend-type", "buildCountTypeString", "Latest"), |
| 51 |
("amount-type", "amountTypeString", "Hours"), |
| 52 |
("amount", "amount", "0"), |
| 53 |
("status", "statusTypeString", "Completed"), |
| 54 |
] |
| 55 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 56 |
|
| 57 |
|
| 58 |
def fallback(xml_parent, data): |
| 59 |
xml = XML.SubElement(xml_parent, "hudson.views.AddRemoveFallbackFilter") |
| 60 |
xml.set("plugin", "view-job-filters") |
| 61 |
mapping = [ |
| 62 |
("fallback-type", "fallbackTypeString", "REMOVE_ALL_IF_ALL_INCLUDED"), |
| 63 |
("fallback-type", "fallbackType", "REMOVE_ALL_IF_ALL_INCLUDED"), |
| 64 |
] |
| 65 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 66 |
|
| 67 |
|
| 68 |
def job_status(xml_parent, data): |
| 69 |
xml = XML.SubElement(xml_parent, "hudson.views.JobStatusFilter") |
| 70 |
xml.set("plugin", "view-job-filters") |
| 71 |
mapping = [ |
| 72 |
("match-type", "includeExcludeTypeString", "includeMatched"), |
| 73 |
("unstable", "unstable", False), |
| 74 |
("failed", "failed", False), |
| 75 |
("aborted", "aborted", False), |
| 76 |
("disabled", "disabled", False), |
| 77 |
("stable", "stable", False), |
| 78 |
] |
| 79 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 80 |
|
| 81 |
|
| 82 |
def job_type(xml_parent, data): |
| 83 |
xml = XML.SubElement(xml_parent, "hudson.views.JobTypeFilter") |
| 84 |
xml.set("plugin", "view-job-filters") |
| 85 |
mapping = [ |
| 86 |
("match-type", "includeExcludeTypeString", "includeMatched"), |
| 87 |
("job-type", "jobType", "hudson.model.FreeStyleProject"), |
| 88 |
] |
| 89 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 90 |
|
| 91 |
|
| 92 |
def most_recent(xml_parent, data): |
| 93 |
xml = XML.SubElement(xml_parent, "hudson.views.MostRecentJobsFilter") |
| 94 |
xml.set("plugin", "view-job-filters") |
| 95 |
mapping = [ |
| 96 |
("max-to-include", "maxToInclude", "0"), |
| 97 |
("check-start-time", "checkStartTime", False), |
| 98 |
] |
| 99 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 100 |
|
| 101 |
|
| 102 |
def other_views(xml_parent, data): |
| 103 |
xml = XML.SubElement(xml_parent, "hudson.views.OtherViewsFilter") |
| 104 |
xml.set("plugin", "view-job-filters") |
| 105 |
mapping = [ |
| 106 |
("match-type", "includeExcludeTypeString", "includeMatched"), |
| 107 |
("view-name", "otherViewName", "<select a view other than this one>"), |
| 108 |
] |
| 109 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 110 |
|
| 111 |
|
| 112 |
def parameter(xml_parent, data): |
| 113 |
xml = XML.SubElement(xml_parent, "hudson.views.ParameterFilter") |
| 114 |
xml.set("plugin", "view-job-filters") |
| 115 |
mapping = [ |
| 116 |
("match-type", "includeExcludeTypeString", "includeMatched"), |
| 117 |
("name", "nameRegex", ""), |
| 118 |
("value", "valueRegex", ""), |
| 119 |
("description", "descriptionRegex", ""), |
| 120 |
("use-default", "useDefaultValue", False), |
| 121 |
("match-builds-in-progress", "matchBuildsInProgress", False), |
| 122 |
("match-all-builds", "matchAllBuilds", False), |
| 123 |
("max-builds-to-match", "maxBuildsToMatch", 0), |
| 124 |
] |
| 125 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 126 |
|
| 127 |
|
| 128 |
def scm(xml_parent, data): |
| 129 |
xml = XML.SubElement(xml_parent, "hudson.views.ScmTypeFilter") |
| 130 |
xml.set("plugin", "view-job-filters") |
| 131 |
mapping = [ |
| 132 |
("match-type", "includeExcludeTypeString", "includeMatched"), |
| 133 |
("scm-type", "scmType", "hudson.scm.NullSCM"), |
| 134 |
] |
| 135 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 136 |
|
| 137 |
|
| 138 |
def secured_job(xml_parent, data): |
| 139 |
xml = XML.SubElement(xml_parent, "hudson.views.SecuredJobsFilter") |
| 140 |
xml.set("plugin", "view-job-filters") |
| 141 |
mapping = [("match-type", "includeExcludeTypeString", "includeMatched")] |
| 142 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 143 |
|
| 144 |
|
| 145 |
def regex_job(xml_parent, data): |
| 146 |
xml = XML.SubElement(xml_parent, "hudson.views.RegExJobFilter") |
| 147 |
xml.set("plugin", "view-job-filters") |
| 148 |
mapping = [ |
| 149 |
("match-type", "includeExcludeTypeString", "includeMatched"), |
| 150 |
("regex-name", "valueTypeString", ""), |
| 151 |
("regex", "regex", ""), |
| 152 |
] |
| 153 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 154 |
|
| 155 |
|
| 156 |
def unclassified(xml_parent, data): |
| 157 |
xml = XML.SubElement(xml_parent, "hudson.views.UnclassifiedJobsFilter") |
| 158 |
xml.set("plugin", "view-job-filters") |
| 159 |
mapping = [("match-type", "includeExcludeTypeString", "includeMatched")] |
| 160 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 161 |
|
| 162 |
|
| 163 |
def upstream_downstream(xml_parent, data): |
| 164 |
xml = XML.SubElement(xml_parent, "hudson.views.UpstreamDownstreamJobsFilter") |
| 165 |
xml.set("plugin", "view-job-filters") |
| 166 |
mapping = [ |
| 167 |
("include-upstream", "includeUpstream", False), |
| 168 |
("include-downstream", "includeDownstream", False), |
| 169 |
("recursive", "recursive", False), |
| 170 |
("exclude-originals", "excludeOriginals", False), |
| 171 |
] |
| 172 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 173 |
|
| 174 |
|
| 175 |
def user_permissions(xml_parent, data): |
| 176 |
xml = XML.SubElement(xml_parent, "hudson.views.SecurityFilter") |
| 177 |
xml.set("plugin", "view-job-filters") |
| 178 |
mapping = [ |
| 179 |
("match-type", "includeExcludeTypeString", "includeMatched"), |
| 180 |
("configure", "configure", False), |
| 181 |
("build", "build", False), |
| 182 |
("workspace", "workspace", False), |
| 183 |
("permission-check", "permissionCheckType", "MustMatchAll"), |
| 184 |
] |
| 185 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |
| 186 |
|
| 187 |
|
| 188 |
def user_relevence(xml_parent, data): |
| 189 |
xml = XML.SubElement(xml_parent, "hudson.views.UserRelevanceFilter") |
| 190 |
xml.set("plugin", "view-job-filters") |
| 191 |
mapping = [ |
| 192 |
("match-type", "includeExcludeTypeString", "includeMatched"), |
| 193 |
("build-count", "buildCountTypeString", "AtLeastOne"), |
| 194 |
("amount-type", "amountTypeString", "Hours"), |
| 195 |
("amount", "amount", "0"), |
| 196 |
("match-user-id", "matchUserId", False), |
| 197 |
("match-user-fullname", "matchUserFullName", False), |
| 198 |
("ignore-case", "ignoreCase", False), |
| 199 |
("ignore-whitespace", "ignoreWhitespace", False), |
| 200 |
("ignore-non-alphaNumeric", "ignoreNonAlphaNumeric", False), |
| 201 |
("match-builder", "matchBuilder", False), |
| 202 |
("match-email", "matchEmail", False), |
| 203 |
("match-scm-changes", "matchScmChanges", False), |
| 204 |
] |
| 205 |
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True) |