start with action logger
This commit is contained in:
@@ -46,7 +46,7 @@ func New(ctx context.Context, config Config, opts ...Option) (*App, func(), erro
|
|||||||
StartTime: time.Now(),
|
StartTime: time.Now(),
|
||||||
})
|
})
|
||||||
|
|
||||||
jsonStatService, err := NewStatisticsService(statStore)
|
jsonStatService, err := NewStatisticsService(statStore, b.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -60,6 +60,7 @@ func New(ctx context.Context, config Config, opts ...Option) (*App, func(), erro
|
|||||||
|
|
||||||
Issues: b.issueService,
|
Issues: b.issueService,
|
||||||
Stats: b.statsService,
|
Stats: b.statsService,
|
||||||
|
ActionLogger: config.ActionLogger,
|
||||||
}
|
}
|
||||||
|
|
||||||
return app, b.lifecycle.Close, nil
|
return app, b.lifecycle.Close, nil
|
||||||
|
|||||||
29
internal/models/action_event.go
Normal file
29
internal/models/action_event.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type ActionEvent struct {
|
||||||
|
Source string `json:"source"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
Target string `json:"target,omitempty"`
|
||||||
|
Result string `json:"result,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func EncodeActionEvent(event ActionEvent) string {
|
||||||
|
bytes, err := json.Marshal(event)
|
||||||
|
if err != nil {
|
||||||
|
return event.Action
|
||||||
|
}
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DecodeActionEvent(raw string) (ActionEvent, bool) {
|
||||||
|
var event ActionEvent
|
||||||
|
if err := json.Unmarshal([]byte(raw), &event); err != nil {
|
||||||
|
return ActionEvent{}, false
|
||||||
|
}
|
||||||
|
if event.Source == "" && event.Action == "" && event.Target == "" && event.Result == "" {
|
||||||
|
return ActionEvent{}, false
|
||||||
|
}
|
||||||
|
return event, true
|
||||||
|
}
|
||||||
@@ -16,6 +16,19 @@ type App struct {
|
|||||||
Interfaces map[string]Interface
|
Interfaces map[string]Interface
|
||||||
|
|
||||||
CurrentFeedback *ValidationFeedback
|
CurrentFeedback *ValidationFeedback
|
||||||
|
ActionLogger func(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) LogAction(action string) {
|
||||||
|
if a == nil || action == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if a.Logger != nil {
|
||||||
|
a.Logger.Info("action event", "action", action)
|
||||||
|
}
|
||||||
|
if a.ActionLogger != nil {
|
||||||
|
a.ActionLogger(action)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IssueService defines the interface for managing issues in the application.
|
// IssueService defines the interface for managing issues in the application.
|
||||||
@@ -42,4 +55,5 @@ type StatsService interface {
|
|||||||
Load(ctx context.Context) error
|
Load(ctx context.Context) error
|
||||||
Save(ctx context.Context) error
|
Save(ctx context.Context) error
|
||||||
GetStatistics() (Statistics, error)
|
GetStatistics() (Statistics, error)
|
||||||
|
RecordTaskRun(ctx context.Context, run TaskRunMetrics) error
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user