Unify effective config projection
This commit is contained in:
@@ -60,23 +60,7 @@ func EffectivePipelineValues(cfg *PipelineConfig) ([]EffectivePipelineValueRecor
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("pipeline config is required")
|
||||
}
|
||||
data, err := MarshalEffectivePipeline(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
document, err := parseCompositionBytes("effective pipeline", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
records, err := document.compactSemanticRecords()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
values := make([]EffectivePipelineValueRecord, 0, len(records))
|
||||
for _, record := range records {
|
||||
values = append(values, EffectivePipelineValueRecord{Path: record.Path, Value: record.Value})
|
||||
}
|
||||
return values, nil
|
||||
return projectionValueRecords(projectEffectivePipeline(cfg, true))
|
||||
}
|
||||
|
||||
// EffectivePipelineSources projects pipeline ownership after defaults and
|
||||
@@ -86,15 +70,14 @@ func EffectivePipelineSources(cfg *PipelineConfig, party ResolvedParty) ([]Effec
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("pipeline config is required")
|
||||
}
|
||||
data, err := MarshalEffectivePipeline(cfg)
|
||||
values, err := EffectivePipelineValues(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
document, err := parseCompositionBytes("effective pipeline", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
paths := make([]string, 0, len(values))
|
||||
for _, value := range values {
|
||||
paths = append(paths, value.Path)
|
||||
}
|
||||
paths := effectivePipelineFieldPaths(document.root)
|
||||
owners := effectivePipelineOwners(cfg)
|
||||
families := ArtifactFamilies(cfg)
|
||||
publishCount := 0
|
||||
@@ -168,54 +151,11 @@ func MarshalEffectivePipeline(cfg *PipelineConfig) ([]byte, error) {
|
||||
return nil, fmt.Errorf("pipeline config is required")
|
||||
}
|
||||
|
||||
data, err := yaml.Marshal(cfg)
|
||||
data, err := yaml.Marshal(projectEffectivePipeline(cfg, true))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("serialize effective pipeline: %w", err)
|
||||
}
|
||||
document, err := parseCompositionBytes("effective pipeline", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
removeResolutionOnlyPipelineFields(document)
|
||||
return document.canonicalYAML()
|
||||
}
|
||||
|
||||
func removeResolutionOnlyPipelineFields(document *compositionDocument) {
|
||||
if document == nil || document.root == nil {
|
||||
return
|
||||
}
|
||||
scriptoriumIndex := compositionFieldIndex(document.root.fields, "scriptorium")
|
||||
if scriptoriumIndex < 0 {
|
||||
return
|
||||
}
|
||||
scriptorium := document.root.fields[scriptoriumIndex].value
|
||||
if scriptorium == nil || scriptorium.kind != yaml.MappingNode {
|
||||
return
|
||||
}
|
||||
familyIndex := compositionFieldIndex(scriptorium.fields, "artifact_families")
|
||||
if familyIndex < 0 {
|
||||
return
|
||||
}
|
||||
scriptorium.fields = append(scriptorium.fields[:familyIndex], scriptorium.fields[familyIndex+1:]...)
|
||||
}
|
||||
|
||||
func effectivePipelineFieldPaths(node *compositionNode) []string {
|
||||
var paths []string
|
||||
var visit func(*compositionNode)
|
||||
visit = func(current *compositionNode) {
|
||||
if current == nil {
|
||||
return
|
||||
}
|
||||
if current.kind == yaml.MappingNode && len(current.fields) > 0 {
|
||||
for _, field := range current.fields {
|
||||
visit(field.value)
|
||||
}
|
||||
return
|
||||
}
|
||||
paths = append(paths, current.path)
|
||||
}
|
||||
visit(node)
|
||||
return paths
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func effectivePipelineOwners(cfg *PipelineConfig) map[string][]string {
|
||||
|
||||
Reference in New Issue
Block a user