Skip to content

Commit

Permalink
added git chart repository working directory param
Browse files Browse the repository at this point in the history
  • Loading branch information
janpetryk committed Nov 12, 2020
1 parent 62159c2 commit 4202ee6
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ReleaseHelmChartTask extends DefaultTask {

def gitChartRepositoryProperties = new GitChartRepositoryPropertiesProvider(project, extension).provide()
def chartProperties = new ChartPropertiesProvider(project, extension).provide()
def workDirProperties = new WorkDirPropertiesProvider(project).provide()
def workDirProperties = new WorkDirPropertiesProvider(project, extension).provide()

def helmClient = new HelmRepository(chartProperties, workDirProperties, project.logger)
def gitChartRepository = new GitChartRepository(gitChartRepositoryProperties, workDirProperties, chartProperties, project.logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class GitChartRepositoryProperties {
private String url
private String username
private String password
private String chartRepoWorkDir

String getUrl() {
return url
Expand All @@ -18,8 +17,4 @@ class GitChartRepositoryProperties {
String getPassword() {
return password
}

String getChartRepoWorkDir() {
return chartRepoWorkDir
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class GitChartRepositoryPropertiesProvider {
GitChartRepositoryProperties provide() {
return new GitChartRepositoryProperties(url: gitChartRepoUrl(),
username: gitChartRepoUsername(),
password: gitChartRepoPassword(),
chartRepoWorkDir: chartRepositoryWorkDir())
password: gitChartRepoPassword())
}

private def gitChartRepoUrl() {
Expand Down Expand Up @@ -60,14 +59,4 @@ class GitChartRepositoryPropertiesProvider {
}
return null
}

private def chartRepositoryWorkDir() {
if (project.hasProperty(GIT_CHART_REPO_WORK_DIR_PROPERTY)) {
return project.property(GIT_CHART_REPO_WORK_DIR_PROPERTY)
}
if (extension.gitChartRepoWorkDir) {
return extension.gitChartRepoWorkDir
}
return ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package dk.kmd.helm.chart.publish.properties
class WorkDirProperties {

private String chartRepoTmpDirectory
private String chartRepoWorkingDirectory

String getChartRepoTmpDirectory() {
return chartRepoTmpDirectory
}

String getChartRepoWorkingDirectory() {
return chartRepoWorkingDirectory
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
package dk.kmd.helm.chart.publish.properties

import dk.kmd.helm.chart.publish.HelmChartPublisherExtension
import org.gradle.api.Project

class WorkDirPropertiesProvider {

static String GIT_CHART_REPO_WORK_DIR_PROPERTY = "gitChartRepo.workDir"


Project project
HelmChartPublisherExtension extension

WorkDirPropertiesProvider(Project project) {
WorkDirPropertiesProvider(Project project, HelmChartPublisherExtension extension) {
this.project = project
this.extension = extension
}

WorkDirProperties provide() {
return new WorkDirProperties(chartRepoTmpDirectory: "${project.buildDir}/helm-chart-repository")
def chartRepoTmpDirectory = "${project.buildDir}/helm-chart-repository"
return new WorkDirProperties(chartRepoTmpDirectory: chartRepoTmpDirectory, chartRepoWorkingDirectory: "${chartRepoTmpDirectory}/${chartRepositoryWorkDir()}")
}


private def chartRepositoryWorkDir() {
if (project.hasProperty(GIT_CHART_REPO_WORK_DIR_PROPERTY)) {
return project.property(GIT_CHART_REPO_WORK_DIR_PROPERTY)
}
if (extension.gitChartRepoWorkDir) {
return extension.gitChartRepoWorkDir
}
return ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import spock.lang.Specification
class GitChartRepositoryPropertiesProviderTest extends Specification {

@Rule
public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
public final EnvironmentVariables environmentVariables = new EnvironmentVariables()

def "should resolve git repository url from property if set"() {
given:
Expand Down Expand Up @@ -102,32 +102,4 @@ class GitChartRepositoryPropertiesProviderTest extends Specification {
new GitChartRepositoryPropertiesProvider(ProjectBuilder.builder().build(), extensionWithAnyParams()).provide().password == null
}

def "should resolve git chart repository work directory from properties"() {
given:
def givenWorkDir = randomAlphabetic(4)
Project project = ProjectBuilder.builder().build()
project.extensions.extraProperties.set("gitChartRepo.workDir", givenWorkDir)
def extension = extensionWithAnyParams(gitChartRepoWorkDir: randomAlphabetic(4))

expect:
new GitChartRepositoryPropertiesProvider(project, extension).provide().chartRepoWorkDir == givenWorkDir
}

def "should resolve git chart repository work directory from extension"() {
given:
def givenWorkDir = randomAlphabetic(4)
Project project = ProjectBuilder.builder().build()
def extension = extensionWithAnyParams(gitChartRepoWorkDir: givenWorkDir)

expect:
new GitChartRepositoryPropertiesProvider(project, extension).provide().chartRepoWorkDir == givenWorkDir
}

def "should resolve to empty if git chart repository work directory not set"() {
given:
def extension = extensionWithAnyParams(gitChartRepoWorkDir: null)

expect:
new GitChartRepositoryPropertiesProvider(ProjectBuilder.builder().build(), extension).provide().chartRepoWorkDir == ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package dk.kmd.helm.chart.publish.properties

import static dk.kmd.helm.chart.publish.properties.TestDataProvider.extensionWithAnyParams
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic

import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Specification

class WorkDirPropertiesProviderTest extends Specification {

def "should resolve git chart repository work directory from properties"() {
given:
def givenWorkDir = randomAlphabetic(4)
Project project = ProjectBuilder.builder().build()
project.extensions.extraProperties.set("gitChartRepo.workDir", givenWorkDir)
def extension = extensionWithAnyParams(gitChartRepoWorkDir: randomAlphabetic(4))

when:
def result = new WorkDirPropertiesProvider(project, extension).provide()

then:
result.chartRepoWorkingDirectory == "${result.chartRepoTmpDirectory}/${givenWorkDir}"
}

def "should resolve git chart repository work directory from extension"() {
given:
def givenWorkDir = randomAlphabetic(4)
Project project = ProjectBuilder.builder().build()
def extension = extensionWithAnyParams(gitChartRepoWorkDir: givenWorkDir)

when:
def result = new WorkDirPropertiesProvider(project, extension).provide()

then:
result.chartRepoWorkingDirectory == "${result.chartRepoTmpDirectory}/${givenWorkDir}"
}

def "should resolve to empty if git chart repository work directory not set"() {
given:
def extension = extensionWithAnyParams(gitChartRepoWorkDir: null)


when:
def result = new WorkDirPropertiesProvider(ProjectBuilder.builder().build(), extension).provide()

then:
result.chartRepoWorkingDirectory == "${result.chartRepoTmpDirectory}/"
}
}

0 comments on commit 4202ee6

Please sign in to comment.