-
Notifications
You must be signed in to change notification settings - Fork 66
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
Showing
4 changed files
with
152 additions
and
287 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/jfrog/jfrog-cli-core/v2/pipelines/utils" | ||
"github.com/jfrog/jfrog-client-go/utils/log" | ||
"strings" | ||
) | ||
|
||
type PipelineDefinition struct { | ||
FileName string `json:"fileName,omitempty"` | ||
Content string `json:"content,omitempty"` | ||
YmlType string `json:"ymlType,omitempty"` | ||
} | ||
|
||
type ValidationFiles struct { | ||
Files []PipelineDefinition `json:"files,omitempty"` | ||
} | ||
|
||
func structureFileContentAsPipelineDefinition(allPipelineFiles []string, values string) ([]PipelineDefinition, error) { | ||
var pipelineDefinitions []PipelineDefinition | ||
for _, pathToFile := range allPipelineFiles { | ||
log.Info("Attaching pipelines definition file: ", pathToFile) | ||
fileContent, fileInfo, err := utils.GetFileContentAndBaseName(pathToFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ymlType := "pipelines" | ||
if strings.EqualFold(fileInfo.Name(), "values.yml") { | ||
ymlType = "values" | ||
} else if strings.Contains(fileInfo.Name(), "resources") { | ||
ymlType = "resources" | ||
} | ||
if len(fileContent) == 0 { | ||
continue | ||
} | ||
pipeDefinition := PipelineDefinition{ | ||
FileName: fileInfo.Name(), | ||
Content: string(fileContent), | ||
YmlType: ymlType, | ||
} | ||
pipelineDefinitions = append(pipelineDefinitions, pipeDefinition) | ||
} | ||
if values != "" { | ||
fileContent, fileInfo, err := utils.GetFileContentAndBaseName(values) | ||
if err != nil { | ||
return nil, err | ||
} | ||
pipeDefinition := PipelineDefinition{ | ||
FileName: fileInfo.Name(), | ||
Content: string(fileContent), | ||
YmlType: "values", | ||
} | ||
pipelineDefinitions = append(pipelineDefinitions, pipeDefinition) | ||
} | ||
log.Info("Total number of pipeline definition files eligible for validation: ", len(pipelineDefinitions)) | ||
log.Debug("Pipelines file content: ", pipelineDefinitions) | ||
return pipelineDefinitions, nil | ||
} |
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
Oops, something went wrong.