2021-11-02 18:19:31 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2022-12-10 22:47:59 +00:00
|
|
|
"os"
|
2021-11-02 18:19:31 +00:00
|
|
|
"strings"
|
2021-11-07 13:05:45 +00:00
|
|
|
|
|
|
|
"gitlab.com/revalus/grm/config"
|
2021-11-02 18:19:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func getFileContent(pathToFile string) ([]byte, error) {
|
2022-12-10 22:47:59 +00:00
|
|
|
return os.ReadFile(pathToFile)
|
2021-11-02 18:19:31 +00:00
|
|
|
}
|
|
|
|
|
2022-12-10 22:47:59 +00:00
|
|
|
func getFileExtension(pathToFile string) (string, error) {
|
|
|
|
splitFileName := strings.Split(pathToFile, ".")
|
2021-11-02 18:19:31 +00:00
|
|
|
|
2022-12-10 22:47:59 +00:00
|
|
|
if len(splitFileName) == 1 {
|
|
|
|
msg := fmt.Sprintf("excension for file \"%v\", not found", splitFileName)
|
2021-11-02 18:19:31 +00:00
|
|
|
return "", errors.New(msg)
|
|
|
|
}
|
|
|
|
|
2022-12-10 22:47:59 +00:00
|
|
|
fileExtension := splitFileName[len(splitFileName)-1]
|
2021-11-02 18:19:31 +00:00
|
|
|
|
2022-12-10 22:47:59 +00:00
|
|
|
return fileExtension, nil
|
2021-11-02 18:19:31 +00:00
|
|
|
}
|
2021-11-07 13:05:45 +00:00
|
|
|
|
|
|
|
func checkIsItemInSlice(check string, sliceToCheck []string) bool {
|
|
|
|
for _, item := range sliceToCheck {
|
|
|
|
if item == check {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkAnyOfItemInSlice(check []string, sliceToCheck []string) bool {
|
|
|
|
|
|
|
|
for _, item := range check {
|
|
|
|
if checkIsItemInSlice(item, sliceToCheck) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func reverseRepositoryConfigs(repositories []config.RepositoryConfig) []config.RepositoryConfig {
|
|
|
|
for i, j := 0, len(repositories)-1; i < j; i, j = i+1, j-1 {
|
|
|
|
repositories[i], repositories[j] = repositories[j], repositories[i]
|
|
|
|
}
|
|
|
|
return repositories
|
|
|
|
}
|