Skip to content

Commit e32b720

Browse files
Allow both :: and . for internal exec placeholders
1 parent 6dcb528 commit e32b720

4 files changed

Lines changed: 20 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Here's an example *captainhook.json* configuration file.
5959
"commit-msg": {
6060
"actions": [
6161
{
62-
"run": "CaptainHook::Message.MustFollowBeamsRules"
62+
"run": "CaptainHook.Message.MustFollowBeamsRules"
6363
}
6464
]
6565
},
@@ -73,7 +73,7 @@ Here's an example *captainhook.json* configuration file.
7373
"pre-push": {
7474
"actions": [
7575
{
76-
"run": "CaptainHook::Branch.PreventPushOfFixupAndSquashCommits",
76+
"run": "CaptainHook.Branch.PreventPushOfFixupAndSquashCommits",
7777
"options": {
7878
"branches-to-protect": ["main", "integration"]
7979
}

exec/condition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (c *ConditionRunner) createInternalCondition(condition *configuration.Condi
5454
path := splitInternalPath(condition.Run())
5555
conditionGenerator, err := conditions.ConditionCreationFunc(path)
5656
if err != nil {
57-
c.cIO.Write("ConditionRunner: "+condition.Run()+"\n"+err.Error(), true, io.NORMAL)
57+
c.cIO.Write("ConditionRunner: "+condition.Run()+"\n"+err.Error(), true, io.QUIET)
5858
return nil, err
5959
}
6060
return conditionGenerator(c.cIO, c.conf, c.repo), nil

exec/helper.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,32 @@ import (
66
)
77

88
// isILogicCondition checks if the condition is an "AND" or an "OR" condition
9-
func isLogicCondition(action string) bool {
10-
return strings.HasPrefix(strings.ToLower(action), "captainhook::logic")
9+
func isLogicCondition(exec string) bool {
10+
return strings.HasPrefix(strings.ToLower(exec), "captainhook::logic") ||
11+
strings.HasPrefix(strings.ToLower(exec), "captainhook.logic")
1112
}
1213

1314
// isInternalFunctionality answers if an action should trigger internal CaptainHook functionality
14-
func isInternalFunctionality(action string) bool {
15-
return strings.HasPrefix(strings.ToLower(action), "captainhook::")
15+
func isInternalFunctionality(exec string) bool {
16+
return strings.HasPrefix(strings.ToLower(exec), "captainhook::") ||
17+
strings.HasPrefix(strings.ToLower(exec), "captainhook.")
1618
}
1719

1820
// splitInternalPath is determining the internal functionality to call
1921
// Internal paths consist of two blocks separated by .
2022
//
2123
// Examples:
2224
// - CaptainHook::SOME.FUNCTIONALITY
23-
// - CaptainHook::Branch.EnsureNaming
24-
func splitInternalPath(action string) []string {
25-
actionPath := strings.Split(action, "::")[1]
26-
return strings.Split(actionPath, ".")
25+
// - CaptainHook.Branch.EnsureNaming
26+
func splitInternalPath(exec string) []string {
27+
var prefix string
28+
if strings.HasPrefix(strings.ToLower(exec), "captainhook::") {
29+
prefix = "captainhook::"
30+
} else {
31+
prefix = "captainhook."
32+
}
33+
pathInfo := strings.Replace(strings.ToLower(exec), prefix, "", 1)
34+
return strings.Split(pathInfo, ".")
2735
}
2836

2937
// isSymlink checks if a file is a symlink

hooks/actions/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var (
4747
// ActionCreationFunc is returning a function to create the configured action
4848
func ActionCreationFunc(path []string) (func(appIO io.IO, conf *configuration.Configuration, repo git.Repo) hooks.Action, error) {
4949
if len(path) != 2 {
50-
return nil, errors.New("invalid actions functionality")
50+
return nil, errors.New("invalid action functionality")
5151
}
5252

5353
for index, value := range path {

0 commit comments

Comments
 (0)