Update monitor_files to use convert_xml()

Also update tests to have a minimal & full tests.

Change-Id: Id2b57492c5cc43634df48deefb9eca00a3713b99
Co-Authored-By: Thanh Ha <thanh.ha@linuxfoundation.org>
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
This commit is contained in:
Yolande Amate 2017-07-11 01:48:39 +01:00 committed by Sorin Sbarnea
parent c6df0adc44
commit e70f327a9e
5 changed files with 36 additions and 14 deletions

View File

@ -1607,9 +1607,16 @@ def monitor_files(registry, xml_parent, data):
are being monitored. (default true)
:arg str cron: cron syntax of when to run (default '')
Example:
Minimal Example:
.. literalinclude:: /../../tests/triggers/fixtures/monitor-files001.yaml
.. literalinclude::
/../../tests/triggers/fixtures/monitor-files-minimal.yaml
:language: yaml
Full Example:
.. literalinclude::
/../../tests/triggers/fixtures/monitor-files-full.yaml
:language: yaml
"""
ft_prefix = 'org.jenkinsci.plugins.fstrigger.triggers.'
@ -1635,19 +1642,14 @@ def monitor_files(registry, xml_parent, data):
files_tag = XML.SubElement(ft, 'fileInfo')
for file_info in files:
file_tag = XML.SubElement(files_tag, ft_prefix + 'FileNameTriggerInfo')
try:
XML.SubElement(file_tag,
'filePathPattern').text = file_info['path']
except KeyError:
raise MissingAttributeError('path')
strategy = file_info.get('strategy', 'LATEST')
if strategy not in valid_strategies:
raise InvalidAttributeError('strategy', strategy, valid_strategies)
XML.SubElement(file_tag, 'strategy').text = strategy
check_content = file_info.get('check-content', [])
XML.SubElement(file_tag, 'inspectingContentFile').text = str(
bool(check_content)).lower()
files_mapping = [
('path', 'filePathPattern', None),
('strategy', 'strategy', 'LATEST', valid_strategies),
('', 'inspectingContentFile', bool(check_content)),
]
convert_mapping_to_xml(
file_tag, file_info, files_mapping, fail_required=True)
base_content_tag = XML.SubElement(file_tag, 'contentFileTypes')
for content in check_content:

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
<org.jenkinsci.plugins.fstrigger.triggers.FileNameTrigger>
<spec/>
<fileInfo>
<org.jenkinsci.plugins.fstrigger.triggers.FileNameTriggerInfo>
<filePathPattern>path1</filePathPattern>
<strategy>LATEST</strategy>
<inspectingContentFile>false</inspectingContentFile>
<contentFileTypes/>
</org.jenkinsci.plugins.fstrigger.triggers.FileNameTriggerInfo>
</fileInfo>
</org.jenkinsci.plugins.fstrigger.triggers.FileNameTrigger>
</triggers>
</project>

View File

@ -0,0 +1,4 @@
triggers:
- monitor-files:
files:
- path: 'path1'