-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add general action for building both commands and do actions
- Loading branch information
Showing
16 changed files
with
370 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package action | ||
|
||
import ( | ||
"github.com/evilmartians/lefthook/internal/config" | ||
"github.com/evilmartians/lefthook/internal/git" | ||
"github.com/evilmartians/lefthook/internal/system" | ||
) | ||
|
||
type Params struct { | ||
Repo *git.Repository | ||
Hook *config.Hook | ||
HookName string | ||
GitArgs []string | ||
Force bool | ||
ForceFiles []string | ||
|
||
Run string | ||
Root string | ||
Glob string | ||
Files string | ||
FileTypes []string | ||
Tags []string | ||
Exclude interface{} | ||
Only interface{} | ||
Skip interface{} | ||
} | ||
|
||
type Action struct { | ||
Execs []string | ||
Files []string | ||
} | ||
|
||
func New(name string, params *Params) (*Action, error) { | ||
if params.skip() { | ||
return nil, SkipError{"settings"} | ||
} | ||
|
||
if intersect(params.Hook.ExcludeTags, params.Tags) { | ||
return nil, SkipError{"tags"} | ||
} | ||
|
||
if intersect(params.Hook.ExcludeTags, []string{name}) { | ||
return nil, SkipError{"name"} | ||
} | ||
|
||
if err := params.validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
action, err := build(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return action, nil | ||
} | ||
|
||
func (p *Params) skip() bool { | ||
skipChecker := config.NewSkipChecker(system.Cmd) | ||
return skipChecker.Check(p.Repo.State, p.Skip, p.Only) | ||
} | ||
|
||
func (p *Params) validate() error { | ||
if !config.IsRunnerFilesCompatible(p.Run) { | ||
return config.ErrFilesIncompatible | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func intersect(a, b []string) bool { | ||
intersections := make(map[string]struct{}, len(a)) | ||
|
||
for _, v := range a { | ||
intersections[v] = struct{}{} | ||
} | ||
|
||
for _, v := range b { | ||
if _, ok := intersections[v]; ok { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
Oops, something went wrong.