Skip to content

Commit

Permalink
status report
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Mar 1, 2024
1 parent 3eb3f79 commit 07418c7
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 0 deletions.
219 changes: 219 additions & 0 deletions library/report.go
Original file line number Diff line number Diff line change
@@ -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
}
27 changes: 27 additions & 0 deletions library/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(`{
Expand Down
1 change: 1 addition & 0 deletions pipeline/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
)

Expand Down
6 changes: 6 additions & 0 deletions yaml/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
)

Expand Down Expand Up @@ -62,6 +63,7 @@ func (s *StepSlice) ToPipeline() *pipeline.ContainerSlice {
Volumes: *step.Volumes.ToPipeline(),
User: step.User,
ReportStatus: step.ReportStatus,
ReportPath: step.ReportPath,
})
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 07418c7

Please sign in to comment.