From c20570f9d6dff6346bd14415606b45706a5ea455 Mon Sep 17 00:00:00 2001 From: Somay Jain Date: Fri, 10 Jul 2015 15:21:07 +0530 Subject: [PATCH] Support for repo-depth and ignore-externals in svn plugin Change-Id: I5f35536a936bde33b0a8c710b28ac5e81fcc6c8b --- jenkins_jobs/modules/scm.py | 41 ++++++++++++------- tests/scm/fixtures/svn-multiple-repos-001.xml | 4 ++ .../scm/fixtures/svn-multiple-repos-001.yaml | 2 + tests/scm/fixtures/svn-regions-001.xml | 2 + tests/scm/fixtures/svn-regions-001.yaml | 2 + 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py index 7f54a27a5..a442cd736 100644 --- a/jenkins_jobs/modules/scm.py +++ b/jenkins_jobs/modules/scm.py @@ -39,7 +39,8 @@ Example of an empty ``scm``: import logging import xml.etree.ElementTree as XML import jenkins_jobs.modules.base -from jenkins_jobs.errors import JenkinsJobsException +from jenkins_jobs.errors import (InvalidAttributeError, + JenkinsJobsException) def git(parser, xml_parent, data): @@ -499,6 +500,9 @@ def svn(parser, xml_parent, data): (default '.') :arg str credentials-id: optional argument to specify the ID of credentials to use + :arg str repo-depth: Repository depth. Can be one of 'infinity', 'empty', + 'files', 'immediates' or 'unknown'. (default 'infinity') + :arg bool ignore-externals: Ignore Externals. (default false) :arg str workspaceupdater: optional argument to specify how to update the workspace (default wipeworkspace) :arg list(str) excluded-users: list of users to ignore revisions from @@ -518,8 +522,12 @@ def svn(parser, xml_parent, data): :Repo: * **url** (`str`) -- URL for the repository * **basedir** (`str`) -- Location relative to the workspace - root to checkout to (default '.') + root to checkout to (default '.') * **credentials-id** - optional ID of credentials to use + * **repo-depth** - Repository depth. Can be one of 'infinity', + 'empty', 'files', 'immediates' or 'unknown'. + (default 'infinity') + * **ignore-externals** - Ignore Externals. (default false) :workspaceupdater values: :wipeworkspace: - deletes the workspace before checking out @@ -538,24 +546,29 @@ def svn(parser, xml_parent, data): scm = XML.SubElement(xml_parent, 'scm', {'class': 'hudson.scm.SubversionSCM'}) locations = XML.SubElement(scm, 'locations') - if 'repos' in data: - repos = data['repos'] - for repo in repos: - module = XML.SubElement(locations, - 'hudson.scm.SubversionSCM_-ModuleLocation') - XML.SubElement(module, 'remote').text = repo['url'] - XML.SubElement(module, 'local').text = repo.get('basedir', '.') - if 'credentials-id' in repo: - XML.SubElement(module, 'credentialsId').text = repo[ - 'credentials-id'] - elif 'url' in data: - module = XML.SubElement(locations, + + def populate_repo_xml(parent, data): + module = XML.SubElement(parent, 'hudson.scm.SubversionSCM_-ModuleLocation') XML.SubElement(module, 'remote').text = data['url'] XML.SubElement(module, 'local').text = data.get('basedir', '.') if 'credentials-id' in data: XML.SubElement(module, 'credentialsId').text = data[ 'credentials-id'] + repo_depths = ['infinity', 'empty', 'files', 'immediates', 'unknown'] + repo_depth = data.get('repo-depth', 'infinity') + if repo_depth not in repo_depths: + raise InvalidAttributeError('repo_depth', repo_depth, repo_depths) + XML.SubElement(module, 'depthOption').text = repo_depth + XML.SubElement(module, 'ignoreExternalsOption').text = str( + data.get('ignore-externals', False)).lower() + + if 'repos' in data: + repos = data['repos'] + for repo in repos: + populate_repo_xml(locations, repo) + elif 'url' in data: + populate_repo_xml(locations, data) else: raise JenkinsJobsException("A top level url or repos list must exist") updater = data.get('workspaceupdater', 'wipeworkspace') diff --git a/tests/scm/fixtures/svn-multiple-repos-001.xml b/tests/scm/fixtures/svn-multiple-repos-001.xml index d75139ddb..5422c58f8 100644 --- a/tests/scm/fixtures/svn-multiple-repos-001.xml +++ b/tests/scm/fixtures/svn-multiple-repos-001.xml @@ -6,10 +6,14 @@ http://svn.example.com/repo . abcdef01234567890 + files + true http://svn.example.com/repo2 repo2 + infinity + false diff --git a/tests/scm/fixtures/svn-multiple-repos-001.yaml b/tests/scm/fixtures/svn-multiple-repos-001.yaml index 66441d96e..78adc52f5 100644 --- a/tests/scm/fixtures/svn-multiple-repos-001.yaml +++ b/tests/scm/fixtures/svn-multiple-repos-001.yaml @@ -5,5 +5,7 @@ scm: - url: http://svn.example.com/repo basedir: . credentials-id: "abcdef01234567890" + repo-depth: files + ignore-externals: true - url: http://svn.example.com/repo2 basedir: repo2 diff --git a/tests/scm/fixtures/svn-regions-001.xml b/tests/scm/fixtures/svn-regions-001.xml index 544f1d1e1..e61dfc738 100644 --- a/tests/scm/fixtures/svn-regions-001.xml +++ b/tests/scm/fixtures/svn-regions-001.xml @@ -6,6 +6,8 @@ http://svn.apache.org/repos/asf/spamassassin/trunk . abcdef01234567890 + empty + true diff --git a/tests/scm/fixtures/svn-regions-001.yaml b/tests/scm/fixtures/svn-regions-001.yaml index 2fddbebab..ccaa70656 100644 --- a/tests/scm/fixtures/svn-regions-001.yaml +++ b/tests/scm/fixtures/svn-regions-001.yaml @@ -2,6 +2,8 @@ scm: - svn: url: http://svn.apache.org/repos/asf/spamassassin/trunk credentials-id: "abcdef01234567890" + repo-depth: empty + ignore-externals: true workspaceupdater: wipeworkspace included-regions: - /region1/.*\.cpp