summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-07-15 14:04:43 +0000
committerGerrit Code Review <review@openstack.org>2020-07-15 14:04:43 +0000
commit784a38ecc9ca72c0f818ec4a25caf768e70b64dd (patch)
tree9d28aa2a8f5b0ce9cb94a2b767f9018327e47752
parent156861a149938e233d9df5ca20edc766716851ee (diff)
parent4e15ad0536992e99935c16862f0c5b64006062c5 (diff)
downloadpython-jenkins-job-builder-784a38ecc9ca72c0f818ec4a25caf768e70b64dd.tar.gz
python-jenkins-job-builder-784a38ecc9ca72c0f818ec4a25caf768e70b64dd.tar.xz
python-jenkins-job-builder-784a38ecc9ca72c0f818ec4a25caf768e70b64dd.zip
Merge "Implement disable discover_pr_origin"
-rw-r--r--jenkins_jobs/modules/project_multibranch.py25
-rw-r--r--tests/multibranch/fixtures/scm_github_no_origin_pr_discovery.xml59
-rw-r--r--tests/multibranch/fixtures/scm_github_no_origin_pr_discovery.yaml7
3 files changed, 79 insertions, 12 deletions
diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py
index 4a2923e5..49b5f8e3 100644
--- a/jenkins_jobs/modules/project_multibranch.py
+++ b/jenkins_jobs/modules/project_multibranch.py
@@ -865,7 +865,7 @@ def github_scm(xml_parent, data):
(default 'contributors')
:arg str discover-pr-origin: Discovers pull requests where the origin
repository is the same as the target repository.
- Valid options: merge-current, current, both. (default 'merge-current')
+ Valid options: merge-current, current, both, false. (default 'merge-current')
:arg bool discover-tags: Discovers tags on the repository.
(default false)
:arg list build-strategies: Provides control over whether to build a branch
@@ -1007,18 +1007,19 @@ def github_scm(xml_parent, data):
XML.SubElement(dprf, "trust").attrib["class"] = trust_map[trust]
dpro_strategy = data.get("discover-pr-origin", "merge-current")
- dpro = XML.SubElement(
- traits, "".join([github_path_dscore, ".OriginPullRequestDiscoveryTrait"])
- )
- dpro_strategy_map = {"merge-current": "1", "current": "2", "both": "3"}
- if dpro_strategy not in dpro_strategy_map:
- raise InvalidAttributeError(
- "discover-pr-origin", dpro_strategy, dpro_strategy_map.keys()
+ if dpro_strategy:
+ dpro = XML.SubElement(
+ traits, "".join([github_path_dscore, ".OriginPullRequestDiscoveryTrait"])
)
- dpro_mapping = [
- ("discover-pr-origin", "strategyId", "merge-current", dpro_strategy_map)
- ]
- helpers.convert_mapping_to_xml(dpro, data, dpro_mapping, fail_required=True)
+ dpro_strategy_map = {"merge-current": "1", "current": "2", "both": "3"}
+ if dpro_strategy not in dpro_strategy_map:
+ raise InvalidAttributeError(
+ "discover-pr-origin", dpro_strategy, dpro_strategy_map.keys()
+ )
+ dpro_mapping = [
+ ("discover-pr-origin", "strategyId", "merge-current", dpro_strategy_map)
+ ]
+ helpers.convert_mapping_to_xml(dpro, data, dpro_mapping, fail_required=True)
if data.get("head-filter-regex", None):
rshf = XML.SubElement(traits, "jenkins.scm.impl.trait.RegexSCMHeadFilterTrait")
diff --git a/tests/multibranch/fixtures/scm_github_no_origin_pr_discovery.xml b/tests/multibranch/fixtures/scm_github_no_origin_pr_discovery.xml
new file mode 100644
index 00000000..d700a816
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_github_no_origin_pr_discovery.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch">
+ <properties/>
+ <views>
+ <hudson.model.AllView>
+ <name>All</name>
+ <filterExecutors>false</filterExecutors>
+ <filterQueue>false</filterQueue>
+ <properties class="hudson.model.View$PropertyList"/>
+ <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../../.."/>
+ </hudson.model.AllView>
+ </views>
+ <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
+ <folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api">
+ <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
+ </folderViews>
+ <healthMetrics>
+ <com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder">
+ <nonRecursive>false</nonRecursive>
+ </com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
+ </healthMetrics>
+ <icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api">
+ <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
+ </icon>
+ <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder">
+ <pruneDeadBranches>true</pruneDeadBranches>
+ <daysToKeep>-1</daysToKeep>
+ <numToKeep>-1</numToKeep>
+ </orphanedItemStrategy>
+ <triggers/>
+ <sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api">
+ <data>
+ <jenkins.branch.BranchSource>
+ <source class="org.jenkinsci.plugins.github_branch_source.GitHubSCMSource" plugin="github-branch-source">
+ <id>gh-johndoe-foo</id>
+ <repoOwner>johndoe</repoOwner>
+ <repository>foo</repository>
+ <traits>
+ <org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
+ <strategyId>1</strategyId>
+ </org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
+ <org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
+ <strategyId>1</strategyId>
+ <trust class="org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustContributors"/>
+ </org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
+ <jenkins.plugins.git.traits.WipeWorkspaceTrait>
+ <extension class="hudson.plugins.git.extensions.impl.WipeWorkspace"/>
+ </jenkins.plugins.git.traits.WipeWorkspaceTrait>
+ </traits>
+ </source>
+ </jenkins.branch.BranchSource>
+ </data>
+ <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
+ </sources>
+ <factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
+ <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
+ <scriptPath>Jenkinsfile</scriptPath>
+ </factory>
+</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>
diff --git a/tests/multibranch/fixtures/scm_github_no_origin_pr_discovery.yaml b/tests/multibranch/fixtures/scm_github_no_origin_pr_discovery.yaml
new file mode 100644
index 00000000..7852137e
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_github_no_origin_pr_discovery.yaml
@@ -0,0 +1,7 @@
+name: 'demo-multibranch-github-no-fork-prs'
+project-type: multibranch
+scm:
+ - github:
+ repo: 'foo'
+ repo-owner: 'johndoe'
+ discover-pr-origin: no