Update ircbot plugin

- update ircbot plugin to convert xml
- update docstring
- add plugin='ircbot' attribute
- update test cases

Change-Id: I3d061a5b5d0dd0315a019703c6b269c80a8fdec6
This commit is contained in:
Dong Ma 2017-06-17 15:47:45 +08:00
parent bd0c1f33b8
commit 9a6aea1ca1
7 changed files with 76 additions and 90 deletions

View File

@ -4070,21 +4070,16 @@ def ircbot(registry, xml_parent, data):
* **new-failure-and-fixed** on new failure and fixes
* **statechange-only** only on state change
:arg bool notify-start: Whether to send notifications to channels when a
build starts
(default false)
build starts (default false)
:arg bool notify-committers: Whether to send notifications to the users
that are suspected of having broken this build
(default false)
that are suspected of having broken this build (default false)
:arg bool notify-culprits: Also send notifications to 'culprits' from
previous unstable/failed builds
(default false)
previous unstable/failed builds (default false)
:arg bool notify-upstream: Whether to send notifications to upstream
committers if no committers were found for a
broken build
(default false)
committers if no committers were found for a broken build
(default false)
:arg bool notify-fixers: Whether to send notifications to the users that
have fixed a broken build
(default false)
have fixed a broken build (default false)
:arg string message-type: Channel Notification Message.
:message-type values:
@ -4093,32 +4088,38 @@ def ircbot(registry, xml_parent, data):
* **summary-params** for summary and build parameters
* **summary-scm-fail** for summary, SCM changes, failures)
:arg list channels: list channels definitions
If empty, it takes channel from Jenkins configuration.
(default empty)
WARNING: the IRC plugin requires the channel to be
configured in the system wide configuration or the jobs
will fail to emit notifications to the channel
If empty, it takes channel from Jenkins configuration.
(default empty)
WARNING: the IRC plugin requires the channel to be configured in the
system wide configuration or the jobs will fail to emit notifications
to the channel
:Channel: * **name** (`str`) Channel name
* **password** (`str`) Channel password (optional)
* **notify-only** (`bool`) Set to true if you want to
disallow bot commands (default false)
:arg string matrix-notifier: notify for matrix projects
instant-messaging-plugin injects an additional
field in the configuration form whenever the
project is a multi-configuration project
instant-messaging-plugin injects an additional
field in the configuration form whenever the
project is a multi-configuration project
:matrix-notifier values:
* **all**
* **only-configurations** (default)
* **only-parent**
Example:
Minimal Example:
.. literalinclude:: /../../tests/publishers/fixtures/ircbot001.yaml
.. literalinclude:: /../../tests/publishers/fixtures/ircbot-minimal.yaml
:language: yaml
Full Example:
.. literalinclude:: /../../tests/publishers/fixtures/ircbot-full.yaml
:language: yaml
"""
top = XML.SubElement(xml_parent, 'hudson.plugins.ircbot.IrcPublisher')
top.set('plugin', 'ircbot')
message_dict = {'summary-scm': 'DefaultBuildToChatNotifier',
'summary': 'SummaryOnlyBuildToChatNotifier',
'summary-params': 'BuildParametersBuildToChatNotifier',
@ -4130,45 +4131,39 @@ def ircbot(registry, xml_parent, data):
", ".join(message_dict.keys()))
message = "hudson.plugins.im.build_notify." + message_dict.get(message)
XML.SubElement(top, 'buildToChatNotifier', attrib={'class': message})
strategy_dict = {'all': 'ALL',
'any-failure': 'ANY_FAILURE',
'failure-and-fixed': 'FAILURE_AND_FIXED',
'new-failure-and-fixed': 'NEW_FAILURE_AND_FIXED',
'statechange-only': 'STATECHANGE_ONLY'}
strategy = data.get('strategy', 'all')
if strategy not in strategy_dict:
raise JenkinsJobsException("strategy entered is not valid, must be "
"one of: %s" %
", ".join(strategy_dict.keys()))
XML.SubElement(top, 'strategy').text = strategy_dict.get(strategy)
targets = XML.SubElement(top, 'targets')
channels = data.get('channels', [])
for channel in channels:
sub = XML.SubElement(targets,
'hudson.plugins.im.GroupChatIMMessageTarget')
XML.SubElement(sub, 'name').text = channel.get('name')
XML.SubElement(sub, 'password').text = channel.get('password')
XML.SubElement(sub, 'notificationOnly').text = str(
channel.get('notify-only', False)).lower()
XML.SubElement(top, 'notifyOnBuildStart').text = str(
data.get('notify-start', False)).lower()
XML.SubElement(top, 'notifySuspects').text = str(
data.get('notify-committers', False)).lower()
XML.SubElement(top, 'notifyCulprits').text = str(
data.get('notify-culprits', False)).lower()
XML.SubElement(top, 'notifyFixers').text = str(
data.get('notify-fixers', False)).lower()
XML.SubElement(top, 'notifyUpstreamCommitters').text = str(
data.get('notify-upstream', False)).lower()
sub_mappings = [
('name', 'name', ''),
('password', 'password', ''),
('notify-only', 'notificationOnly', False)
]
helpers.convert_mapping_to_xml(
sub, channel, sub_mappings, fail_required=True)
strategy_dict = {'all': 'ALL',
'any-failure': 'ANY_FAILURE',
'failure-and-fixed': 'FAILURE_AND_FIXED',
'new-failure-and-fixed': 'NEW_FAILURE_AND_FIXED',
'statechange-only': 'STATECHANGE_ONLY'}
matrix_dict = {'all': 'ALL',
'only-configurations': 'ONLY_CONFIGURATIONS',
'only-parent': 'ONLY_PARENT'}
matrix = data.get('matrix-notifier', 'only-configurations')
if matrix not in matrix_dict:
raise JenkinsJobsException("matrix-notifier entered is not valid, "
"must be one of: %s" %
", ".join(matrix_dict.keys()))
XML.SubElement(top, 'matrixMultiplier').text = matrix_dict.get(matrix)
mappings = [
('strategy', 'strategy', 'all', strategy_dict),
('notify-start', 'notifyOnBuildStart', False),
('notify-committers', 'notifySuspects', False),
('notify-culprits', 'notifyCulprits', False),
('notify-fixers', 'notifyFixers', False),
('notify-upstream', 'notifyUpstreamCommitters', False),
('matrix-notifier',
'matrixMultiplier',
'only-configurations',
matrix_dict)
]
helpers.convert_mapping_to_xml(top, data, mappings, fail_required=True)
def plot(registry, xml_parent, data):

View File

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.ircbot.IrcPublisher>
<buildToChatNotifier class="hudson.plugins.im.build_notify.DefaultBuildToChatNotifier"/>
<strategy>ALL</strategy>
<hudson.plugins.ircbot.IrcPublisher plugin="ircbot">
<buildToChatNotifier class="hudson.plugins.im.build_notify.SummaryOnlyBuildToChatNotifier"/>
<targets>
<hudson.plugins.im.GroupChatIMMessageTarget>
<name>#jenkins-channel1</name>
@ -16,12 +15,13 @@
<notificationOnly>true</notificationOnly>
</hudson.plugins.im.GroupChatIMMessageTarget>
</targets>
<notifyOnBuildStart>false</notifyOnBuildStart>
<notifySuspects>false</notifySuspects>
<notifyCulprits>false</notifyCulprits>
<notifyFixers>false</notifyFixers>
<notifyUpstreamCommitters>false</notifyUpstreamCommitters>
<matrixMultiplier>ONLY_CONFIGURATIONS</matrixMultiplier>
<strategy>FAILURE_AND_FIXED</strategy>
<notifyOnBuildStart>true</notifyOnBuildStart>
<notifySuspects>true</notifySuspects>
<notifyCulprits>true</notifyCulprits>
<notifyFixers>true</notifyFixers>
<notifyUpstreamCommitters>true</notifyUpstreamCommitters>
<matrixMultiplier>ALL</matrixMultiplier>
</hudson.plugins.ircbot.IrcPublisher>
</publishers>
</project>

View File

@ -0,0 +1,16 @@
publishers:
- ircbot:
strategy: failure-and-fixed
notify-start: true
notify-committers: true
notify-culprits: true
notify-upstream: true
notify-fixers: true
message-type: summary
channels:
- name: '#jenkins-channel1'
password: secrete
notify-only: false
- name: '#jenkins-channel2'
notify-only: true
matrix-notifier: all

View File

@ -1,16 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.ircbot.IrcPublisher>
<hudson.plugins.ircbot.IrcPublisher plugin="ircbot">
<buildToChatNotifier class="hudson.plugins.im.build_notify.DefaultBuildToChatNotifier"/>
<targets/>
<strategy>ALL</strategy>
<targets>
<hudson.plugins.im.GroupChatIMMessageTarget>
<name>#jenkins-channel</name>
<password/>
<notificationOnly>true</notificationOnly>
</hudson.plugins.im.GroupChatIMMessageTarget>
</targets>
<notifyOnBuildStart>false</notifyOnBuildStart>
<notifySuspects>false</notifySuspects>
<notifyCulprits>false</notifyCulprits>

View File

@ -0,0 +1,2 @@
publishers:
- ircbot

View File

@ -1,16 +0,0 @@
publishers:
- ircbot:
strategy: all
notify-start: false
notify-committers: false
notify-culprits: false
notify-upstream: false
notify-fixers: false
message-type: summary-scm
channels:
- name: '#jenkins-channel1'
password: secrete
notify-only: false
- name: '#jenkins-channel2'
notify-only: true
matrix-notifier: only-configurations

View File

@ -1,5 +0,0 @@
publishers:
- ircbot:
channels:
- name: '#jenkins-channel'
notify-only: true