Skip to content

Commit

Permalink
wip: warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Sep 30, 2024
1 parent af6cf50 commit 5b6361f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
9 changes: 9 additions & 0 deletions database/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"

"github.com/go-vela/types/library"
"github.com/lib/pq"
)

var (
Expand Down Expand Up @@ -48,6 +49,7 @@ type Pipeline struct {
Steps sql.NullBool `sql:"steps"`
Templates sql.NullBool `sql:"templates"`
Data []byte `sql:"data"`
Warnings pq.StringArray `sql:"warnings" gorm:"type:varchar(1000)"`
}

// Compress will manipulate the existing data for the
Expand Down Expand Up @@ -158,6 +160,7 @@ func (p *Pipeline) ToLibrary() *library.Pipeline {
pipeline.SetSteps(p.Steps.Bool)
pipeline.SetTemplates(p.Templates.Bool)
pipeline.SetData(p.Data)
pipeline.SetWarnings(p.Warnings)

return pipeline
}
Expand Down Expand Up @@ -200,6 +203,10 @@ func (p *Pipeline) Validate() error {
p.Type = sql.NullString{String: sanitize(p.Type.String), Valid: p.Type.Valid}
p.Version = sql.NullString{String: sanitize(p.Version.String), Valid: p.Version.Valid}

for i, v := range p.Warnings {
p.Warnings[i] = sanitize(v)
}

return nil
}

Expand All @@ -222,6 +229,8 @@ func PipelineFromLibrary(p *library.Pipeline) *Pipeline {
Steps: sql.NullBool{Bool: p.GetSteps(), Valid: true},
Templates: sql.NullBool{Bool: p.GetTemplates(), Valid: true},
Data: p.GetData(),

Warnings: pq.StringArray(p.GetWarnings()),
}

return pipeline.Nullify()
Expand Down
47 changes: 33 additions & 14 deletions library/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ import (
//
// swagger:model Pipeline
type Pipeline struct {
ID *int64 `json:"id,omitempty"`
RepoID *int64 `json:"repo_id,omitempty"`
Commit *string `json:"commit,omitempty"`
Flavor *string `json:"flavor,omitempty"`
Platform *string `json:"platform,omitempty"`
Ref *string `json:"ref,omitempty"`
Type *string `json:"type,omitempty"`
Version *string `json:"version,omitempty"`
ExternalSecrets *bool `json:"external_secrets,omitempty"`
InternalSecrets *bool `json:"internal_secrets,omitempty"`
Services *bool `json:"services,omitempty"`
Stages *bool `json:"stages,omitempty"`
Steps *bool `json:"steps,omitempty"`
Templates *bool `json:"templates,omitempty"`
ID *int64 `json:"id,omitempty"`
RepoID *int64 `json:"repo_id,omitempty"`
Commit *string `json:"commit,omitempty"`
Flavor *string `json:"flavor,omitempty"`
Platform *string `json:"platform,omitempty"`
Ref *string `json:"ref,omitempty"`
Type *string `json:"type,omitempty"`
Version *string `json:"version,omitempty"`
ExternalSecrets *bool `json:"external_secrets,omitempty"`
InternalSecrets *bool `json:"internal_secrets,omitempty"`
Services *bool `json:"services,omitempty"`
Stages *bool `json:"stages,omitempty"`
Steps *bool `json:"steps,omitempty"`
Templates *bool `json:"templates,omitempty"`
Warnings *[]string `json:"warnings,omitempty"`
// swagger:strfmt base64
Data *[]byte `json:"data,omitempty"`
}
Expand Down Expand Up @@ -223,6 +224,15 @@ func (p *Pipeline) GetData() []byte {
return *p.Data
}

func (p *Pipeline) GetWarnings() []string {
// return zero value if Pipeline type or field is nil
if p == nil || p.Data == nil {
return []string{}
}

return *p.Warnings
}

// SetID sets the ID field.
//
// When the provided Pipeline type is nil, it
Expand Down Expand Up @@ -418,6 +428,15 @@ func (p *Pipeline) SetData(v []byte) {
p.Data = &v
}

func (p *Pipeline) SetWarnings(v []string) {
// return if Pipeline type is nil
if p == nil {
return
}

p.Warnings = &v
}

// String implements the Stringer interface for the Pipeline type.
func (p *Pipeline) String() string {
return fmt.Sprintf(`{
Expand Down
6 changes: 6 additions & 0 deletions yaml/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func (b *Build) ToPipelineLibrary() *library.Pipeline {
pipeline.SetExternalSecrets(external)
pipeline.SetInternalSecrets(internal)

w := ([]string{})
for _, s := range b.Steps {
w = append(w, s.Warnings...)
}
pipeline.Warnings = &w

return pipeline
}

Expand Down
7 changes: 7 additions & 0 deletions yaml/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type (
User string `yaml:"user,omitempty" json:"user,omitempty" jsonschema:"description=Set the user for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-user-key"`
ReportAs string `yaml:"report_as,omitempty" json:"report_as,omitempty" jsonschema:"description=Set the name of the step to report as.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-report_as-key"`
IDRequest string `yaml:"id_request,omitempty" json:"id_request,omitempty" jsonschema:"description=Request ID Request Token for the step.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-id_request-key"`
Warnings []string `yaml:"-" json:"-"`
}
)

Expand Down Expand Up @@ -88,6 +89,7 @@ func (s *StepSlice) UnmarshalYAML(v *yaml.Node) error {
for _, st := range v.Content {
// make local var
tmpStep := *st
warnings := []string{}

// steps are mapping nodes
if tmpStep.Kind != yaml.MappingNode {
Expand All @@ -113,6 +115,8 @@ func (s *StepSlice) UnmarshalYAML(v *yaml.Node) error {
if anchorKey == nil {
anchorKey = key
anchorSequence = value

warnings = append(warnings, fmt.Sprintf("%d:contains anchor reference, behavior may have changed", key.Line))
}

// append value to anchor list
Expand Down Expand Up @@ -172,6 +176,9 @@ func (s *StepSlice) UnmarshalYAML(v *yaml.Node) error {
step.Pull = constants.PullNotPresent
}

// append warnings
step.Warnings = append(step.Warnings, warnings...)

*stepSlice = append(*stepSlice, step)
}

Expand Down

0 comments on commit 5b6361f

Please sign in to comment.