Skip to content

Commit

Permalink
add ToolExecutionNotifications
Browse files Browse the repository at this point in the history
  • Loading branch information
shaopeng-gh committed Sep 16, 2022
1 parent c621d4b commit 37bbd09
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
15 changes: 11 additions & 4 deletions sarif/invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import "time"
// Invocation describes the runtime environment of the analysis tool run.
type Invocation struct {
PropertyBag
StartTimeUTC *time.Time `json:"startTimeUtc,omitempty"`
EndTimeUTC *time.Time `json:"endTimeUtc,omitempty"`
ExecutionSuccessful bool `json:"executionSuccessful"`
WorkingDirectory *ArtifactLocation `json:"workingDirectory,omitempty"`
StartTimeUTC *time.Time `json:"startTimeUtc,omitempty"`
EndTimeUTC *time.Time `json:"endTimeUtc,omitempty"`
ExecutionSuccessful bool `json:"executionSuccessful"`
WorkingDirectory *ArtifactLocation `json:"workingDirectory,omitempty"`
ToolExecutionNotifications []*Notification `json:"toolExecutionNotifications,omitempty"`
}

// WithStartTimeUTC sets the instant when the invocation started and returns the same Invocation.
Expand All @@ -30,3 +31,9 @@ func (i *Invocation) WithWorkingDirectory(workingDirectory *ArtifactLocation) *I
i.WorkingDirectory = workingDirectory
return i
}

// WithToolExecutionNotifications ...
func (i *Invocation) WithToolExecutionNotifications(notification *Notification) *Invocation {
i.ToolExecutionNotifications = append(i.ToolExecutionNotifications, notification)
return i
}
48 changes: 48 additions & 0 deletions sarif/notification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package sarif

// Notification represents different Notifications in the SARIF spec
type Notification struct {
PropertyBag
Level *string `json:"level,omitempty"`
Message Message `json:"message"`
Locations []*Location `json:"locations,omitempty"`
Properties Properties `json:"properties,omitempty"`
}

// NewNotification ...
func NewNotification() *Notification {
return &Notification{}
}

func newLevelNotification(level string) *Notification {
return NewNotification().WithLevel(level)
}

// WithLevel ...
func (n *Notification) WithLevel(level string) *Notification {
n.Level = &level
return n
}

// WithMessage ...
func (n *Notification) WithMessage(message *Message) *Notification {
n.Message = *message
return n
}

// WithLocation ...
func (n *Notification) WithLocation(location *Location) *Notification {
n.Locations = append(n.Locations, location)
return n
}

// WithProperties specifies properties for a rule and returns the updated rule
func (n *Notification) WithProperties(properties Properties) *Notification {
n.Properties = properties
return n
}

// AttachPropertyBag adds a property bag to a rule
func (n *Notification) AttachPropertyBag(pb *PropertyBag) {
n.Properties = pb.Properties
}

0 comments on commit 37bbd09

Please sign in to comment.