From f97acb632a508c9f572894da3de7c338019accbd Mon Sep 17 00:00:00 2001 From: Yolande Amate Date: Sun, 25 Jun 2017 17:25:04 +0100 Subject: [PATCH] Update flowdock to use convert_mapping_to_xml() Change-Id: I70588de4912ea0dbd11ca28c5af2b4f2c78899bd --- jenkins_jobs/modules/publishers.py | 40 +++++++++-------------- tests/publishers/fixtures/flowdock001.xml | 12 +++---- tests/publishers/fixtures/flowdock002.xml | 12 +++---- tests/publishers/fixtures/flowdock003.xml | 12 +++---- 4 files changed, 33 insertions(+), 43 deletions(-) diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 9b652f32e..1e29452ab 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -6293,28 +6293,26 @@ def flowdock(registry, xml_parent, data): .. literalinclude:: /../../tests/publishers/fixtures/flowdock002.yaml :language: yaml """ - def gen_notification_entry(data_item, default, text): e = XML.SubElement(nm, 'entry') - XML.SubElement(e, 'com.flowdock.jenkins.BuildResult').text = text - XML.SubElement(e, 'boolean').text = str( - data.get(data_item, default)).lower() - - def gen_setting(item, default): - XML.SubElement(parent, 'notify%s' % item).text = str( - data.get('notify-%s' % item.lower(), default)).lower() - - # Raise exception if token was not specified - if 'token' not in data: - raise MissingAttributeError('token') + mapping = [ + ('', 'com.flowdock.jenkins.BuildResult', text), + (data_item, 'boolean', default)] + helpers.convert_mapping_to_xml(e, data, mapping, fail_required=True) parent = XML.SubElement(xml_parent, 'com.flowdock.jenkins.FlowdockNotifier') - - XML.SubElement(parent, 'flowToken').text = data['token'] - XML.SubElement(parent, 'notificationTags').text = data.get('tags', '') - XML.SubElement(parent, 'chatNotification').text = str( - data.get('chat-notification', True)).lower() + mapping = [ + ('token', 'flowToken', None), + ('tags', 'notificationTags', ''), + ('chat-notification', 'chatNotification', True), + ('notify-success', 'notifySuccess', True), + ('notify-failure', 'notifyFailure', True), + ('notify-fixed', 'notifyFixed', True), + ('notify-unstable', 'notifyUnstable', False), + ('notify-aborted', 'notifyAborted', False), + ('notify-notbuilt', 'notifyNotBuilt', False)] + helpers.convert_mapping_to_xml(parent, data, mapping, fail_required=True) nm = XML.SubElement(parent, 'notifyMap') @@ -6326,14 +6324,6 @@ def flowdock(registry, xml_parent, data): gen_notification_entry('notify-aborted', False, 'ABORTED') gen_notification_entry('notify-notbuilt', False, 'NOT_BUILT') - # notification settings - gen_setting('Success', True) - gen_setting('Failure', True) - gen_setting('Fixed', True) - gen_setting('Unstable', False) - gen_setting('Aborted', False) - gen_setting('NotBuilt', False) - def clamav(registry, xml_parent, data): """yaml: clamav diff --git a/tests/publishers/fixtures/flowdock001.xml b/tests/publishers/fixtures/flowdock001.xml index 15642fad4..83348441c 100644 --- a/tests/publishers/fixtures/flowdock001.xml +++ b/tests/publishers/fixtures/flowdock001.xml @@ -5,6 +5,12 @@ abcdefghijklmnopqrstuvwxyzabcdef true + true + true + true + false + false + false SUCCESS @@ -31,12 +37,6 @@ false - true - true - true - false - false - false diff --git a/tests/publishers/fixtures/flowdock002.xml b/tests/publishers/fixtures/flowdock002.xml index 5cfba6da5..1d8b24299 100644 --- a/tests/publishers/fixtures/flowdock002.xml +++ b/tests/publishers/fixtures/flowdock002.xml @@ -5,6 +5,12 @@ abcdefghijklmnopqrstuvwxyzabcdef jenkins,ci true + true + true + true + false + false + false SUCCESS @@ -31,12 +37,6 @@ false - true - true - true - false - false - false diff --git a/tests/publishers/fixtures/flowdock003.xml b/tests/publishers/fixtures/flowdock003.xml index 700a78e57..6100fccaa 100644 --- a/tests/publishers/fixtures/flowdock003.xml +++ b/tests/publishers/fixtures/flowdock003.xml @@ -5,6 +5,12 @@ abcdefghijklmnopqrstuvwxyzabcdef jenkins,ci false + false + false + false + true + true + true SUCCESS @@ -31,12 +37,6 @@ true - false - false - false - true - true - true