Skip to content

Commit 9554be6

Browse files
Thomas Michaelschnatterer
authored andcommitted
Refactor: config.content.repos override to overwrite
Makes clearer that we are talking about the file operation of overwriting
1 parent 3be6540 commit 9554be6

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

docs/configuration.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
"type" : [ "boolean", "null" ],
169169
"description" : "If true, no Jenkinsjob will be created."
170170
},
171-
"overrideMode" : {
171+
"overwriteMode" : {
172172
"anyOf" : [ {
173173
"type" : "null"
174174
}, {

src/main/groovy/com/cloudogu/gitops/config/Config.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ class Config {
135135
@JsonPropertyDescription(CONTENT_REPO_TARGET_DESCRIPTION)
136136
String target = ''
137137

138-
@JsonPropertyDescription(CONTENT_REPO_TARGET_OVERRIDE_MODE)
139-
OverrideMode overrideMode = OverrideMode.INIT // Defensively use init to not override existing files by default
138+
@JsonPropertyDescription(CONTENT_REPO_TARGET_OVERWRITE_MODE)
139+
OverwriteMode overwriteMode = OverwriteMode.INIT // Defensively use init to not override existing files by default
140140

141141
@JsonPropertyDescription(CONTENT_REPO_IGNORE_JENKINS)
142142
Boolean ignoreJenkins = false
@@ -806,9 +806,9 @@ class Config {
806806

807807
/**
808808
* This defines, how customer repos will be updated.
809-
* See {@link ConfigConstants#CONTENT_REPO_TARGET_OVERRIDE_MODE}
809+
* See {@link ConfigConstants#CONTENT_REPO_TARGET_OVERWRITE_MODE}
810810
*/
811-
static enum OverrideMode {
811+
static enum OverwriteMode {
812812
INIT, RESET, UPGRADE
813813
}
814814

src/main/groovy/com/cloudogu/gitops/config/ConfigConstants.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface ConfigConstants {
4040
String CONTENT_REPO_TEMPLATING_DESCRIPTION = "When true, template all files ending in .ftl within the repo"
4141
String CONTENT_REPO_TYPE_DESCRIPTION = "Content Repos can either be:\ncopied (only the files, starting on ref, starting at path within the repo. Requires target)\n, mirrored (FORCE pushes ref or the whole git repo if no ref set). Requires target, does not allow path and template.)\nfolderBased (folder structure is interpreted as repos. That is, root folder becomes namespace in SCM, sub folders become repository names in SCM, files are copied. Requires target.)"
4242
String CONTENT_REPO_TARGET_DESCRIPTION = "Target repo for the repository in the for of namespace/name. Must contain one slash to separate namespace from name."
43-
String CONTENT_REPO_TARGET_OVERRIDE_MODE = "This defines, how customer repos will be updated.\nINIT - push only if repo does not exist.\nRESET - delete all files after cloning source - files not in content are deleted\nUPGRADE - clone and copy - existing files will be overwritten, files not in content are kept"
43+
String CONTENT_REPO_TARGET_OVERWRITE_MODE = "This defines, how customer repos will be updated.\nINIT - push only if repo does not exist.\nRESET - delete all files after cloning source - files not in content are deleted\nUPGRADE - clone and copy - existing files will be overwritten, files not in content are kept"
4444
String CONTENT_REPO_IGNORE_JENKINS = "If true, no Jenkinsjob will be created."
4545
String CONTENT_VARIABLES_DESCRIPTION = "Additional variables to use in custom templates."
4646

src/main/groovy/com/cloudogu/gitops/features/Content.groovy

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.cloudogu.gitops.features
22

33
import com.cloudogu.gitops.Feature
44
import com.cloudogu.gitops.config.Config
5-
import com.cloudogu.gitops.config.Config.OverrideMode
5+
import com.cloudogu.gitops.config.Config.OverwriteMode
66
import com.cloudogu.gitops.scmm.ScmmRepo
77
import com.cloudogu.gitops.scmm.ScmmRepoProvider
88
import com.cloudogu.gitops.scmm.api.ScmmApiClient
@@ -106,7 +106,7 @@ class Content extends Feature {
106106
config.content.repos.each { repoConfig ->
107107

108108
def repoTmpDir = File.createTempDir('gitops-playground-folder-based-single-content-repo-')
109-
log.debug("Cloning content repo, ${repoConfig.url}, revision ${repoConfig.ref}, path ${repoConfig.path}, overrideMode ${repoConfig.overrideMode}")
109+
log.debug("Cloning content repo, ${repoConfig.url}, revision ${repoConfig.ref}, path ${repoConfig.path}, overwriteMode ${repoConfig.overwriteMode}")
110110

111111
cloneToLocalFolder(repoConfig, repoTmpDir)
112112

@@ -161,7 +161,7 @@ class Content extends Feature {
161161
/**
162162
* Merges the files of src into the mergeRepoFolder/namespace/name and adds a new object to repoCoordinates.
163163
*
164-
* Note that existing repoCoordinate objects with different overrideMode are overwritten. The last repo to be mentioned within config.content.repos wins!
164+
* Note that existing repoCoordinate objects with different overwriteMode are overwritten. The last repo to be mentioned within config.content.repos wins!
165165
*/
166166
private static RepoCoordinate mergeRepoDirs(File src, String namespace, String repoName, File mergedRepoFolder,
167167
ContentRepositorySchema repoConfig, List<RepoCoordinate> repoCoordinates) {
@@ -260,10 +260,10 @@ class Content extends Feature {
260260
ScmmRepo targetRepo = repoProvider.getRepo(repoCoordinate.fullRepoName)
261261
def isRepoCreated = targetRepo.create('', scmmApiClient)
262262

263-
if (!isRepoCreated && OverrideMode.INIT == repoCoordinate.repoConfig.overrideMode) {
264-
log.warn("OverrideMode ${OverrideMode.INIT} set for repo '${repoCoordinate.fullRepoName}' " +
263+
if (!isRepoCreated && OverwriteMode.INIT == repoCoordinate.repoConfig.overwriteMode) {
264+
log.warn("OverwriteMode ${OverwriteMode.INIT} set for repo '${repoCoordinate.fullRepoName}' " +
265265
"and repo already exists in target: Not pushing content!" +
266-
"If you want to override, set ${OverrideMode.UPGRADE} or ${OverrideMode.RESET} .")
266+
"If you want to override, set ${OverwriteMode.UPGRADE} or ${OverwriteMode.RESET} .")
267267
} else {
268268

269269
targetRepo.cloneRepo()
@@ -287,13 +287,13 @@ class Content extends Feature {
287287
* Same logic for both FOLDER_BASED and COPY repo types.
288288
*/
289289
private static void handleRepoCopying(RepoCoordinate repoCoordinate, ScmmRepo targetRepo) {
290-
if (OverrideMode.INIT != repoCoordinate.repoConfig.overrideMode) {
291-
if (OverrideMode.RESET == repoCoordinate.repoConfig.overrideMode) {
292-
log.info("OverrideMode ${OverrideMode.RESET} set for repo '${repoCoordinate.fullRepoName}': " +
290+
if (OverwriteMode.INIT != repoCoordinate.repoConfig.overwriteMode) {
291+
if (OverwriteMode.RESET == repoCoordinate.repoConfig.overwriteMode) {
292+
log.info("OverwriteMode ${Config.OverwriteMode.RESET} set for repo '${repoCoordinate.fullRepoName}': " +
293293
"Deleting existing files in repo and replacing them with new content.")
294294
targetRepo.clearRepo()
295295
} else {
296-
log.info("OverrideMode ${OverrideMode.UPGRADE} set for repo '${repoCoordinate.fullRepoName}': " +
296+
log.info("OverwriteMode ${OverwriteMode.UPGRADE} set for repo '${repoCoordinate.fullRepoName}': " +
297297
"Merging new content into existing repo. ")
298298
}
299299
}
@@ -496,7 +496,7 @@ class Content extends Feature {
496496

497497
@Override
498498
String toString() {
499-
return "RepoCoordinates{ namespace='$namespace', repoName='$repoName', repoConfig.type='${repoConfig.type}', repoConfig.overrideMode='${repoConfig.overrideMode}', newContent=$newContent', refIsTag='${refIsTag}' }"
499+
return "RepoCoordinates{ namespace='$namespace', repoName='$repoName', repoConfig.type='${repoConfig.type}', repoConfig.overwriteMode='${repoConfig.overwriteMode}', newContent=$newContent', refIsTag='${refIsTag}' }"
500500
}
501501

502502
String getFullRepoName() {

src/test/groovy/com/cloudogu/gitops/features/ContentTest.groovy

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ class ContentTest {
269269
void 'Is able to COPY into MIRRORED repo'() {
270270
config.content.repos = [
271271
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1', 'git-repository-with-branches-tags'), type: ContentRepoType.MIRROR, target: 'common/repo'),
272-
new ContentRepositorySchema(url: createContentRepo('folderBasedRepo1'), type: ContentRepoType.FOLDER_BASED, overrideMode: OverrideMode.UPGRADE),
273-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo2'), type: ContentRepoType.COPY, target: 'common/repo', overrideMode: OverrideMode.UPGRADE, path: 'subPath')
272+
new ContentRepositorySchema(url: createContentRepo('folderBasedRepo1'), type: ContentRepoType.FOLDER_BASED, overwriteMode: OverwriteMode.UPGRADE),
273+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo2'), type: ContentRepoType.COPY, target: 'common/repo', overwriteMode: OverwriteMode.UPGRADE, path: 'subPath')
274274
]
275275

276276
scmmApiClient.mockRepoApiBehaviour()
@@ -297,8 +297,8 @@ class ContentTest {
297297
void 'Handles MIRRORING COPYed repo'() {
298298
config.content.repos = [
299299
new ContentRepositorySchema(url: createContentRepo('folderBasedRepo1'), type: ContentRepoType.FOLDER_BASED),
300-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo2'), type: ContentRepoType.COPY, target: 'common/repo', overrideMode: OverrideMode.UPGRADE, path: 'subPath'),
301-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1', 'git-repository-with-branches-tags'), type: ContentRepoType.MIRROR, overrideMode: OverrideMode.RESET, target: 'common/repo'),
300+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo2'), type: ContentRepoType.COPY, target: 'common/repo', overwriteMode: OverwriteMode.UPGRADE, path: 'subPath'),
301+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1', 'git-repository-with-branches-tags'), type: ContentRepoType.MIRROR, overwriteMode: OverwriteMode.RESET, target: 'common/repo'),
302302
]
303303

304304
scmmApiClient.mockRepoApiBehaviour()
@@ -326,9 +326,9 @@ class ContentTest {
326326
def repoToMirror = createContentRepo('nonFolderBasedRepo1', 'git-repository-with-branches-tags')
327327
config.content.repos = [
328328
new ContentRepositorySchema(url: repoToMirror, type: ContentRepoType.MIRROR, ref: 'main', target: 'common/repo'),
329-
new ContentRepositorySchema(url: repoToMirror, type: ContentRepoType.MIRROR, ref: 'someBranch', target: 'common/repo', overrideMode: OverrideMode.UPGRADE),
330-
new ContentRepositorySchema(url: repoToMirror, type: ContentRepoType.MIRROR, ref: 'someTag', target: 'common/repo', overrideMode: OverrideMode.UPGRADE),
331-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo2'), type: ContentRepoType.COPY, target: 'common/repo', overrideMode: OverrideMode.UPGRADE, path: 'subPath')
329+
new ContentRepositorySchema(url: repoToMirror, type: ContentRepoType.MIRROR, ref: 'someBranch', target: 'common/repo', overwriteMode: OverwriteMode.UPGRADE),
330+
new ContentRepositorySchema(url: repoToMirror, type: ContentRepoType.MIRROR, ref: 'someTag', target: 'common/repo', overwriteMode: OverwriteMode.UPGRADE),
331+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo2'), type: ContentRepoType.COPY, target: 'common/repo', overwriteMode: OverwriteMode.UPGRADE, path: 'subPath')
332332
]
333333

334334
scmmApiClient.mockRepoApiBehaviour()
@@ -390,8 +390,8 @@ class ContentTest {
390390
def repoToMirror = createContentRepo('nonFolderBasedRepo1', 'git-repository-with-branches-tags')
391391
config.content.repos = [
392392
new ContentRepositorySchema(url: repoToMirror, type: ContentRepoType.MIRROR, ref: 'main', target: 'common/repo'),
393-
new ContentRepositorySchema(url: repoToMirror, type: ContentRepoType.MIRROR, ref: 'someBranch', target: 'common/repo') /* Deliberately not use overrideMode here !*/,
394-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo2'), type: ContentRepoType.COPY, target: 'common/repo', overrideMode: OverrideMode.UPGRADE, path: 'subPath')
393+
new ContentRepositorySchema(url: repoToMirror, type: ContentRepoType.MIRROR, ref: 'someBranch', target: 'common/repo') /* Deliberately not use overwriteMode here !*/,
394+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo2'), type: ContentRepoType.COPY, target: 'common/repo', overwriteMode: OverwriteMode.UPGRADE, path: 'subPath')
395395
]
396396

397397
scmmApiClient.mockRepoApiBehaviour()
@@ -409,7 +409,7 @@ class ContentTest {
409409
// So for our testcase we just mirror the same repo twice
410410
config.content.repos = [
411411
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1', 'git-repository-with-branches-tags'), type: ContentRepoType.MIRROR, target: 'common/repo'),
412-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1', 'git-repository-with-branches-tags'), type: ContentRepoType.MIRROR, target: 'common/repo', overrideMode: OverrideMode.RESET),
412+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1', 'git-repository-with-branches-tags'), type: ContentRepoType.MIRROR, target: 'common/repo', overwriteMode: OverwriteMode.RESET),
413413
]
414414

415415
scmmApiClient.mockRepoApiBehaviour()
@@ -593,7 +593,7 @@ class ContentTest {
593593
* Now Reset to nonFolderBased1
594594
*/
595595
config.content.repos = [
596-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1'), ref: 'main', type: ContentRepoType.COPY, target: 'common/repo', overrideMode: OverrideMode.RESET),
596+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1'), ref: 'main', type: ContentRepoType.COPY, target: 'common/repo', overwriteMode: OverwriteMode.RESET),
597597
]
598598

599599
def resourceExistsAnswer = scmmApiClient.mockErrorResponse(409)
@@ -654,7 +654,7 @@ class ContentTest {
654654
* Now Upgrade to nonFolderBased2
655655
*/
656656
config.content.repos = [
657-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo2'), type: ContentRepoType.COPY, target: 'common/repo', path: 'subPath', overrideMode: OverrideMode.UPGRADE)
657+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo2'), type: ContentRepoType.COPY, target: 'common/repo', path: 'subPath', overwriteMode: OverwriteMode.UPGRADE)
658658
]
659659

660660
def resourceExistsAnswer = scmmApiClient.mockErrorResponse(409)
@@ -718,7 +718,7 @@ class ContentTest {
718718
* no changes expected, file still has nonFolderBasedRepo2 and so on
719719
*/
720720
config.content.repos = [
721-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1'), ref: 'main', type: ContentRepoType.COPY, target: 'common/repo', overrideMode: OverrideMode.INIT),
721+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1'), ref: 'main', type: ContentRepoType.COPY, target: 'common/repo', overwriteMode: OverwriteMode.INIT),
722722
]
723723

724724
def resourceExistsAnswer = scmmApiClient.mockErrorResponse(409)

0 commit comments

Comments
 (0)