Browse Source

[Triggers] Update helpers import to common style

Change-Id: Ic9f6791ab7b701e160a7d8b8ff20fe0615d222a4
Signed-off-by: Thanh Ha <zxiiro@linux.com>
tags/2.2.0
Thanh Ha 10 months ago
parent
commit
059fd49f3d
1 changed files with 71 additions and 44 deletions
  1. 71
    44
      jenkins_jobs/modules/triggers.py

+ 71
- 44
jenkins_jobs/modules/triggers.py View File

@@ -42,7 +42,7 @@ from jenkins_jobs.errors import JenkinsJobsException
42 42
 from jenkins_jobs.errors import MissingAttributeError
43 43
 import jenkins_jobs.modules.base
44 44
 from jenkins_jobs.modules import hudson_model
45
-from jenkins_jobs.modules.helpers import convert_mapping_to_xml
45
+import jenkins_jobs.modules.helpers as helpers
46 46
 
47 47
 logger = logging.getLogger(str(__name__))
48 48
 
@@ -170,8 +170,10 @@ def build_gerrit_triggers(xml_parent, data):
170 170
                 mapping = [
171 171
                     ('exclude-drafts', 'excludeDrafts', False),
172 172
                     ('exclude-trivial-rebase', 'excludeTrivialRebase', False),
173
-                    ('exclude-no-code-change', 'excludeNoCodeChange', False)]
174
-                convert_mapping_to_xml(pc, pce, mapping, fail_required=True)
173
+                    ('exclude-no-code-change', 'excludeNoCodeChange', False),
174
+                ]
175
+                helpers.convert_mapping_to_xml(
176
+                    pc, pce, mapping, fail_required=True)
175 177
 
176 178
             if 'comment-added-event' in event.keys():
177 179
                 comment_added_event = event['comment-added-event']
@@ -181,8 +183,9 @@ def build_gerrit_triggers(xml_parent, data):
181 183
                 mapping = [
182 184
                     ('approval-category', 'verdictCategory', None),
183 185
                     ('approval-value',
184
-                        'commentAddedTriggerApprovalValue', None)]
185
-                convert_mapping_to_xml(cadded,
186
+                        'commentAddedTriggerApprovalValue', None),
187
+                ]
188
+                helpers.convert_mapping_to_xml(cadded,
186 189
                     comment_added_event, mapping, fail_required=True)
187 190
 
188 191
             if 'comment-added-contains-event' in event.keys():
@@ -558,7 +561,8 @@ def gerrit(registry, xml_parent, data):
558 561
         ('readable-message', 'readableMessage', False),
559 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 566
     notification_levels = ['NONE', 'OWNER', 'OWNER_REVIEWERS', 'ALL',
563 567
                            'SERVER_DEFAULT']
564 568
     notification_level = data.get('notification-level', 'SERVER_DEFAULT')
@@ -614,7 +618,8 @@ def gerrit(registry, xml_parent, data):
614 618
         ('custom-url', 'customUrl', ''),
615 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
 
620 625
 def dockerhub_notification(registry, xml_parent, data):
@@ -874,7 +879,7 @@ def jms_messaging(registry, xml_parent, data):
874 879
         ("selector", 'selector', ''),
875 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 884
     checks = data.get('checks', [])
880 885
     if len(checks) > 0:
@@ -884,8 +889,9 @@ def jms_messaging(registry, xml_parent, data):
884 889
                                       'messaging.checks.MsgCheck')
885 890
             mapping = [
886 891
                 ('field', 'field', ''),
887
-                ('expected-value', 'expectedValue', '')]
888
-            convert_mapping_to_xml(
892
+                ('expected-value', 'expectedValue', ''),
893
+            ]
894
+            helpers.convert_mapping_to_xml(
889 895
                 msgcheck, check, mapping, fail_required=True)
890 896
 
891 897
 
@@ -1239,9 +1245,9 @@ def gitlab_merge_request(registry, xml_parent, data):
1239 1245
         ('publish-build-progress-messages', '__publishBuildProgressMessages',
1240 1246
          True),
1241 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
 
1247 1253
 def gitlab(registry, xml_parent, data):
@@ -1350,26 +1356,34 @@ def gitlab(registry, xml_parent, data):
1350 1356
     if plugin_ver >= pkg_resources.parse_version("1.1.26"):
1351 1357
         mapping = [
1352 1358
             ('trigger-open-merge-request-push',
1353
-             'triggerOpenMergeRequestOnPush', 'never', valid_merge_request)]
1354
-        convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
1359
+             'triggerOpenMergeRequestOnPush', 'never', valid_merge_request),
1360
+        ]
1361
+        helpers.convert_mapping_to_xml(
1362
+            gitlab, data, mapping, fail_required=True)
1355 1363
     else:
1356 1364
         mapping = [
1357 1365
             ('trigger-open-merge-request-push',
1358
-             'triggerOpenMergeRequestOnPush', True)]
1359
-        convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
1366
+             'triggerOpenMergeRequestOnPush', True),
1367
+        ]
1368
+        helpers.convert_mapping_to_xml(
1369
+            gitlab, data, mapping, fail_required=True)
1360 1370
 
1361 1371
     if plugin_ver < pkg_resources.parse_version('1.2.0'):
1362 1372
         if data.get('branch-filter-type', '') == 'All':
1363 1373
             data['branch-filter-type'] = ''
1364 1374
         valid_filters = ['', 'NameBasedFilter', 'RegexBasedFilter']
1365 1375
         mapping = [
1366
-            ('branch-filter-type', 'branchFilterName', '', valid_filters)]
1367
-        convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
1376
+            ('branch-filter-type', 'branchFilterName', '', valid_filters),
1377
+        ]
1378
+        helpers.convert_mapping_to_xml(
1379
+            gitlab, data, mapping, fail_required=True)
1368 1380
     else:
1369 1381
         valid_filters = ['All', 'NameBasedFilter', 'RegexBasedFilter']
1370 1382
         mapping = [
1371
-            ('branch-filter-type', 'branchFilterType', 'All', valid_filters)]
1372
-        convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
1383
+            ('branch-filter-type', 'branchFilterType', 'All', valid_filters),
1384
+        ]
1385
+        helpers.convert_mapping_to_xml(
1386
+            gitlab, data, mapping, fail_required=True)
1373 1387
 
1374 1388
     XML.SubElement(gitlab, 'spec').text = ''
1375 1389
     mapping = [
@@ -1396,7 +1410,7 @@ def gitlab(registry, xml_parent, data):
1396 1410
         ('include-branches', 'includeBranchesSpec', []),
1397 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 1415
     for yaml_name, xml_name, default_val in list_mapping:
1402 1416
         value = ', '.join(data.get(yaml_name, default_val))
@@ -1437,7 +1451,7 @@ def build_result(registry, xml_parent, data):
1437 1451
         ('cron', 'spec', ''),
1438 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 1455
     jobs_info = XML.SubElement(brt, 'jobsInfo')
1442 1456
     result_dict = {'success': 'SUCCESS',
1443 1457
                    'unstable': 'UNSTABLE',
@@ -1449,15 +1463,20 @@ def build_result(registry, xml_parent, data):
1449 1463
                               'buildresulttrigger.model.'
1450 1464
                               'BuildResultTriggerInfo')
1451 1465
         jobs_string = ",".join(group['jobs'])
1452
-        mapping = [('', 'jobNames', jobs_string, group)]
1453
-        convert_mapping_to_xml(brti, group, mapping, fail_required=True)
1466
+        mapping = [
1467
+            ('', 'jobNames', jobs_string, group),
1468
+        ]
1469
+        helpers.convert_mapping_to_xml(
1470
+            brti, group, mapping, fail_required=True)
1454 1471
         checked_results = XML.SubElement(brti, 'checkedResults')
1455 1472
         for result in group.get('results', ['success']):
1456 1473
             model_checked = XML.SubElement(checked_results, 'org.jenkinsci.'
1457 1474
                                            'plugins.buildresulttrigger.model.'
1458 1475
                                            'CheckedResult')
1459
-            mapping = [('', 'checked', result, result_dict)]
1460
-            convert_mapping_to_xml(
1476
+            mapping = [
1477
+                ('', 'checked', result, result_dict),
1478
+            ]
1479
+            helpers.convert_mapping_to_xml(
1461 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 1574
         ('path', 'path', ''),
1556 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 1579
     includes = data.get('includes', '')
1561 1580
     XML.SubElement(ft, 'includes').text = ",".join(includes)
@@ -1674,7 +1693,7 @@ def monitor_files(registry, xml_parent, data):
1674 1693
             ('strategy', 'strategy', 'LATEST', valid_strategies),
1675 1694
             ('', 'inspectingContentFile', bool(check_content)),
1676 1695
         ]
1677
-        convert_mapping_to_xml(
1696
+        helpers.convert_mapping_to_xml(
1678 1697
             file_tag, file_info, files_mapping, fail_required=True)
1679 1698
 
1680 1699
         base_content_tag = XML.SubElement(file_tag, 'contentFileTypes')
@@ -1748,7 +1767,7 @@ def ivy(registry, xml_parent, data):
1748 1767
         ('enable-concurrent', 'enableConcurrentBuild', False),
1749 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 1772
     properties_file_path = data.get('properties-file', [])
1754 1773
     XML.SubElement(it, 'propertiesFilePath').text = ";".join(
@@ -1800,7 +1819,7 @@ def script(registry, xml_parent, data):
1800 1819
         ('', 'labelRestriction', bool(label)),
1801 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
 
1806 1825
 def groovy_script(registry, xml_parent, data):
@@ -1850,7 +1869,7 @@ def groovy_script(registry, xml_parent, data):
1850 1869
         ('', 'labelRestriction', bool(label)),
1851 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
 
1856 1875
 def rabbitmq(registry, xml_parent, data):
@@ -1873,8 +1892,9 @@ def rabbitmq(registry, xml_parent, data):
1873 1892
         'RemoteBuildTrigger')
1874 1893
     mapping = [
1875 1894
         ('', 'spec', ''),
1876
-        ('token', 'remoteBuildToken', None)]
1877
-    convert_mapping_to_xml(rabbitmq, data, mapping, fail_required=True)
1895
+        ('token', 'remoteBuildToken', None),
1896
+    ]
1897
+    helpers.convert_mapping_to_xml(rabbitmq, data, mapping, fail_required=True)
1878 1898
 
1879 1899
 
1880 1900
 def parameterized_timer(parser, xml_parent, data):
@@ -1899,8 +1919,10 @@ def parameterized_timer(parser, xml_parent, data):
1899 1919
         'ParameterizedTimerTrigger')
1900 1920
     mapping = [
1901 1921
         ('', 'spec', ''),
1902
-        ('cron', 'parameterizedSpecification', None)]
1903
-    convert_mapping_to_xml(param_timer, data, mapping, fail_required=True)
1922
+        ('cron', 'parameterizedSpecification', None),
1923
+    ]
1924
+    helpers.convert_mapping_to_xml(
1925
+        param_timer, data, mapping, fail_required=True)
1904 1926
 
1905 1927
 
1906 1928
 def jira_changelog(registry, xml_parent, data):
@@ -1961,8 +1983,10 @@ def jira_changelog(registry, xml_parent, data):
1961 1983
                           'jiratrigger.JiraChangelogTrigger')
1962 1984
     jcht.set('plugin', 'jira-trigger')
1963 1985
 
1964
-    mapping = [('jql-filter', 'jqlFilter', '')]
1965
-    convert_mapping_to_xml(jcht, data, mapping, fail_required=True)
1986
+    mapping = [
1987
+        ('jql-filter', 'jqlFilter', ''),
1988
+    ]
1989
+    helpers.convert_mapping_to_xml(jcht, data, mapping, fail_required=True)
1966 1990
 
1967 1991
     changelog = XML.SubElement(jcht, 'changelogMatchers')
1968 1992
     mappings = [
@@ -1987,7 +2011,7 @@ def jira_changelog(registry, xml_parent, data):
1987 2011
                                         'JiraFieldChangelogMatcher')
1988 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 2015
             mappings, fail_required=True)
1992 2016
 
1993 2017
     param = XML.SubElement(jcht, 'parameterMappings')
@@ -1999,7 +2023,7 @@ def jira_changelog(registry, xml_parent, data):
1999 2023
         parent = XML.SubElement(param, 'com.ceilfors.jenkins.plugins.'
2000 2024
                                 'jiratrigger.parameter.'
2001 2025
                                 'IssueAttributePathParameterMapping')
2002
-        convert_mapping_to_xml(
2026
+        helpers.convert_mapping_to_xml(
2003 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 2061
     jct.set('plugin', 'jira-trigger')
2038 2062
     mapping = [
2039 2063
         ('jql-filter', 'jqlFilter', ''),
2040
-        ('comment-pattern', 'commentPattern', '(?i)build this please')]
2041
-    convert_mapping_to_xml(jct, data, mapping, fail_required=True)
2064
+        ('comment-pattern', 'commentPattern', '(?i)build this please'),
2065
+    ]
2066
+    helpers.convert_mapping_to_xml(jct, data, mapping, fail_required=True)
2042 2067
 
2043 2068
     param = XML.SubElement(jct, 'parameterMappings')
2044 2069
     for parameter in data.get('parameter-mapping', []):
@@ -2047,8 +2072,9 @@ def jira_comment_trigger(registry, xml_parent, data):
2047 2072
                                 'IssueAttributePathParameterMapping')
2048 2073
         parameter_mappings = [
2049 2074
             ('jenkins-parameter', 'jenkinsParameter', ''),
2050
-            ('issue-attribute-path', 'issueAttributePath', '')]
2051
-        convert_mapping_to_xml(
2075
+            ('issue-attribute-path', 'issueAttributePath', ''),
2076
+        ]
2077
+        helpers.convert_mapping_to_xml(
2052 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 2146
             'deletePreviousBuildFinishComments', False),
2121 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
 
2126 2153
 class Triggers(jenkins_jobs.modules.base.Base):

Loading…
Cancel
Save