Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace usage of deprecated properties by traits #1144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BranchSourcesContext extends AbstractExtensibleContext {
*
* @since 1.46
*/
@RequiresPlugin(id = 'github-branch-source', minimumVersion = '1.8')
@RequiresPlugin(id = 'github-branch-source', minimumVersion = '2.2.0')
void github(@DslContext(GitHubBranchSourceContext) Closure branchSourceClosure) {
GitHubBranchSourceContext context = new GitHubBranchSourceContext(jobManagement)
ContextHelper.executeInContext(branchSourceClosure, context)
Expand All @@ -55,18 +55,54 @@ class BranchSourcesContext extends AbstractExtensibleContext {
if (context.apiUri) {
apiUri(context.apiUri)
}
scanCredentialsId(context.scanCredentialsId ?: '')
checkoutCredentialsId(context.checkoutCredentialsId ?: '')
credentialsId(context.scanCredentialsId ?: '')
repoOwner(context.repoOwner ?: '')
repository(context.repository ?: '')
includes(context.includes ?: '')
excludes(context.excludes ?: '')
buildOriginBranch(context.buildOriginBranch)
buildOriginBranchWithPR(context.buildOriginBranchWithPR)
buildOriginPRMerge(context.buildOriginPRMerge)
buildOriginPRHead(context.buildOriginPRHead)
buildForkPRMerge(context.buildForkPRMerge)
buildForkPRHead(context.buildForkPRHead)
traits {
if (context.buildOriginBranch || context.buildOriginBranchWithPR) {
'org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait' {
strategyId((context.buildOriginBranch ? 1 : 0) + (context.buildOriginBranchWithPR ? 2 : 0))
}
}
if (context.buildOriginPRMerge || context.buildOriginPRHead) {
'org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait' {
strategyId((context.buildOriginPRMerge ? 1 : 0) + (context.buildOriginPRHead ? 2 : 0))
}
}
if (context.buildForkPRMerge || context.buildForkPRHead) {
'org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait' {
strategyId((context.buildForkPRMerge ? 1 : 0) + (context.buildForkPRHead ? 2 : 0))
trust(class:
'org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustPermission')
}
}
if (context.checkoutCredentialsId != null &&
'SAME' != context.scanCredentialsId &&
context.checkoutCredentialsId != context.scanCredentialsId) {
'org.jenkinsci.plugins.github__branch__source.SSHCheckoutTrait' {
credentialsId(context.checkoutCredentialsId)
}
}
if ((context.includes != null && '*' != context.includes) ||
(context.excludes != null && '' != context.excludes)) {
'jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait' {
includes(context.includes ?: '*')
excludes(context.excludes ?: '')
}
}
if (context.pattern != null && '.*' != context.pattern) {
'jenkins.scm.impl.trait.RegexSCMSourceFilterTrait' {
regex(context.pattern)
}
}
if (!context.noTags) {
'jenkins.plugins.git.traits.CloneOptionTrait' {
extension(class: 'hudson.plugins.git.extensions.impl.CloneOption') {
noTags(context.noTags)
}
}
}
}
}
strategy(class: 'jenkins.branch.DefaultBranchPropertyStrategy') {
properties(class: 'empty-list')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ class GitHubBranchSourceContext extends AbstractContext {
String repository
String includes = '*'
String excludes
String pattern = '.*'
boolean buildOriginBranch = true
boolean buildOriginBranchWithPR = true
boolean buildOriginPRMerge = false
boolean buildOriginPRHead = false
boolean buildForkPRMerge = true
boolean buildForkPRHead = false
boolean noTags = true

GitHubBranchSourceContext(JobManagement jobManagement) {
super(jobManagement)
Expand Down Expand Up @@ -81,6 +83,15 @@ class GitHubBranchSourceContext extends AbstractContext {
this.excludes = excludes
}

/**
* Regex for project names to include. Defaults to {@code .*}.
*
* @since 1.71
*/
void pattern(String pattern) {
this.pattern = pattern
}

/**
* Build origin branches. Defaults to {@code true}.
*
Expand Down Expand Up @@ -134,4 +145,13 @@ class GitHubBranchSourceContext extends AbstractContext {
void buildForkPRHead(boolean buildForkPRHead = true) {
this.buildForkPRHead = buildForkPRHead
}

/**
* Do not clone tags. Defaults to {@code true}.
*
* @since 1.71
*/
void noTags(boolean noTags = true) {
this.noTags = noTags
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,14 @@ class BranchSourcesContextsSpec extends Specification {
name() == 'jenkins.branch.BranchSource'
children().size() == 2
with(source[0]) {
children().size() == 13
children().size() == 5
id[0].value() instanceof String
scanCredentialsId[0].value().empty
checkoutCredentialsId[0].value() == 'SAME'
credentialsId[0].value().empty
repoOwner[0].value().empty
repository[0].value().empty
includes[0].value() == '*'
excludes[0].value().empty
buildOriginBranch[0].value() == true
buildOriginBranchWithPR[0].value() == true
buildOriginPRMerge[0].value() == false
buildOriginPRHead[0].value() == false
buildForkPRMerge[0].value() == true
buildForkPRHead[0].value() == false
with(traits[0]) {
children().size() == 3
}
}
with(strategy[0]) {
children().size() == 1
Expand All @@ -114,7 +108,7 @@ class BranchSourcesContextsSpec extends Specification {
properties[0].attribute('class') == 'empty-list'
}
}
1 * jobManagement.requireMinimumPluginVersion('github-branch-source', '1.8')
1 * jobManagement.requireMinimumPluginVersion('github-branch-source', '2.2.0')
}

def 'github with all options'() {
Expand Down Expand Up @@ -142,21 +136,15 @@ class BranchSourcesContextsSpec extends Specification {
name() == 'jenkins.branch.BranchSource'
children().size() == 2
with(source[0]) {
children().size() == 14
children().size() == 6
id[0].value() == 'test'
apiUri[0].value() == 'https://custom.url'
scanCredentialsId[0].value() == 'scanCreds'
checkoutCredentialsId[0].value() == 'checkoutCreds'
credentialsId[0].value() == 'scanCreds'
repoOwner[0].value() == 'ownerName'
repository[0].value() == 'repoName'
includes[0].value() == 'lorem'
excludes[0].value() == 'ipsum'
buildOriginBranch[0].value() == false
buildOriginBranchWithPR[0].value() == false
buildOriginPRMerge[0].value() == true
buildOriginPRHead[0].value() == true
buildForkPRMerge[0].value() == false
buildForkPRHead[0].value() == true
with(traits[0]) {
children().size() == 4
}
}
with(strategy[0]) {
children().size() == 1
Expand All @@ -165,6 +153,6 @@ class BranchSourcesContextsSpec extends Specification {
properties[0].attribute('class') == 'empty-list'
}
}
1 * jobManagement.requireMinimumPluginVersion('github-branch-source', '1.8')
1 * jobManagement.requireMinimumPluginVersion('github-branch-source', '2.2.0')
}
}