From 0bdd8199697546bd022b09630d59500bf2e05fc9 Mon Sep 17 00:00:00 2001 From: Dong Ma Date: Sun, 13 Nov 2016 19:23:05 -0800 Subject: [PATCH] Update jabber plugin - update jabber plugin to use convert xml - add plugin="jabber" and plugin="instant-messaging" attribute - update test cases - add new notification strategy option Change-Id: I221f75f30e611ca206041be6f9a86e4075f6bb8d --- jenkins_jobs/modules/publishers.py | 35 ++++++++++++------- .../{jabber001.xml => jabber-complete.xml} | 18 +++++----- .../{jabber001.yaml => jabber-complete.yaml} | 8 +++-- tests/publishers/fixtures/jabber-minimal.xml | 16 +++++++++ tests/publishers/fixtures/jabber-minimal.yaml | 2 ++ 5 files changed, 56 insertions(+), 23 deletions(-) rename tests/publishers/fixtures/{jabber001.xml => jabber-complete.xml} (56%) rename tests/publishers/fixtures/{jabber001.yaml => jabber-complete.yaml} (52%) create mode 100644 tests/publishers/fixtures/jabber-minimal.xml create mode 100644 tests/publishers/fixtures/jabber-minimal.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 1cd145277..d55c60795 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -2767,6 +2767,7 @@ def jabber(registry, xml_parent, data): * **all** -- Always * **failure** -- On any failure * **failure-fixed** -- On failure and fixes + * **new-failure-fixed** -- On new failure and fixes * **change** -- Only on state change :arg dict message: Channel notification message (default summary-scm) @@ -2776,45 +2777,55 @@ def jabber(registry, xml_parent, data): * **summary-build** -- Summary and build parameters * **summary-scm-fail** -- Summary, SCM changes, and failed tests - Example: + Minimal Example: - .. literalinclude:: /../../tests/publishers/fixtures/jabber001.yaml + .. literalinclude:: /../../tests/publishers/fixtures/jabber-minimal.yaml + :language: yaml + + Full Example: + + .. literalinclude:: /../../tests/publishers/fixtures/jabber-complete.yaml :language: yaml """ j = XML.SubElement(xml_parent, 'hudson.plugins.jabber.im.transport.' 'JabberPublisher') + j.set('plugin', 'jabber') + t = XML.SubElement(j, 'targets') if 'group-targets' in data: for group in data['group-targets']: gcimt = XML.SubElement(t, 'hudson.plugins.im.' 'GroupChatIMMessageTarget') + gcimt.set('plugin', 'instant-messaging') XML.SubElement(gcimt, 'name').text = group XML.SubElement(gcimt, 'notificationOnly').text = 'false' if 'individual-targets' in data: for individual in data['individual-targets']: dimt = XML.SubElement(t, 'hudson.plugins.im.' 'DefaultIMMessageTarget') + dimt.set('plugin', 'instant-messaging') XML.SubElement(dimt, 'value').text = individual strategy = data.get('strategy', 'all') strategydict = {'all': 'ALL', 'failure': 'ANY_FAILURE', 'failure-fixed': 'FAILURE_AND_FIXED', + 'new-failure-fixed': 'NEW_FAILURE_AND_FIXED', 'change': 'STATECHANGE_ONLY'} if strategy not in strategydict: raise JenkinsJobsException("Strategy entered is not valid, must be " + "one of: all, failure, failure-fixed, or " "change") XML.SubElement(j, 'strategy').text = strategydict[strategy] - XML.SubElement(j, 'notifyOnBuildStart').text = str( - data.get('notify-on-build-start', False)).lower() - XML.SubElement(j, 'notifySuspects').text = str( - data.get('notify-scm-committers', False)).lower() - XML.SubElement(j, 'notifyCulprits').text = str( - data.get('notify-scm-culprits', False)).lower() - XML.SubElement(j, 'notifyFixers').text = str( - data.get('notify-scm-fixers', False)).lower() - XML.SubElement(j, 'notifyUpstreamCommitters').text = str( - data.get('notify-upstream-committers', False)).lower() + + mappings = [ + ('notify-on-build-start', 'notifyOnBuildStart', False), + ('notify-scm-committers', 'notifySuspects', False), + ('notify-scm-culprits', 'notifyCulprits', False), + ('notify-scm-fixers', 'notifyFixers', False), + ('notify-upstream-committers', 'notifyUpstreamCommitters', False) + ] + helpers.convert_mapping_to_xml(j, data, mappings, fail_required=True) + message = data.get('message', 'summary-scm') messagedict = {'summary-scm': 'DefaultBuildToChatNotifier', 'summary': 'SummaryOnlyBuildToChatNotifier', diff --git a/tests/publishers/fixtures/jabber001.xml b/tests/publishers/fixtures/jabber-complete.xml similarity index 56% rename from tests/publishers/fixtures/jabber001.xml rename to tests/publishers/fixtures/jabber-complete.xml index 409e1a0c2..a9f091347 100644 --- a/tests/publishers/fixtures/jabber001.xml +++ b/tests/publishers/fixtures/jabber-complete.xml @@ -1,23 +1,23 @@ - + - + foo-room@conference-2-fooserver.foo.com false - + foo-user@conference-2-fooserver.foo.com - ALL + NEW_FAILURE_AND_FIXED true - false - false - false - false - + true + true + true + true + ONLY_CONFIGURATIONS diff --git a/tests/publishers/fixtures/jabber001.yaml b/tests/publishers/fixtures/jabber-complete.yaml similarity index 52% rename from tests/publishers/fixtures/jabber001.yaml rename to tests/publishers/fixtures/jabber-complete.yaml index 31735f9af..a2da5701a 100644 --- a/tests/publishers/fixtures/jabber001.yaml +++ b/tests/publishers/fixtures/jabber-complete.yaml @@ -1,9 +1,13 @@ publishers: - jabber: notify-on-build-start: true + notify-scm-committers: true + notify-scm-culprits: true + notify-upstream-committers: true + notify-scm-fixers: true group-targets: - "foo-room@conference-2-fooserver.foo.com" individual-targets: - "foo-user@conference-2-fooserver.foo.com" - strategy: all - message: summary-scm + strategy: new-failure-fixed + message: summary diff --git a/tests/publishers/fixtures/jabber-minimal.xml b/tests/publishers/fixtures/jabber-minimal.xml new file mode 100644 index 000000000..4f0ddb288 --- /dev/null +++ b/tests/publishers/fixtures/jabber-minimal.xml @@ -0,0 +1,16 @@ + + + + + + ALL + false + false + false + false + false + + ONLY_CONFIGURATIONS + + + diff --git a/tests/publishers/fixtures/jabber-minimal.yaml b/tests/publishers/fixtures/jabber-minimal.yaml new file mode 100644 index 000000000..9e97534c7 --- /dev/null +++ b/tests/publishers/fixtures/jabber-minimal.yaml @@ -0,0 +1,2 @@ +publishers: + - jabber