diff --git a/database/repo.go b/database/repo.go index 5c4f8c2c..99ce6eb2 100644 --- a/database/repo.go +++ b/database/repo.go @@ -66,6 +66,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 @@ -206,6 +207,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 } @@ -235,6 +241,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 } @@ -327,6 +334,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 34304168..41f2808a 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"` ReportAs sql.NullString `sql:"report_as"` } @@ -143,6 +144,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 + } + // check if the ReportAs field should be false if len(s.ReportAs.String) == 0 { s.ReportAs.Valid = false @@ -172,6 +178,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) step.SetReportAs(s.ReportAs.String) return step @@ -241,6 +248,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}, ReportAs: sql.NullString{String: s.GetReportAs(), Valid: true}, } diff --git a/library/repo.go b/library/repo.go index 46c87df7..06cef929 100644 --- a/library/repo.go +++ b/library/repo.go @@ -32,6 +32,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"` } // UnmarshalYAML implements the Unmarshaler interface for the Repo type. @@ -73,6 +74,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()), @@ -363,6 +365,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 @@ -636,6 +651,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. func (r *Repo) String() string { return fmt.Sprintf(`{ @@ -648,6 +676,7 @@ func (r *Repo) String() string { Counter: %d, FullName: %s, ID: %d, + InstallID: %d, Link: %s, Name: %s, Org: %s, @@ -669,6 +698,7 @@ func (r *Repo) String() string { r.GetCounter(), r.GetFullName(), r.GetID(), + r.GetInstallID(), r.GetLink(), r.GetName(), r.GetOrg(), 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 bf33ae5c..719ce809 100644 --- a/library/step.go +++ b/library/step.go @@ -31,7 +31,9 @@ type Step struct { Host *string `json:"host,omitempty"` Runtime *string `json:"runtime,omitempty"` 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 @@ -79,6 +81,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()), "VELA_STEP_REPORT_AS": ToString(s.GetReportAs()), } } @@ -291,6 +294,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 +} + // GetReportAs returns the ReportAs field. // // When the provided Step type is nil, or the field within @@ -304,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 @@ -512,6 +541,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 +} + // SetReportAs sets the ReportAs field. // // When the provided Step type is nil, it @@ -525,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(`{ @@ -540,6 +595,7 @@ func (s *Step) String() string { Name: %s, Number: %d, RepoID: %d, + CheckID: %d, ReportAs: %s, Runtime: %s, Stage: %s, @@ -558,6 +614,7 @@ func (s *Step) String() string { s.GetName(), s.GetNumber(), s.GetRepoID(), + s.GetCheckID(), s.GetReportAs(), s.GetRuntime(), s.GetStage(), 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 }