octopush/internal/services/actions/action.go
kjuulh 46cc160764
Examples, rename and fixes
updated roadmap

updated roadmap

Add a basic readme (#15)

Co-authored-by: kjuulh <contact@kjuulh.io>
Reviewed-on: kjuulh/kraken#15

fix readme

Add readme

with stuff

more roadmap items

update formatting

formatting 2

more setup

with semantic

with semantic 2

revert

add releaserc

with releaser

with kraken

Update roadmap

rename

rename

feature/move-command (#18)

Co-authored-by: kjuulh <contact@kjuulh.io>
Reviewed-on: #18

fix/require-two-pushes (#20)

Co-authored-by: kjuulh <contact@kjuulh.io>
Reviewed-on: #20
2022-09-21 22:52:24 +02:00

44 lines
864 B
Go

package actions
import (
"context"
"git.front.kjuulh.io/kjuulh/octopush/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
}