From 3eb3f79c16f04bfb47a2cfd17e098fd084585c17 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Wed, 28 Feb 2024 10:48:45 -0600 Subject: [PATCH 1/3] feat: starting types for github app --- database/repo.go | 8 ++++++ database/step.go | 8 ++++++ library/repo.go | 30 ++++++++++++++++++++++ library/step.go | 30 ++++++++++++++++++++++ pipeline/container.go | 41 +++++++++++++++--------------- yaml/step.go | 58 ++++++++++++++++++++++--------------------- 6 files changed, 127 insertions(+), 48 deletions(-) diff --git a/database/repo.go b/database/repo.go index 8fde8286..6b560f6d 100644 --- a/database/repo.go +++ b/database/repo.go @@ -70,6 +70,7 @@ type Repo struct { PipelineType sql.NullString `sql:"pipeline_type"` PreviousName sql.NullString `sql:"previous_name"` ApproveBuild sql.NullString `sql:"approve_build"` + InstallID sql.NullInt64 `sql:"install_id"` } // Decrypt will manipulate the existing repo hash by @@ -210,6 +211,11 @@ func (r *Repo) Nullify() *Repo { r.ApproveBuild.Valid = false } + // check if the InstallID field should be false + if r.InstallID.Int64 == 0 { + r.InstallID.Valid = false + } + return r } @@ -244,6 +250,7 @@ func (r *Repo) ToLibrary() *library.Repo { repo.SetPipelineType(r.PipelineType.String) repo.SetPreviousName(r.PreviousName.String) repo.SetApproveBuild(r.ApproveBuild.String) + repo.SetInstallID(r.InstallID.Int64) return repo } @@ -341,6 +348,7 @@ func RepoFromLibrary(r *library.Repo) *Repo { PipelineType: sql.NullString{String: r.GetPipelineType(), Valid: true}, PreviousName: sql.NullString{String: r.GetPreviousName(), Valid: true}, ApproveBuild: sql.NullString{String: r.GetApproveBuild(), Valid: true}, + InstallID: sql.NullInt64{Int64: r.GetInstallID(), Valid: true}, } return repo.Nullify() diff --git a/database/step.go b/database/step.go index 318407e1..437d0a18 100644 --- a/database/step.go +++ b/database/step.go @@ -49,6 +49,7 @@ type Step struct { Host sql.NullString `sql:"host"` Runtime sql.NullString `sql:"runtime"` Distribution sql.NullString `sql:"distribution"` + CheckID sql.NullInt64 `sql:"check_id"` } // Nullify ensures the valid flag for @@ -142,6 +143,11 @@ func (s *Step) Nullify() *Step { s.Distribution.Valid = false } + // check if the CheckID field should be false + if s.CheckID.Int64 == 0 { + s.CheckID.Valid = false + } + return s } @@ -166,6 +172,7 @@ func (s *Step) ToLibrary() *library.Step { step.SetHost(s.Host.String) step.SetRuntime(s.Runtime.String) step.SetDistribution(s.Distribution.String) + step.SetCheckID(s.CheckID.Int64) return step } @@ -233,6 +240,7 @@ func StepFromLibrary(s *library.Step) *Step { Host: sql.NullString{String: s.GetHost(), Valid: true}, Runtime: sql.NullString{String: s.GetRuntime(), Valid: true}, Distribution: sql.NullString{String: s.GetDistribution(), Valid: true}, + CheckID: sql.NullInt64{Int64: s.GetCheckID(), Valid: true}, } return step.Nullify() diff --git a/library/repo.go b/library/repo.go index 845028b9..64e2d1ce 100644 --- a/library/repo.go +++ b/library/repo.go @@ -37,6 +37,7 @@ type Repo struct { PipelineType *string `json:"pipeline_type,omitempty"` PreviousName *string `json:"previous_name,omitempty"` ApproveBuild *string `json:"approve_build,omitempty"` + InstallID *int64 `json:"install_id,omitempty"` } // Environment returns a list of environment variables @@ -64,6 +65,7 @@ func (r *Repo) Environment() map[string]string { "VELA_REPO_VISIBILITY": ToString(r.GetVisibility()), "VELA_REPO_PIPELINE_TYPE": ToString(r.GetPipelineType()), "VELA_REPO_APPROVE_BUILD": ToString(r.GetApproveBuild()), + "VELA_REPO_INSTALL_ID": ToString(r.GetInstallID()), // deprecated environment variables "REPOSITORY_ACTIVE": ToString(r.GetActive()), @@ -424,6 +426,19 @@ func (r *Repo) GetApproveBuild() string { return *r.ApproveBuild } +// GetInstallID returns the InstallID field. +// +// When the provided Repo type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (r *Repo) GetInstallID() int64 { + // return zero value if Repo type or InstallID field is nil + if r == nil || r.InstallID == nil { + return 0 + } + + return *r.InstallID +} + // SetID sets the ID field. // // When the provided Repo type is nil, it @@ -762,6 +777,19 @@ func (r *Repo) SetApproveBuild(v string) { r.ApproveBuild = &v } +// SetInstallID sets the InstallID field. +// +// When the provided Repo type is nil, it +// will set nothing and immediately return. +func (r *Repo) SetInstallID(v int64) { + // return if Repo type is nil + if r == nil { + return + } + + r.InstallID = &v +} + // String implements the Stringer interface for the Repo type. // //nolint:dupl // ignore duplicate with test func @@ -781,6 +809,7 @@ func (r *Repo) String() string { Counter: %d, FullName: %s, ID: %d, + InstallID: %d, Link: %s, Name: %s, Org: %s, @@ -807,6 +836,7 @@ func (r *Repo) String() string { r.GetCounter(), r.GetFullName(), r.GetID(), + r.GetInstallID(), r.GetLink(), r.GetName(), r.GetOrg(), diff --git a/library/step.go b/library/step.go index 5dfa8aee..89af8f9b 100644 --- a/library/step.go +++ b/library/step.go @@ -31,6 +31,7 @@ type Step struct { Host *string `json:"host,omitempty"` Runtime *string `json:"runtime,omitempty"` Distribution *string `json:"distribution,omitempty"` + CheckID *int64 `json:"check_id,omitempty"` } // Duration calculates and returns the total amount of @@ -78,6 +79,7 @@ func (s *Step) Environment() map[string]string { "VELA_STEP_STAGE": ToString(s.GetStage()), "VELA_STEP_STARTED": ToString(s.GetStarted()), "VELA_STEP_STATUS": ToString(s.GetStatus()), + "VELA_STEP_CHECK_ID": ToString(s.GetCheckID()), } } @@ -289,6 +291,19 @@ func (s *Step) GetDistribution() string { return *s.Distribution } +// GetCheckID returns the CheckID field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetCheckID() int64 { + // return zero value if Step type or CheckID field is nil + if s == nil || s.CheckID == nil { + return 0 + } + + return *s.CheckID +} + // SetID sets the ID field. // // When the provided Step type is nil, it @@ -497,6 +512,19 @@ func (s *Step) SetDistribution(v string) { s.Distribution = &v } +// SetCheckID sets the CheckID field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetCheckID(v int64) { + // return if Step type is nil + if s == nil { + return + } + + s.CheckID = &v +} + // String implements the Stringer interface for the Step type. func (s *Step) String() string { return fmt.Sprintf(`{ @@ -512,6 +540,7 @@ func (s *Step) String() string { Name: %s, Number: %d, RepoID: %d, + CheckID: %d, Runtime: %s, Stage: %s, Started: %d, @@ -529,6 +558,7 @@ func (s *Step) String() string { s.GetName(), s.GetNumber(), s.GetRepoID(), + s.GetCheckID(), s.GetRuntime(), s.GetStage(), s.GetStarted(), diff --git a/pipeline/container.go b/pipeline/container.go index 3ada27a0..75282016 100644 --- a/pipeline/container.go +++ b/pipeline/container.go @@ -31,26 +31,27 @@ type ( // // swagger:model PipelineContainer Container struct { - ID string `json:"id,omitempty" yaml:"id,omitempty"` - Commands []string `json:"commands,omitempty" yaml:"commands,omitempty"` - Detach bool `json:"detach,omitempty" yaml:"detach,omitempty"` - Directory string `json:"directory,omitempty" yaml:"directory,omitempty"` - Entrypoint []string `json:"entrypoint,omitempty" yaml:"entrypoint,omitempty"` - Environment map[string]string `json:"environment,omitempty" yaml:"environment,omitempty"` - ExitCode int `json:"exit_code,omitempty" yaml:"exit_code,omitempty"` - Image string `json:"image,omitempty" yaml:"image,omitempty"` - Name string `json:"name,omitempty" yaml:"name,omitempty"` - Needs []string `json:"needs,omitempty" yaml:"needs,omitempty"` - Networks []string `json:"networks,omitempty" yaml:"networks,omitempty"` - Number int `json:"number,omitempty" yaml:"number,omitempty"` - Ports []string `json:"ports,omitempty" yaml:"ports,omitempty"` - Privileged bool `json:"privileged,omitempty" yaml:"privileged,omitempty"` - Pull string `json:"pull,omitempty" yaml:"pull,omitempty"` - Ruleset Ruleset `json:"ruleset,omitempty" yaml:"ruleset,omitempty"` - Secrets StepSecretSlice `json:"secrets,omitempty" yaml:"secrets,omitempty"` - Ulimits UlimitSlice `json:"ulimits,omitempty" yaml:"ulimits,omitempty"` - Volumes VolumeSlice `json:"volumes,omitempty" yaml:"volumes,omitempty"` - User string `json:"user,omitempty" yaml:"user,omitempty"` + ID string `json:"id,omitempty" yaml:"id,omitempty"` + Commands []string `json:"commands,omitempty" yaml:"commands,omitempty"` + Detach bool `json:"detach,omitempty" yaml:"detach,omitempty"` + Directory string `json:"directory,omitempty" yaml:"directory,omitempty"` + Entrypoint []string `json:"entrypoint,omitempty" yaml:"entrypoint,omitempty"` + Environment map[string]string `json:"environment,omitempty" yaml:"environment,omitempty"` + ExitCode int `json:"exit_code,omitempty" yaml:"exit_code,omitempty"` + Image string `json:"image,omitempty" yaml:"image,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Needs []string `json:"needs,omitempty" yaml:"needs,omitempty"` + Networks []string `json:"networks,omitempty" yaml:"networks,omitempty"` + Number int `json:"number,omitempty" yaml:"number,omitempty"` + Ports []string `json:"ports,omitempty" yaml:"ports,omitempty"` + Privileged bool `json:"privileged,omitempty" yaml:"privileged,omitempty"` + Pull string `json:"pull,omitempty" yaml:"pull,omitempty"` + Ruleset Ruleset `json:"ruleset,omitempty" yaml:"ruleset,omitempty"` + Secrets StepSecretSlice `json:"secrets,omitempty" yaml:"secrets,omitempty"` + Ulimits UlimitSlice `json:"ulimits,omitempty" yaml:"ulimits,omitempty"` + Volumes VolumeSlice `json:"volumes,omitempty" yaml:"volumes,omitempty"` + User string `json:"user,omitempty" yaml:"user,omitempty"` + ReportStatus bool `json:"report_status,omitempty" yaml:"report_status,omitempty"` } ) diff --git a/yaml/step.go b/yaml/step.go index 82232143..57a72cc9 100644 --- a/yaml/step.go +++ b/yaml/step.go @@ -19,21 +19,22 @@ type ( // Step is the yaml representation of a step // from the steps block for a pipeline. Step struct { - Ruleset Ruleset `yaml:"ruleset,omitempty" json:"ruleset,omitempty" jsonschema:"description=Conditions to limit the execution of the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-ruleset-tag"` - Commands raw.StringSlice `yaml:"commands,omitempty" json:"commands,omitempty" jsonschema:"description=Execution instructions to run inside the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-commands-tag"` - Entrypoint raw.StringSlice `yaml:"entrypoint,omitempty" json:"entrypoint,omitempty" jsonschema:"description=Command to execute inside the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-entrypoint-tag"` - Secrets StepSecretSlice `yaml:"secrets,omitempty" json:"secrets,omitempty" jsonschema:"description=Sensitive variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-secrets-tag"` - Template StepTemplate `yaml:"template,omitempty" json:"template,omitempty" jsonschema:"oneof_required=template,description=Name of template to expand in the pipeline.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-template-tag"` - Ulimits UlimitSlice `yaml:"ulimits,omitempty" json:"ulimits,omitempty" jsonschema:"description=Set the user limits for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-ulimits-tag"` - Volumes VolumeSlice `yaml:"volumes,omitempty" json:"volumes,omitempty" jsonschema:"description=Mount volumes for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-volume-tag"` - Image string `yaml:"image,omitempty" json:"image,omitempty" jsonschema:"oneof_required=image,minLength=1,description=Docker image to use to create the ephemeral container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-image-tag"` - Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"required,minLength=1,description=Unique name for the step.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-name-tag"` - Pull string `yaml:"pull,omitempty" json:"pull,omitempty" jsonschema:"enum=always,enum=not_present,enum=on_start,enum=never,default=not_present,description=Declaration to configure if and when the Docker image is pulled.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-pull-tag"` - Environment raw.StringSliceMap `yaml:"environment,omitempty" json:"environment,omitempty" jsonschema:"description=Provide environment variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-environment-tag"` - Parameters map[string]interface{} `yaml:"parameters,omitempty" json:"parameters,omitempty" jsonschema:"description=Extra configuration variables for a plugin.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-parameters-tag"` - Detach bool `yaml:"detach,omitempty" json:"detach,omitempty" jsonschema:"description=Run the container in a detached (headless) state.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-detach-tag"` - Privileged bool `yaml:"privileged,omitempty" json:"privileged,omitempty" jsonschema:"description=Run the container with extra privileges.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-privileged-tag"` - 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-tag"` + Ruleset Ruleset `yaml:"ruleset,omitempty" json:"ruleset,omitempty" jsonschema:"description=Conditions to limit the execution of the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-ruleset-tag"` + Commands raw.StringSlice `yaml:"commands,omitempty" json:"commands,omitempty" jsonschema:"description=Execution instructions to run inside the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-commands-tag"` + Entrypoint raw.StringSlice `yaml:"entrypoint,omitempty" json:"entrypoint,omitempty" jsonschema:"description=Command to execute inside the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-entrypoint-tag"` + Secrets StepSecretSlice `yaml:"secrets,omitempty" json:"secrets,omitempty" jsonschema:"description=Sensitive variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-secrets-tag"` + Template StepTemplate `yaml:"template,omitempty" json:"template,omitempty" jsonschema:"oneof_required=template,description=Name of template to expand in the pipeline.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-template-tag"` + Ulimits UlimitSlice `yaml:"ulimits,omitempty" json:"ulimits,omitempty" jsonschema:"description=Set the user limits for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-ulimits-tag"` + Volumes VolumeSlice `yaml:"volumes,omitempty" json:"volumes,omitempty" jsonschema:"description=Mount volumes for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-volume-tag"` + Image string `yaml:"image,omitempty" json:"image,omitempty" jsonschema:"oneof_required=image,minLength=1,description=Docker image to use to create the ephemeral container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-image-tag"` + Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"required,minLength=1,description=Unique name for the step.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-name-tag"` + Pull string `yaml:"pull,omitempty" json:"pull,omitempty" jsonschema:"enum=always,enum=not_present,enum=on_start,enum=never,default=not_present,description=Declaration to configure if and when the Docker image is pulled.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-pull-tag"` + Environment raw.StringSliceMap `yaml:"environment,omitempty" json:"environment,omitempty" jsonschema:"description=Provide environment variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-environment-tag"` + Parameters map[string]interface{} `yaml:"parameters,omitempty" json:"parameters,omitempty" jsonschema:"description=Extra configuration variables for a plugin.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-parameters-tag"` + Detach bool `yaml:"detach,omitempty" json:"detach,omitempty" jsonschema:"description=Run the container in a detached (headless) state.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-detach-tag"` + Privileged bool `yaml:"privileged,omitempty" json:"privileged,omitempty" jsonschema:"description=Run the container with extra privileges.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-privileged-tag"` + 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-tag"` + ReportStatus bool `yaml:"report_status,omitempty" json:"report_status,omitempty" jsonschema:"description=Report the status of the container to the SCM.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-report_status-tag"` } ) @@ -47,19 +48,20 @@ func (s *StepSlice) ToPipeline() *pipeline.ContainerSlice { for _, step := range *s { // append the element to the pipeline container slice *stepSlice = append(*stepSlice, &pipeline.Container{ - Commands: step.Commands, - Detach: step.Detach, - Entrypoint: step.Entrypoint, - Environment: step.Environment, - Image: step.Image, - Name: step.Name, - Privileged: step.Privileged, - Pull: step.Pull, - Ruleset: *step.Ruleset.ToPipeline(), - Secrets: *step.Secrets.ToPipeline(), - Ulimits: *step.Ulimits.ToPipeline(), - Volumes: *step.Volumes.ToPipeline(), - User: step.User, + Commands: step.Commands, + Detach: step.Detach, + Entrypoint: step.Entrypoint, + Environment: step.Environment, + Image: step.Image, + Name: step.Name, + Privileged: step.Privileged, + Pull: step.Pull, + Ruleset: *step.Ruleset.ToPipeline(), + Secrets: *step.Secrets.ToPipeline(), + Ulimits: *step.Ulimits.ToPipeline(), + Volumes: *step.Volumes.ToPipeline(), + User: step.User, + ReportStatus: step.ReportStatus, }) } From 07418c75ab800b7ccf151093d726278d4c37e9f5 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Fri, 1 Mar 2024 08:52:06 -0600 Subject: [PATCH 2/3] status report --- library/report.go | 219 ++++++++++++++++++++++++++++++++++++++++++ library/step.go | 27 ++++++ pipeline/container.go | 1 + yaml/step.go | 6 ++ 4 files changed, 253 insertions(+) create mode 100644 library/report.go diff --git a/library/report.go b/library/report.go new file mode 100644 index 00000000..661d845b --- /dev/null +++ b/library/report.go @@ -0,0 +1,219 @@ +// SPDX-License-Identifier: Apache-2.0 + +package library + +type Report struct { + Title *string `json:"title,omitempty"` + Summary *string `json:"summary,omitempty"` + Text *string `json:"text,omitempty"` + AnnotationsCount *int `json:"annotations_count,omitempty"` + AnnotationsURL *string `json:"annotations_url,omitempty"` + Annotations []*Annotation `json:"annotations,omitempty"` +} + +type Annotation struct { + Path *string `json:"path,omitempty"` + StartLine *int `json:"start_line,omitempty"` + EndLine *int `json:"end_line,omitempty"` + StartColumn *int `json:"start_column,omitempty"` + EndColumn *int `json:"end_column,omitempty"` + AnnotationLevel *string `json:"annotation_level,omitempty"` + Message *string `json:"message,omitempty"` + Title *string `json:"title,omitempty"` + RawDetails *string `json:"raw_details,omitempty"` +} + +// GetTitle returns the Title field. +// +// When the provided Report type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (r *Report) GetTitle() string { + // return zero value if Step type or ID field is nil + if r == nil || r.Title == nil { + return "" + } + + return *r.Title +} + +// GetSummary returns the Summary field. +// +// When the provided Report type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (r *Report) GetSummary() string { + // return zero value if Step type or ID field is nil + if r == nil || r.Summary == nil { + return "" + } + + return *r.Summary +} + +// GetText returns the Text field. +// +// When the provided Report type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (r *Report) GetText() string { + // return zero value if Step type or ID field is nil + if r == nil || r.Text == nil { + return "" + } + + return *r.Text +} + +// GetAnnotationsCount returns the AnnotationsCount field. +// +// When the provided Report type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (r *Report) GetAnnotationsCount() int { + // return zero value if Step type or ID field is nil + if r == nil || r.AnnotationsCount == nil { + return 0 + } + + return *r.AnnotationsCount +} + +// GetAnnotationsURL returns the AnnotationsURL field. +// +// When the provided Report type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (r *Report) GetAnnotationsURL() string { + // return zero value if Step type or ID field is nil + if r == nil || r.AnnotationsURL == nil { + return "" + } + + return *r.AnnotationsURL +} + +// GetAnnotations returns the Annotations field. +// +// When the provided Report type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (r *Report) GetAnnotations() []*Annotation { + // return zero value if Step type or ID field is nil + if r == nil || r.Annotations == nil { + return []*Annotation{} + } + + return r.Annotations +} + +// GetPath returns the Path field. +// +// When the provided Annotation type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (a *Annotation) GetPath() string { + // return zero value if Step type or ID field is nil + if a == nil || a.Path == nil { + return "" + } + + return *a.Path +} + +// GetStartLine returns the StartLine field. +// +// When the provided Annotation type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (a *Annotation) GetStartLine() int { + // return zero value if Step type or ID field is nil + if a == nil || a.StartLine == nil { + return 0 + } + + return *a.StartLine +} + +// GetEndLine returns the EndLine field. +// +// When the provided Annotation type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (a *Annotation) GetEndLine() int { + // return zero value if Step type or ID field is nil + if a == nil || a.EndLine == nil { + return 0 + } + + return *a.EndLine +} + +// GetStartColumn returns the StartColumn field. +// +// When the provided Annotation type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (a *Annotation) GetStartColumn() int { + // return zero value if Step type or ID field is nil + if a == nil || a.StartColumn == nil { + return 0 + } + + return *a.StartColumn +} + +// GetEndColumn returns the EndColumn field. +// +// When the provided Annotation type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (a *Annotation) GetEndColumn() int { + // return zero value if Step type or ID field is nil + if a == nil || a.EndColumn == nil { + return 0 + } + + return *a.EndColumn +} + +// GetAnnotationLevel returns the AnnotationLevel field. +// +// When the provided Annotation type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (a *Annotation) GetAnnotationLevel() string { + // return zero value if Step type or ID field is nil + if a == nil || a.AnnotationLevel == nil { + return "" + } + + return *a.AnnotationLevel +} + +// GetMessage returns the Message field. +// +// When the provided Annotation type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (a *Annotation) GetMessage() string { + // return zero value if Step type or ID field is nil + if a == nil || a.Message == nil { + return "" + } + + return *a.Message +} + +// GetTitle returns the Title field. +// +// When the provided Annotation type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (a *Annotation) GetTitle() string { + // return zero value if Step type or ID field is nil + if a == nil || a.Title == nil { + return "" + } + + return *a.Title +} + +// GetRawDetails returns the RawDetails field. +// +// When the provided Annotation type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (a *Annotation) GetRawDetails() string { + // return zero value if Step type or ID field is nil + if a == nil || a.RawDetails == nil { + return "" + } + + return *a.RawDetails +} diff --git a/library/step.go b/library/step.go index 89af8f9b..d9f4961a 100644 --- a/library/step.go +++ b/library/step.go @@ -32,6 +32,7 @@ type Step struct { Runtime *string `json:"runtime,omitempty"` Distribution *string `json:"distribution,omitempty"` CheckID *int64 `json:"check_id,omitempty"` + Report *Report `json:"report,omitempty"` } // Duration calculates and returns the total amount of @@ -304,6 +305,19 @@ func (s *Step) GetCheckID() int64 { return *s.CheckID } +// GetReport returns the Report field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetReport() *Report { + // return zero value if Report type is nil + if s == nil { + return nil + } + + return s.Report +} + // SetID sets the ID field. // // When the provided Step type is nil, it @@ -525,6 +539,19 @@ func (s *Step) SetCheckID(v int64) { s.CheckID = &v } +// SetReport sets the Report field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetReport(v *Report) { + // return if Report type is nil + if s == nil { + return + } + + s.Report = v +} + // String implements the Stringer interface for the Step type. func (s *Step) String() string { return fmt.Sprintf(`{ diff --git a/pipeline/container.go b/pipeline/container.go index 75282016..602e2575 100644 --- a/pipeline/container.go +++ b/pipeline/container.go @@ -52,6 +52,7 @@ type ( Volumes VolumeSlice `json:"volumes,omitempty" yaml:"volumes,omitempty"` User string `json:"user,omitempty" yaml:"user,omitempty"` ReportStatus bool `json:"report_status,omitempty" yaml:"report_status,omitempty"` + ReportPath string `json:"report_path,omitempty" yaml:"report_path,omitempty"` } ) diff --git a/yaml/step.go b/yaml/step.go index 57a72cc9..fe4bad3c 100644 --- a/yaml/step.go +++ b/yaml/step.go @@ -35,6 +35,7 @@ type ( Privileged bool `yaml:"privileged,omitempty" json:"privileged,omitempty" jsonschema:"description=Run the container with extra privileges.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-privileged-tag"` 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-tag"` ReportStatus bool `yaml:"report_status,omitempty" json:"report_status,omitempty" jsonschema:"description=Report the status of the container to the SCM.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-report_status-tag"` + ReportPath string `yaml:"report_path,omitempty" json:"report_path,omitempty" jsonschema:"description=Path to the file containing the status report.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-report_path-tag"` } ) @@ -62,6 +63,7 @@ func (s *StepSlice) ToPipeline() *pipeline.ContainerSlice { Volumes: *step.Volumes.ToPipeline(), User: step.User, ReportStatus: step.ReportStatus, + ReportPath: step.ReportPath, }) } @@ -110,6 +112,10 @@ func (s *StepSlice) UnmarshalYAML(unmarshal func(interface{}) error) error { if strings.EqualFold(step.Pull, "false") { step.Pull = constants.PullNotPresent } + + if len(step.ReportPath) > 0 && !strings.HasSuffix(step.ReportPath, ".json") && !strings.HasSuffix(step.ReportPath, ".JSON") { + step.ReportPath = fmt.Sprintf("%s.json", step.ReportPath) + } } // overwrite existing StepSlice From 189c0ac1213738aa65c9bb2ecb18c9c2ab655bfd Mon Sep 17 00:00:00 2001 From: ecrupper Date: Tue, 13 Aug 2024 07:20:52 -0500 Subject: [PATCH 3/3] updates --- library/step.go | 27 ++++++++++++++++++++++++ pipeline/container.go | 49 +++++++++++++++++++++++-------------------- 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/library/step.go b/library/step.go index 293efd36..719ce809 100644 --- a/library/step.go +++ b/library/step.go @@ -33,6 +33,7 @@ type Step struct { Distribution *string `json:"distribution,omitempty"` CheckID *int64 `json:"check_id,omitempty"` ReportAs *string `json:"report_as,omitempty"` + Report *Report `json:"report,omitempty"` } // Duration calculates and returns the total amount of @@ -319,6 +320,19 @@ func (s *Step) GetReportAs() string { return *s.ReportAs } +// GetReport returns the Report field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetReport() *Report { + // return zero value if Step type or Report field is nil + if s == nil || s.Report == nil { + return new(Report) + } + + return s.Report +} + // SetID sets the ID field. // // When the provided Step type is nil, it @@ -553,6 +567,19 @@ func (s *Step) SetReportAs(v string) { s.ReportAs = &v } +// SetReport sets the Report field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetReport(v *Report) { + // return if Step type is nil + if s == nil { + return + } + + s.Report = v +} + // String implements the Stringer interface for the Step type. func (s *Step) String() string { return fmt.Sprintf(`{ diff --git a/pipeline/container.go b/pipeline/container.go index 8e2e55f1..25447804 100644 --- a/pipeline/container.go +++ b/pipeline/container.go @@ -31,28 +31,30 @@ type ( // // swagger:model PipelineContainer Container struct { - ID string `json:"id,omitempty" yaml:"id,omitempty"` - Commands []string `json:"commands,omitempty" yaml:"commands,omitempty"` - Detach bool `json:"detach,omitempty" yaml:"detach,omitempty"` - Directory string `json:"directory,omitempty" yaml:"directory,omitempty"` - Entrypoint []string `json:"entrypoint,omitempty" yaml:"entrypoint,omitempty"` - Environment map[string]string `json:"environment,omitempty" yaml:"environment,omitempty"` - ExitCode int `json:"exit_code,omitempty" yaml:"exit_code,omitempty"` - Image string `json:"image,omitempty" yaml:"image,omitempty"` - Name string `json:"name,omitempty" yaml:"name,omitempty"` - Needs []string `json:"needs,omitempty" yaml:"needs,omitempty"` - Networks []string `json:"networks,omitempty" yaml:"networks,omitempty"` - Number int `json:"number,omitempty" yaml:"number,omitempty"` - Ports []string `json:"ports,omitempty" yaml:"ports,omitempty"` - Privileged bool `json:"privileged,omitempty" yaml:"privileged,omitempty"` - Pull string `json:"pull,omitempty" yaml:"pull,omitempty"` - Ruleset Ruleset `json:"ruleset,omitempty" yaml:"ruleset,omitempty"` - Secrets StepSecretSlice `json:"secrets,omitempty" yaml:"secrets,omitempty"` - Ulimits UlimitSlice `json:"ulimits,omitempty" yaml:"ulimits,omitempty"` - Volumes VolumeSlice `json:"volumes,omitempty" yaml:"volumes,omitempty"` - User string `json:"user,omitempty" yaml:"user,omitempty"` - ReportAs string `json:"report_as,omitempty" yaml:"report_as,omitempty"` - IDRequest string `json:"id_request,omitempty" yaml:"id_request,omitempty"` + ID string `json:"id,omitempty" yaml:"id,omitempty"` + Commands []string `json:"commands,omitempty" yaml:"commands,omitempty"` + Detach bool `json:"detach,omitempty" yaml:"detach,omitempty"` + Directory string `json:"directory,omitempty" yaml:"directory,omitempty"` + Entrypoint []string `json:"entrypoint,omitempty" yaml:"entrypoint,omitempty"` + Environment map[string]string `json:"environment,omitempty" yaml:"environment,omitempty"` + ExitCode int `json:"exit_code,omitempty" yaml:"exit_code,omitempty"` + Image string `json:"image,omitempty" yaml:"image,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Needs []string `json:"needs,omitempty" yaml:"needs,omitempty"` + Networks []string `json:"networks,omitempty" yaml:"networks,omitempty"` + Number int `json:"number,omitempty" yaml:"number,omitempty"` + Ports []string `json:"ports,omitempty" yaml:"ports,omitempty"` + Privileged bool `json:"privileged,omitempty" yaml:"privileged,omitempty"` + Pull string `json:"pull,omitempty" yaml:"pull,omitempty"` + Ruleset Ruleset `json:"ruleset,omitempty" yaml:"ruleset,omitempty"` + Secrets StepSecretSlice `json:"secrets,omitempty" yaml:"secrets,omitempty"` + Ulimits UlimitSlice `json:"ulimits,omitempty" yaml:"ulimits,omitempty"` + Volumes VolumeSlice `json:"volumes,omitempty" yaml:"volumes,omitempty"` + User string `json:"user,omitempty" yaml:"user,omitempty"` + ReportAs string `json:"report_as,omitempty" yaml:"report_as,omitempty"` + IDRequest string `json:"id_request,omitempty" yaml:"id_request,omitempty"` + ReportStatus bool `json:"report_status,omitempty" yaml:"report_status,omitempty"` + ReportPath string `json:"report_path,omitempty" yaml:"report_path,omitempty"` } ) @@ -137,7 +139,8 @@ func (c *Container) Empty() bool { len(c.Volumes) == 0 && len(c.User) == 0 && len(c.ReportAs) == 0 && - len(c.IDRequest) == 0 { + len(c.IDRequest) == 0 && + len(c.ReportPath) == 0 { return true }