-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f2ada2
commit 921e06f
Showing
9 changed files
with
147 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
Copyright © 2024 PATRICK HERMANN PATRICK.HERMANN@SVA.DE | ||
*/ | ||
package modules | ||
|
||
import ( | ||
billy "github.com/go-git/go-billy/v5" | ||
|
||
sthingsCli "github.com/stuttgart-things/sthingsCli" | ||
) | ||
|
||
// LOAD CLUSTERFILE - DEFAULT IS <ROOT>/<ENV>/<LAB>/clusters.yaml | ||
func CloneGitRepository(values map[string]string) (repository billy.Filesystem, repositoryCloned bool) { | ||
repository, repositoryCloned = sthingsCli.CloneGitRepository(values["repository"], values["branch"], values["commitID"], nil) | ||
|
||
if !repositoryCloned { | ||
log.Error("GIT REPOSITORY CAN NOT BE CLONED: ", values["repository"]) | ||
repositoryCloned = false | ||
} | ||
|
||
return repository, repositoryCloned | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright © 2024 PATRICK HERMANN PATRICK.HERMANN@SVA.DE | ||
*/ | ||
package modules | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCloneGitRepository(t *testing.T) { | ||
|
||
assert := assert.New(t) | ||
|
||
repoworks := make(map[string]string) | ||
repoworks["repository"] = "https://github.com/stuttgart-things/kaeffken.git" | ||
repoworks["branch"] = "main" | ||
repoworks["gitCommitID"] = "09de9ff7b5c76aff8bb32f68cfb0bbe49cd5a7a8" | ||
|
||
repoworksNot := make(map[string]string) | ||
repoworksNot["repository"] = "https://github.com/stuttgart-things/kaeffken.git" | ||
repoworksNot["branch"] = "test" | ||
repoworksNot["gitCommitID"] = "09de9ff7b5c76aff8bb32f68cfb0bbe49cd5a7a8" | ||
|
||
_, cloned := CloneGitRepository(repoworks) | ||
assert.Equal(cloned, true) | ||
|
||
_, cloned = CloneGitRepository(repoworksNot) | ||
assert.Equal(cloned, false) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright © 2024 PATRICK HERMANN PATRICK.HERMANN@SVA.DE | ||
*/ | ||
package modules | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
billy "github.com/go-git/go-billy/v5" | ||
sthingsBase "github.com/stuttgart-things/sthingsBase" | ||
sthingsCli "github.com/stuttgart-things/sthingsCli" | ||
) | ||
|
||
// LOAD CLUSTERFILE - DEFAULT IS <ROOT>/<ENV>/<LAB>/clusters.yaml | ||
func LoadDataFromRepository(repository billy.Filesystem, filePath string) (loadedFile string) { | ||
|
||
loadedFile = "" | ||
file := filepath.Base(filePath) | ||
folder := filepath.Dir(filePath) | ||
|
||
fmt.Println(file) | ||
fmt.Println(folder) | ||
|
||
// GET FILELIST | ||
fileList, directoryList := sthingsCli.GetFileListFromGitRepository(folder, repository) | ||
fmt.Println(fileList, directoryList) | ||
|
||
if sthingsBase.CheckForStringInSlice(fileList, file) { | ||
loadedFile = sthingsCli.ReadFileContentFromGitRepo(repository, filePath) | ||
return | ||
} else { | ||
log.Error("FILE DOES NOT EXIST IN REPOSITORY: ", filePath) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright © 2024 PATRICK HERMANN PATRICK.HERMANN@SVA.DE | ||
*/ | ||
package modules | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoadDataFromRepository(t *testing.T) { | ||
|
||
assert := assert.New(t) | ||
|
||
type test struct { | ||
filePath string | ||
want bool | ||
} | ||
|
||
tests := []test{ | ||
{filePath: "cmd/deploy.go", want: true}, | ||
{filePath: "cmd/deploy.go1", want: false}, | ||
} | ||
|
||
repoworks := make(map[string]string) | ||
repoworks["repository"] = "https://github.com/stuttgart-things/kaeffken.git" | ||
repoworks["branch"] = "main" | ||
repoworks["gitCommitID"] = "2f2ada234ffee467195439dacfe4a5579be3f66a" | ||
|
||
repository, cloned := CloneGitRepository(repoworks) | ||
|
||
for _, tc := range tests { | ||
var fileLoaded bool | ||
|
||
if cloned { | ||
loadedFile := LoadDataFromRepository(repository, tc.filePath) | ||
|
||
if loadedFile != "" { | ||
fileLoaded = true | ||
} | ||
} | ||
|
||
assert.Equal(fileLoaded, tc.want) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters