summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-07-25 02:51:28 +0000
committerGerrit Code Review <review@openstack.org>2018-07-25 02:51:28 +0000
commitebf7670df10c8a0a0506c7e0e3ab6e51c12a99e2 (patch)
tree2bb024a687cb47ea4ab1fe6945fb51a5315e9bd3
parentb30a825e9b1c5c4e65273e73d55dba936280ea0f (diff)
parent059fd49f3d4b4f8ac342738c55c85acab8f33cc2 (diff)
Merge "[Triggers] Update helpers import to common style"
-rw-r--r--jenkins_jobs/modules/triggers.py115
1 files changed, 71 insertions, 44 deletions
diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py
index 004236f..34eff76 100644
--- a/jenkins_jobs/modules/triggers.py
+++ b/jenkins_jobs/modules/triggers.py
@@ -42,7 +42,7 @@ from jenkins_jobs.errors import JenkinsJobsException
42from jenkins_jobs.errors import MissingAttributeError 42from jenkins_jobs.errors import MissingAttributeError
43import jenkins_jobs.modules.base 43import jenkins_jobs.modules.base
44from jenkins_jobs.modules import hudson_model 44from jenkins_jobs.modules import hudson_model
45from jenkins_jobs.modules.helpers import convert_mapping_to_xml 45import jenkins_jobs.modules.helpers as helpers
46 46
47logger = logging.getLogger(str(__name__)) 47logger = logging.getLogger(str(__name__))
48 48
@@ -170,8 +170,10 @@ def build_gerrit_triggers(xml_parent, data):
170 mapping = [ 170 mapping = [
171 ('exclude-drafts', 'excludeDrafts', False), 171 ('exclude-drafts', 'excludeDrafts', False),
172 ('exclude-trivial-rebase', 'excludeTrivialRebase', False), 172 ('exclude-trivial-rebase', 'excludeTrivialRebase', False),
173 ('exclude-no-code-change', 'excludeNoCodeChange', False)] 173 ('exclude-no-code-change', 'excludeNoCodeChange', False),
174 convert_mapping_to_xml(pc, pce, mapping, fail_required=True) 174 ]
175 helpers.convert_mapping_to_xml(
176 pc, pce, mapping, fail_required=True)
175 177
176 if 'comment-added-event' in event.keys(): 178 if 'comment-added-event' in event.keys():
177 comment_added_event = event['comment-added-event'] 179 comment_added_event = event['comment-added-event']
@@ -181,8 +183,9 @@ def build_gerrit_triggers(xml_parent, data):
181 mapping = [ 183 mapping = [
182 ('approval-category', 'verdictCategory', None), 184 ('approval-category', 'verdictCategory', None),
183 ('approval-value', 185 ('approval-value',
184 'commentAddedTriggerApprovalValue', None)] 186 'commentAddedTriggerApprovalValue', None),
185 convert_mapping_to_xml(cadded, 187 ]
188 helpers.convert_mapping_to_xml(cadded,
186 comment_added_event, mapping, fail_required=True) 189 comment_added_event, mapping, fail_required=True)
187 190
188 if 'comment-added-contains-event' in event.keys(): 191 if 'comment-added-contains-event' in event.keys():
@@ -558,7 +561,8 @@ def gerrit(registry, xml_parent, data):
558 ('readable-message', 'readableMessage', False), 561 ('readable-message', 'readableMessage', False),
559 ('dependency-jobs', 'dependencyJobsNames', ''), 562 ('dependency-jobs', 'dependencyJobsNames', ''),
560 ] 563 ]
561 convert_mapping_to_xml(gtrig, data, general_mappings, fail_required=True) 564 helpers.convert_mapping_to_xml(
565 gtrig, data, general_mappings, fail_required=True)
562 notification_levels = ['NONE', 'OWNER', 'OWNER_REVIEWERS', 'ALL', 566 notification_levels = ['NONE', 'OWNER', 'OWNER_REVIEWERS', 'ALL',
563 'SERVER_DEFAULT'] 567 'SERVER_DEFAULT']
564 notification_level = data.get('notification-level', 'SERVER_DEFAULT') 568 notification_level = data.get('notification-level', 'SERVER_DEFAULT')
@@ -614,7 +618,8 @@ def gerrit(registry, xml_parent, data):
614 ('custom-url', 'customUrl', ''), 618 ('custom-url', 'customUrl', ''),
615 ('server-name', 'serverName', '__ANY__'), 619 ('server-name', 'serverName', '__ANY__'),
616 ] 620 ]
617 convert_mapping_to_xml(gtrig, data, message_mappings, fail_required=True) 621 helpers.convert_mapping_to_xml(
622 gtrig, data, message_mappings, fail_required=True)
618 623
619 624
620def dockerhub_notification(registry, xml_parent, data): 625def dockerhub_notification(registry, xml_parent, data):
@@ -874,7 +879,7 @@ def jms_messaging(registry, xml_parent, data):
874 ("selector", 'selector', ''), 879 ("selector", 'selector', ''),
875 ("provider-name", 'providerName', ''), 880 ("provider-name", 'providerName', ''),
876 ] 881 ]
877 convert_mapping_to_xml(jmsm, data, mapping, fail_required=True) 882 helpers.convert_mapping_to_xml(jmsm, data, mapping, fail_required=True)
878 883
879 checks = data.get('checks', []) 884 checks = data.get('checks', [])
880 if len(checks) > 0: 885 if len(checks) > 0:
@@ -884,8 +889,9 @@ def jms_messaging(registry, xml_parent, data):
884 'messaging.checks.MsgCheck') 889 'messaging.checks.MsgCheck')
885 mapping = [ 890 mapping = [
886 ('field', 'field', ''), 891 ('field', 'field', ''),
887 ('expected-value', 'expectedValue', '')] 892 ('expected-value', 'expectedValue', ''),
888 convert_mapping_to_xml( 893 ]
894 helpers.convert_mapping_to_xml(
889 msgcheck, check, mapping, fail_required=True) 895 msgcheck, check, mapping, fail_required=True)
890 896
891 897
@@ -1239,9 +1245,9 @@ def gitlab_merge_request(registry, xml_parent, data):
1239 ('publish-build-progress-messages', '__publishBuildProgressMessages', 1245 ('publish-build-progress-messages', '__publishBuildProgressMessages',
1240 True), 1246 True),
1241 ('auto-close-failed', '__autoCloseFailed', False), 1247 ('auto-close-failed', '__autoCloseFailed', False),
1242 ('auto-merge-passed', '__autoMergePassed', False) 1248 ('auto-merge-passed', '__autoMergePassed', False),
1243 ] 1249 ]
1244 convert_mapping_to_xml(ghprb, data, mapping, True) 1250 helpers.convert_mapping_to_xml(ghprb, data, mapping, True)
1245 1251
1246 1252
1247def gitlab(registry, xml_parent, data): 1253def gitlab(registry, xml_parent, data):
@@ -1350,26 +1356,34 @@ def gitlab(registry, xml_parent, data):
1350 if plugin_ver >= pkg_resources.parse_version("1.1.26"): 1356 if plugin_ver >= pkg_resources.parse_version("1.1.26"):
1351 mapping = [ 1357 mapping = [
1352 ('trigger-open-merge-request-push', 1358 ('trigger-open-merge-request-push',
1353 'triggerOpenMergeRequestOnPush', 'never', valid_merge_request)] 1359 'triggerOpenMergeRequestOnPush', 'never', valid_merge_request),
1354 convert_mapping_to_xml(gitlab, data, mapping, fail_required=True) 1360 ]
1361 helpers.convert_mapping_to_xml(
1362 gitlab, data, mapping, fail_required=True)
1355 else: 1363 else:
1356 mapping = [ 1364 mapping = [
1357 ('trigger-open-merge-request-push', 1365 ('trigger-open-merge-request-push',
1358 'triggerOpenMergeRequestOnPush', True)] 1366 'triggerOpenMergeRequestOnPush', True),
1359 convert_mapping_to_xml(gitlab, data, mapping, fail_required=True) 1367 ]
1368 helpers.convert_mapping_to_xml(
1369 gitlab, data, mapping, fail_required=True)
1360 1370
1361 if plugin_ver < pkg_resources.parse_version('1.2.0'): 1371 if plugin_ver < pkg_resources.parse_version('1.2.0'):
1362 if data.get('branch-filter-type', '') == 'All': 1372 if data.get('branch-filter-type', '') == 'All':
1363 data['branch-filter-type'] = '' 1373 data['branch-filter-type'] = ''
1364 valid_filters = ['', 'NameBasedFilter', 'RegexBasedFilter'] 1374 valid_filters = ['', 'NameBasedFilter', 'RegexBasedFilter']
1365 mapping = [ 1375 mapping = [
1366 ('branch-filter-type', 'branchFilterName', '', valid_filters)] 1376 ('branch-filter-type', 'branchFilterName', '', valid_filters),
1367 convert_mapping_to_xml(gitlab, data, mapping, fail_required=True) 1377 ]
1378 helpers.convert_mapping_to_xml(
1379 gitlab, data, mapping, fail_required=True)
1368 else: 1380 else:
1369 valid_filters = ['All', 'NameBasedFilter', 'RegexBasedFilter'] 1381 valid_filters = ['All', 'NameBasedFilter', 'RegexBasedFilter']
1370 mapping = [ 1382 mapping = [
1371 ('branch-filter-type', 'branchFilterType', 'All', valid_filters)] 1383 ('branch-filter-type', 'branchFilterType', 'All', valid_filters),
1372 convert_mapping_to_xml(gitlab, data, mapping, fail_required=True) 1384 ]
1385 helpers.convert_mapping_to_xml(
1386 gitlab, data, mapping, fail_required=True)
1373 1387
1374 XML.SubElement(gitlab, 'spec').text = '' 1388 XML.SubElement(gitlab, 'spec').text = ''
1375 mapping = [ 1389 mapping = [
@@ -1396,7 +1410,7 @@ def gitlab(registry, xml_parent, data):
1396 ('include-branches', 'includeBranchesSpec', []), 1410 ('include-branches', 'includeBranchesSpec', []),
1397 ('exclude-branches', 'excludeBranchesSpec', []), 1411 ('exclude-branches', 'excludeBranchesSpec', []),
1398 ) 1412 )
1399 convert_mapping_to_xml(gitlab, data, mapping, fail_required=True) 1413 helpers.convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
1400 1414
1401 for yaml_name, xml_name, default_val in list_mapping: 1415 for yaml_name, xml_name, default_val in list_mapping:
1402 value = ', '.join(data.get(yaml_name, default_val)) 1416 value = ', '.join(data.get(yaml_name, default_val))
@@ -1437,7 +1451,7 @@ def build_result(registry, xml_parent, data):
1437 ('cron', 'spec', ''), 1451 ('cron', 'spec', ''),
1438 ('combine', 'combinedJobs', False), 1452 ('combine', 'combinedJobs', False),
1439 ] 1453 ]
1440 convert_mapping_to_xml(brt, data, mapping, fail_required=True) 1454 helpers.convert_mapping_to_xml(brt, data, mapping, fail_required=True)
1441 jobs_info = XML.SubElement(brt, 'jobsInfo') 1455 jobs_info = XML.SubElement(brt, 'jobsInfo')
1442 result_dict = {'success': 'SUCCESS', 1456 result_dict = {'success': 'SUCCESS',
1443 'unstable': 'UNSTABLE', 1457 'unstable': 'UNSTABLE',
@@ -1449,15 +1463,20 @@ def build_result(registry, xml_parent, data):
1449 'buildresulttrigger.model.' 1463 'buildresulttrigger.model.'
1450 'BuildResultTriggerInfo') 1464 'BuildResultTriggerInfo')
1451 jobs_string = ",".join(group['jobs']) 1465 jobs_string = ",".join(group['jobs'])
1452 mapping = [('', 'jobNames', jobs_string, group)] 1466 mapping = [
1453 convert_mapping_to_xml(brti, group, mapping, fail_required=True) 1467 ('', 'jobNames', jobs_string, group),
1468 ]
1469 helpers.convert_mapping_to_xml(
1470 brti, group, mapping, fail_required=True)
1454 checked_results = XML.SubElement(brti, 'checkedResults') 1471 checked_results = XML.SubElement(brti, 'checkedResults')
1455 for result in group.get('results', ['success']): 1472 for result in group.get('results', ['success']):
1456 model_checked = XML.SubElement(checked_results, 'org.jenkinsci.' 1473 model_checked = XML.SubElement(checked_results, 'org.jenkinsci.'
1457 'plugins.buildresulttrigger.model.' 1474 'plugins.buildresulttrigger.model.'
1458 'CheckedResult') 1475 'CheckedResult')
1459 mapping = [('', 'checked', result, result_dict)] 1476 mapping = [
1460 convert_mapping_to_xml( 1477 ('', 'checked', result, result_dict),
1478 ]
1479 helpers.convert_mapping_to_xml(
1461 model_checked, result_dict, mapping, fail_required=True) 1480 model_checked, result_dict, mapping, fail_required=True)
1462 1481
1463 1482
@@ -1555,7 +1574,7 @@ def monitor_folders(registry, xml_parent, data):
1555 ('path', 'path', ''), 1574 ('path', 'path', ''),
1556 ('cron', 'spec', ''), 1575 ('cron', 'spec', ''),
1557 ] 1576 ]
1558 convert_mapping_to_xml(ft, data, mappings, fail_required=True) 1577 helpers.convert_mapping_to_xml(ft, data, mappings, fail_required=True)
1559 1578
1560 includes = data.get('includes', '') 1579 includes = data.get('includes', '')
1561 XML.SubElement(ft, 'includes').text = ",".join(includes) 1580 XML.SubElement(ft, 'includes').text = ",".join(includes)
@@ -1674,7 +1693,7 @@ def monitor_files(registry, xml_parent, data):
1674 ('strategy', 'strategy', 'LATEST', valid_strategies), 1693 ('strategy', 'strategy', 'LATEST', valid_strategies),
1675 ('', 'inspectingContentFile', bool(check_content)), 1694 ('', 'inspectingContentFile', bool(check_content)),
1676 ] 1695 ]
1677 convert_mapping_to_xml( 1696 helpers.convert_mapping_to_xml(
1678 file_tag, file_info, files_mapping, fail_required=True) 1697 file_tag, file_info, files_mapping, fail_required=True)
1679 1698
1680 base_content_tag = XML.SubElement(file_tag, 'contentFileTypes') 1699 base_content_tag = XML.SubElement(file_tag, 'contentFileTypes')
@@ -1748,7 +1767,7 @@ def ivy(registry, xml_parent, data):
1748 ('enable-concurrent', 'enableConcurrentBuild', False), 1767 ('enable-concurrent', 'enableConcurrentBuild', False),
1749 ('cron', 'spec', ''), 1768 ('cron', 'spec', ''),
1750 ] 1769 ]
1751 convert_mapping_to_xml(it, data, mapping, fail_required=False) 1770 helpers.convert_mapping_to_xml(it, data, mapping, fail_required=False)
1752 1771
1753 properties_file_path = data.get('properties-file', []) 1772 properties_file_path = data.get('properties-file', [])
1754 XML.SubElement(it, 'propertiesFilePath').text = ";".join( 1773 XML.SubElement(it, 'propertiesFilePath').text = ";".join(
@@ -1800,7 +1819,7 @@ def script(registry, xml_parent, data):
1800 ('', 'labelRestriction', bool(label)), 1819 ('', 'labelRestriction', bool(label)),
1801 ('', 'triggerLabel', label), 1820 ('', 'triggerLabel', label),
1802 ] 1821 ]
1803 convert_mapping_to_xml(st, data, mappings, fail_required=False) 1822 helpers.convert_mapping_to_xml(st, data, mappings, fail_required=False)
1804 1823
1805 1824
1806def groovy_script(registry, xml_parent, data): 1825def groovy_script(registry, xml_parent, data):
@@ -1850,7 +1869,7 @@ def groovy_script(registry, xml_parent, data):
1850 ('', 'labelRestriction', bool(label)), 1869 ('', 'labelRestriction', bool(label)),
1851 ('', 'triggerLabel', label), 1870 ('', 'triggerLabel', label),
1852 ] 1871 ]
1853 convert_mapping_to_xml(gst, data, mappings, fail_required=False) 1872 helpers.convert_mapping_to_xml(gst, data, mappings, fail_required=False)
1854 1873
1855 1874
1856def rabbitmq(registry, xml_parent, data): 1875def rabbitmq(registry, xml_parent, data):
@@ -1873,8 +1892,9 @@ def rabbitmq(registry, xml_parent, data):
1873 'RemoteBuildTrigger') 1892 'RemoteBuildTrigger')
1874 mapping = [ 1893 mapping = [
1875 ('', 'spec', ''), 1894 ('', 'spec', ''),
1876 ('token', 'remoteBuildToken', None)] 1895 ('token', 'remoteBuildToken', None),
1877 convert_mapping_to_xml(rabbitmq, data, mapping, fail_required=True) 1896 ]
1897 helpers.convert_mapping_to_xml(rabbitmq, data, mapping, fail_required=True)
1878 1898
1879 1899
1880def parameterized_timer(parser, xml_parent, data): 1900def parameterized_timer(parser, xml_parent, data):
@@ -1899,8 +1919,10 @@ def parameterized_timer(parser, xml_parent, data):
1899 'ParameterizedTimerTrigger') 1919 'ParameterizedTimerTrigger')
1900 mapping = [ 1920 mapping = [
1901 ('', 'spec', ''), 1921 ('', 'spec', ''),
1902 ('cron', 'parameterizedSpecification', None)] 1922 ('cron', 'parameterizedSpecification', None),
1903 convert_mapping_to_xml(param_timer, data, mapping, fail_required=True) 1923 ]
1924 helpers.convert_mapping_to_xml(
1925 param_timer, data, mapping, fail_required=True)
1904 1926
1905 1927
1906def jira_changelog(registry, xml_parent, data): 1928def jira_changelog(registry, xml_parent, data):
@@ -1961,8 +1983,10 @@ def jira_changelog(registry, xml_parent, data):
1961 'jiratrigger.JiraChangelogTrigger') 1983 'jiratrigger.JiraChangelogTrigger')
1962 jcht.set('plugin', 'jira-trigger') 1984 jcht.set('plugin', 'jira-trigger')
1963 1985
1964 mapping = [('jql-filter', 'jqlFilter', '')] 1986 mapping = [
1965 convert_mapping_to_xml(jcht, data, mapping, fail_required=True) 1987 ('jql-filter', 'jqlFilter', ''),
1988 ]
1989 helpers.convert_mapping_to_xml(jcht, data, mapping, fail_required=True)
1966 1990
1967 changelog = XML.SubElement(jcht, 'changelogMatchers') 1991 changelog = XML.SubElement(jcht, 'changelogMatchers')
1968 mappings = [ 1992 mappings = [
@@ -1987,7 +2011,7 @@ def jira_changelog(registry, xml_parent, data):
1987 'JiraFieldChangelogMatcher') 2011 'JiraFieldChangelogMatcher')
1988 XML.SubElement(parent_tag, 'fieldType').text = 'JIRA' 2012 XML.SubElement(parent_tag, 'fieldType').text = 'JIRA'
1989 2013
1990 convert_mapping_to_xml(parent_tag, matcher, 2014 helpers.convert_mapping_to_xml(parent_tag, matcher,
1991 mappings, fail_required=True) 2015 mappings, fail_required=True)
1992 2016
1993 param = XML.SubElement(jcht, 'parameterMappings') 2017 param = XML.SubElement(jcht, 'parameterMappings')
@@ -1999,7 +2023,7 @@ def jira_changelog(registry, xml_parent, data):
1999 parent = XML.SubElement(param, 'com.ceilfors.jenkins.plugins.' 2023 parent = XML.SubElement(param, 'com.ceilfors.jenkins.plugins.'
2000 'jiratrigger.parameter.' 2024 'jiratrigger.parameter.'
2001 'IssueAttributePathParameterMapping') 2025 'IssueAttributePathParameterMapping')
2002 convert_mapping_to_xml( 2026 helpers.convert_mapping_to_xml(
2003 parent, parameter, parameter_mappings, fail_required=True) 2027 parent, parameter, parameter_mappings, fail_required=True)
2004 2028
2005 2029
@@ -2037,8 +2061,9 @@ def jira_comment_trigger(registry, xml_parent, data):
2037 jct.set('plugin', 'jira-trigger') 2061 jct.set('plugin', 'jira-trigger')
2038 mapping = [ 2062 mapping = [
2039 ('jql-filter', 'jqlFilter', ''), 2063 ('jql-filter', 'jqlFilter', ''),
2040 ('comment-pattern', 'commentPattern', '(?i)build this please')] 2064 ('comment-pattern', 'commentPattern', '(?i)build this please'),
2041 convert_mapping_to_xml(jct, data, mapping, fail_required=True) 2065 ]
2066 helpers.convert_mapping_to_xml(jct, data, mapping, fail_required=True)
2042 2067
2043 param = XML.SubElement(jct, 'parameterMappings') 2068 param = XML.SubElement(jct, 'parameterMappings')
2044 for parameter in data.get('parameter-mapping', []): 2069 for parameter in data.get('parameter-mapping', []):
@@ -2047,8 +2072,9 @@ def jira_comment_trigger(registry, xml_parent, data):
2047 'IssueAttributePathParameterMapping') 2072 'IssueAttributePathParameterMapping')
2048 parameter_mappings = [ 2073 parameter_mappings = [
2049 ('jenkins-parameter', 'jenkinsParameter', ''), 2074 ('jenkins-parameter', 'jenkinsParameter', ''),
2050 ('issue-attribute-path', 'issueAttributePath', '')] 2075 ('issue-attribute-path', 'issueAttributePath', ''),
2051 convert_mapping_to_xml( 2076 ]
2077 helpers.convert_mapping_to_xml(
2052 parent, parameter, parameter_mappings, fail_required=True) 2078 parent, parameter, parameter_mappings, fail_required=True)
2053 2079
2054 2080
@@ -2120,7 +2146,8 @@ def stash_pull_request(registry, xml_parent, data):
2120 'deletePreviousBuildFinishComments', False), 2146 'deletePreviousBuildFinishComments', False),
2121 ('cancel-outdated-jobs', 'cancelOutdatedJobsEnabled', False), 2147 ('cancel-outdated-jobs', 'cancelOutdatedJobsEnabled', False),
2122 ] 2148 ]
2123 convert_mapping_to_xml(pr_trigger, data, mappings, fail_required=True) 2149 helpers.convert_mapping_to_xml(
2150 pr_trigger, data, mappings, fail_required=True)
2124 2151
2125 2152
2126class Triggers(jenkins_jobs.modules.base.Base): 2153class Triggers(jenkins_jobs.modules.base.Base):