Merge "Add filter-by-name-wildcard to scm_github multibranch plugin."

This commit is contained in:
Zuul 2021-06-17 20:20:49 +00:00 committed by Gerrit Code Review
commit 15b46e316f
3 changed files with 119 additions and 16 deletions

View File

@ -621,22 +621,7 @@ def bitbucket_scm(xml_parent, data):
cossh, data.get("checkout-over-ssh"), cossh_credentials, fail_required=True
)
if data.get("filter-by-name-wildcard", None):
wscmf_name = XML.SubElement(
traits,
"jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait",
{"plugin": "scm-api"},
)
wscmf_name_mapping = [
("includes", "includes", ""),
("excludes", "excludes", ""),
]
helpers.convert_mapping_to_xml(
wscmf_name,
data.get("filter-by-name-wildcard", ""),
wscmf_name_mapping,
fail_required=True,
)
add_filter_by_name_wildcard_behaviors(traits, data)
# handle the default git extensions like:
# - clean
@ -943,6 +928,15 @@ def github_scm(xml_parent, data):
(like to disable SCM triggering or to override the pipeline durability)
(optional)
Refer to :func:`~property_strategies <property_strategies>`.
:arg dict filter-by-name-wildcard: Enable filter by name with wildcards.
Requires the :jenkins-plugins:`SCM API Plugin <scm-api>`.
* **includes** ('str'): Space-separated list
of name patterns to consider. You may use * as a wildcard;
for example: `master release*`
* **excludes** ('str'): Name patterns to
ignore even if matched by the includes list.
For example: `release*`
:extensions:
@ -1110,6 +1104,8 @@ def github_scm(xml_parent, data):
XML.SubElement(rshf, "contextLabel").text = data.get("notification-context")
XML.SubElement(rshf, "typeSuffix").text = "true"
add_filter_by_name_wildcard_behaviors(traits, data)
# handle the default git extensions like:
# - clean
# - shallow-clone
@ -1766,3 +1762,34 @@ def add_filter_branch_pr_behaviors(traits, data):
wildcard_mapping,
fail_required=True,
)
def add_filter_by_name_wildcard_behaviors(traits, data):
"""Configure branch filtering behaviors.
:arg dict filter-by-name-wildcard: Enable filter by name with wildcards.
Requires the :jenkins-plugins:`SCM API Plugin <scm-api>`.
* **includes** ('str'): Space-separated list
of name patterns to consider. You may use * as a wildcard;
for example: `master release*`
* **excludes** ('str'): Name patterns to
ignore even if matched by the includes list.
For example: `release*`
"""
if data.get("filter-by-name-wildcard", None):
wscmf_name = XML.SubElement(
traits,
"jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait",
{"plugin": "scm-api"},
)
wscmf_name_mapping = [
("includes", "includes", ""),
("excludes", "excludes", ""),
]
helpers.convert_mapping_to_xml(
wscmf_name,
data.get("filter-by-name-wildcard", ""),
wscmf_name_mapping,
fail_required=True,
)

View File

@ -0,0 +1,66 @@
<?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>
<org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
<strategyId>1</strategyId>
</org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
<jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait plugin="scm-api">
<includes>includes-branch-*</includes>
<excludes>excludes-branch-*</excludes>
</jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait>
<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>

View File

@ -0,0 +1,10 @@
name: 'demo-multibranch-github-min'
project-type: multibranch
scm:
- github:
repo: 'foo'
repo-owner: 'johndoe'
filter-by-name-wildcard:
includes: includes-branch-*
excludes: excludes-branch-*