Skip to content

Commit

Permalink
Fix m2k kfunc: remove .git folders from output
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-farache authored and masayag committed Feb 6, 2024
1 parent 64ce167 commit c080b56
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ public CloudEvent<EventGenerator.EventPOJO> saveTransformation(FunInput input) {
input.transformId, input.workspaceId, input.projectId, input.gitRepo, e), SOURCE);
}

try {
cleanTransformationOutputFolder(transformationOutputPath);
} catch (IOException e) {
log.error("Error while cleaning extracted transformation output", e);
return EventGenerator.createErrorEvent(input.workflowCallerId, String.format("Cannot clean extracted transformation output of transformation %s" +
" in workspace %s for project %s for repo %s; error: %s",
input.transformId, input.workspaceId, input.projectId, input.gitRepo, e), SOURCE);
}

return pushTransformationToGitRepo(input, transformationOutputPath);
}

Expand Down Expand Up @@ -114,6 +123,20 @@ public void moveTransformationOutputToBranchDirectory(Path transformationOutput,
gitDirectory.resolve("Readme.md").toFile());
}

private static void cleanTransformationOutputFolder(Path transformationOutput) throws IOException {
try (var files = Files.walk(transformationOutput)) {
files.forEach(path -> {
if (path.toAbsolutePath().toString().contains(".git") && path.toFile().isDirectory()) {
try {
FileUtils.deleteDirectory(path.toFile());
} catch (IOException e) {
log.error("Error while deleting .git directory {} of transformation output", path, e);
}
}
});
}
}

private static void cleanCurrentGitFolder(Path gitDirectory) throws IOException {
try (var files = Files.walk(gitDirectory, 1)) {
files.forEach(path -> {
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit c080b56

Please sign in to comment.