Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Yauheni Abramovich committed Oct 24, 2023
1 parent dea33a4 commit d2d8f4d
Show file tree
Hide file tree
Showing 77 changed files with 289 additions and 295 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ vars:
GIT_COMMIT:
sh: git log -n 1 --format=%h
VERSION_PATH: fisherman/internal/constants.Version
ENTRY_POINT: ./cmd/fisherman/...
ENTRY_POINT: ./main.go
OUTPUT_FILE: fisherman{{exeExt}}

tasks:
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Condition expressions
---

Fisherman uses expressions to define a condition for executing a rule. In this
document, you can find all supported syntaxes.
document, you can find all supported syntax's.

### Supported Literals

Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/rules/shell-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ it can be set with the following code:
- type: shell-script
commands: [ 'command1', 'command2' ]
# multilane array
# multiline array
- type: shell-script
commands:
- 'command1 arg1 arg2'
Expand Down
2 changes: 1 addition & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: FAQ
slug: /faq
---

## I want check commit prefix based on current brach name
## I want check commit prefix based on current branch name

Can be used to check that message starts with issue number.

Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ cd fisherman
# Compiling binary to $GOPATH/bin:
task install
# Or without task:
go install -v ./cmd/fisherman/main.go
go install -v ./main.go

# Compiling it to another location:
task build
# Or without task (Note: replace <version> to fisherman version):
go build -v -ldflags="-s -w -X fisherman/internal/constants.Version=<version>" ./cmd/fisherman/main.go -o fisherman
go build -v -ldflags="-s -w -X fisherman/internal/constants.Version=<version>" ./main.go -o fisherman

./fisherman
```
Expand Down
12 changes: 6 additions & 6 deletions internal/app/fisherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type FishermanApp struct {
}

// NewFishermanApp is an fisherman application constructor.
func NewFishermanApp(options ...appOption) *FishermanApp {
func NewFishermanApp(options ...AppOption) *FishermanApp {
app := FishermanApp{
commands: CliCommands{},
cwd: "",
Expand All @@ -34,8 +34,8 @@ func NewFishermanApp(options ...appOption) *FishermanApp {
// Run runs fisherman application.
func (r *FishermanApp) Run(baseCtx context.Context, args []string) error {
ctx, cancel := context.WithCancel(baseCtx)
subscribeInteruption(r.interruption, func() {
log.Debug("application received interapt event")
subscribeInterruption(r.interruption, func() {
log.Debug("application received interact event")
cancel()
})

Expand All @@ -58,14 +58,14 @@ func (r *FishermanApp) Run(baseCtx context.Context, args []string) error {
return err
}

log.Debugf("Command '%s' finished witout error", command.Name())
log.Debugf("Command '%s' finished without error", command.Name())

return nil
}

func subscribeInteruption(interaption chan os.Signal, action func()) {
func subscribeInterruption(interruption chan os.Signal, action func()) {
go func() {
<-interaption
<-interruption
action()
}()
}
Expand Down
6 changes: 3 additions & 3 deletions internal/app/fisherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestRunner_Run(t *testing.T) {
expectedErr string
}{
{
name: "should run called commnad and return its error",
name: "should run called command and return its error",
args: []string{"init"},
commands: []internal.CliCommand{
makeCommand(t, "handle"),
Expand All @@ -40,7 +40,7 @@ func TestRunner_Run(t *testing.T) {
expectedErr: "expected error",
},
{
name: "should run called commnad and return nil when command executed witout error",
name: "should run called command and return nil when command executed without error",
args: []string{"init"},
commands: []internal.CliCommand{
makeCommand(t, "handle"),
Expand All @@ -65,7 +65,7 @@ func TestRunner_Run(t *testing.T) {
expectedErr: "unknown command: not",
},
{
name: "should not return error when commnad not specified",
name: "should not return error when command not specified",
args: []string{},
commands: []internal.CliCommand{
makeCommand(t, "handle"),
Expand Down
10 changes: 5 additions & 5 deletions internal/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ import (
"os/signal"
)

type appOption = func(app *FishermanApp)
type AppOption = func(app *FishermanApp)

// WithCommands setups commands lists for application.
func WithCommands(commands []internal.CliCommand) appOption {
func WithCommands(commands []internal.CliCommand) AppOption {
return func(app *FishermanApp) {
app.commands = commands
}
}

// WithCwd setups current working directory (CWD) for application.
func WithCwd(cwd string) appOption {
func WithCwd(cwd string) AppOption {
return func(app *FishermanApp) {
app.cwd = cwd
}
}

func WithSistemInterruptSignals() appOption {
func WithSistermInterruptSignals() AppOption {
return func(app *FishermanApp) {
app.interruption = make(chan os.Signal, 1)
signal.Notify(app.interruption, os.Interrupt)
}
}

func WithInterruptChanel(chanel chan os.Signal) appOption {
func WithInterruptChanel(chanel chan os.Signal) AppOption {
return func(app *FishermanApp) {
app.interruption = chanel
}
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/handle/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Command struct {

const defaultWorkerCount = 5

func NewCommand(options ...commandOption) *Command {
func NewCommand(options ...CommandOption) *Command {
command := &Command{
flagSet: flag.NewFlagSet("handle", flag.ExitOnError),
usage: "starts hook processing based on the config file (for debugging only)",
Expand Down
22 changes: 11 additions & 11 deletions internal/commands/handle/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,63 @@ import (
"github.com/go-git/go-billy/v5"
)

type commandOption = func(*Command)
type CommandOption = func(*Command)

func WithExpressionEngine(engine expression.Engine) commandOption {
func WithExpressionEngine(engine expression.Engine) CommandOption {
return func(h *Command) {
h.engine = engine
}
}

func WithHooksConfig(config *configuration.HooksConfig) commandOption {
func WithHooksConfig(config *configuration.HooksConfig) CommandOption {
return func(h *Command) {
h.config = config
}
}

func WithGlobalVars(globalVars map[string]any) commandOption {
func WithGlobalVars(globalVars map[string]any) CommandOption {
return func(h *Command) {
h.globalVars = globalVars
}
}

func WithCwd(cwd string) commandOption {
func WithCwd(cwd string) CommandOption {
return func(h *Command) {
h.cwd = cwd
}
}

func WithFileSystem(fs billy.Filesystem) commandOption {
func WithFileSystem(fs billy.Filesystem) CommandOption {
return func(h *Command) {
h.fs = fs
}
}

func WithRepository(repo internal.Repository) commandOption {
func WithRepository(repo internal.Repository) CommandOption {
return func(h *Command) {
h.repo = repo
}
}

func WithEnv(env []string) commandOption {
func WithEnv(env []string) CommandOption {
return func(h *Command) {
h.env = env
}
}

func WithWorkersCount(workersCount uint) commandOption {
func WithWorkersCount(workersCount uint) CommandOption {
return func(h *Command) {
h.workersCount = workersCount
}
}

func WithConfigFiles(configFiles map[string]string) commandOption {
func WithConfigFiles(configFiles map[string]string) CommandOption {
return func(h *Command) {
h.configFiles = configFiles
}
}

func WithOutput(output io.Writer) commandOption {
func WithOutput(output io.Writer) CommandOption {
return func(h *Command) {
h.output = output
}
Expand Down
6 changes: 3 additions & 3 deletions internal/commands/initialize/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func (c *Command) Run(_ context.Context, args []string) error {
return err
}

log.Debugf("Statring initialization (force = %t)", c.force)
log.Debugf("Stating initialization (force = %t)", c.force)
if !c.force {
var result *multierror.Error
for _, hookName := range constants.HooksNames {
hookPath := filepath.Join(c.cwd, ".git", "hooks", hookName)
log.Debugf("Cheking hook '%s' (%s)", hookName, hookPath)
log.Debugf("Checking hook '%s' (%s)", hookName, hookPath)
exist, err := utils.Exists(c.fs, hookPath)
if err != nil {
return err
Expand All @@ -98,7 +98,7 @@ func (c *Command) Run(_ context.Context, args []string) error {
return err
}

log.Infof("Hook '%s' (%s) was writted", hookName, hookPath)
log.Infof("Hook '%s' (%s) was written", hookName, hookPath)
}

return c.writeConfig()
Expand Down
8 changes: 4 additions & 4 deletions internal/commands/remove/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"github.com/go-git/go-billy/v5"
)

type removeOption = func(c *Command)
type RemoveOption = func(c *Command)

func WithCwd(cwd string) removeOption {
func WithCwd(cwd string) RemoveOption {
return func(c *Command) {
c.cwd = cwd
}
}

func WithFileSystem(fs billy.Filesystem) removeOption {
func WithFileSystem(fs billy.Filesystem) RemoveOption {
return func(c *Command) {
c.fs = fs
}
}

func WithConfigFiles(configs map[string]string) removeOption {
func WithConfigFiles(configs map[string]string) RemoveOption {
return func(c *Command) {
c.configFiles = configs
}
Expand Down
22 changes: 11 additions & 11 deletions internal/commands/remove/remove.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package remove

import (
"context"
"flag"
"github.com/evg4b/fisherman/internal/constants"
"github.com/evg4b/fisherman/internal/utils"
"github.com/evg4b/fisherman/pkg/guards"
"github.com/evg4b/fisherman/pkg/log"
"path/filepath"

"github.com/go-git/go-billy/v5"
"context"
"flag"
"github.com/evg4b/fisherman/internal/constants"
"github.com/evg4b/fisherman/internal/utils"
"github.com/evg4b/fisherman/pkg/guards"
"github.com/evg4b/fisherman/pkg/log"
"path/filepath"

"github.com/go-git/go-billy/v5"
)

type Command struct {
Expand All @@ -20,7 +20,7 @@ type Command struct {
configFiles map[string]string
}

func NewCommand(options ...removeOption) *Command {
func NewCommand(options ...RemoveOption) *Command {
command := &Command{
flagSet: flag.NewFlagSet("remove", flag.ExitOnError),
usage: "removes fisherman from git repository",
Expand All @@ -43,7 +43,7 @@ func (c *Command) Run(_ context.Context, args []string) error {
return err
}

filesToDelete := []string{}
filesToDelete := make([]string, 0, len(c.configFiles)+len(constants.HooksNames))
for _, config := range c.configFiles {
filesToDelete = append(filesToDelete, config)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/configuration/hook_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type Rule interface {
GetType() string
GetPrefix() string
GetContition() string
GetCondition() string
GetPosition() byte
Check(ctx context.Context, writer io.Writer) error
Compile(variables map[string]any)
Expand Down
8 changes: 4 additions & 4 deletions internal/configuration/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func FindConfigFiles(usr *user.User, cwd string, fs billy.Filesystem) (map[strin
return nil, err
}

files := []string{}
var files []string
for _, name := range constants.AppConfigNames {
configPath := filepath.Join(folder, name)
exist, err := utils.Exists(fs, configPath)
Expand Down Expand Up @@ -72,7 +72,7 @@ func Load(fs billy.Filesystem, files map[string]string) (*FishermanConfig, error
for _, mode := range ModeOptions {
file, ok := files[mode]
if ok {
loadedConfig, err := unmarshlFile(fs, file)
loadedConfig, err := unmarshalFile(fs, file)
if err != nil {
return &config, err
}
Expand All @@ -84,11 +84,11 @@ func Load(fs billy.Filesystem, files map[string]string) (*FishermanConfig, error
}
}

// TODO: incorrect log level marging
// TODO: incorrect log level margin
return &config, nil
}

func unmarshlFile(fs billy.Filesystem, path string) (*FishermanConfig, error) {
func unmarshalFile(fs billy.Filesystem, path string) (*FishermanConfig, error) {
var config FishermanConfig

file, err := fs.Open(path)
Expand Down
2 changes: 1 addition & 1 deletion internal/configuration/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ hooks:
}
})

t.Run("files megred on loading", func(t *testing.T) {
t.Run("files merged on loading", func(t *testing.T) {
fs := testutils.FsFromMap(t, map[string]string{
"global.yaml": `
variables:
Expand Down
2 changes: 1 addition & 1 deletion internal/constants/graphics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package constants

// Logo is a logotip of fisherman.
// Logo is a logotype of fisherman.
var Logo = `
.d888 d8b 888
d88P" Y8P 888 Version: {{FishermanVersion}}
Expand Down
4 changes: 2 additions & 2 deletions internal/handling/allowed_hooks.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package handling

import (
"github.com/evg4b/fisherman/internal/constants"
"github.com/evg4b/fisherman/internal/rules"
"github.com/evg4b/fisherman/internal/constants"
"github.com/evg4b/fisherman/internal/rules"
)

var allowedHooks = map[string][]string{
Expand Down
Loading

0 comments on commit d2d8f4d

Please sign in to comment.