Adding Initial action (#1)

Co-authored-by: kjuulh <contact@kjuulh.io>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/kraken/pulls/1
This commit is contained in:
2022-09-12 22:12:02 +02:00
parent b3302bb3c6
commit 50228f0aff
23 changed files with 1155 additions and 59 deletions

View File

@@ -0,0 +1,43 @@
package actions
import (
"context"
"git.front.kjuulh.io/kjuulh/kraken/internal/services/storage"
"go.uber.org/zap"
)
type Predicate func(ctx context.Context, area *storage.Area) (bool, error)
type ActionFunc func(ctx context.Context, area *storage.Area) error
type Action struct {
logger *zap.Logger
}
func NewAction(logger *zap.Logger) *Action {
return &Action{logger: logger}
}
func (a *Action) Run(ctx context.Context, area *storage.Area, predicate Predicate, action ActionFunc, dryrun bool) error {
matches, err := predicate(ctx, area)
if err != nil {
return err
}
if !matches {
a.logger.Debug("repo doesn't match, skipping", zap.String("path", area.Path))
return nil
}
if dryrun {
a.logger.Panic("dryrun selected, but not implemented yet")
return nil
}
err = action(ctx, area)
if err != nil {
return err
}
return nil
}