-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhelpers.go
52 lines (41 loc) · 1.21 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package gittp
import (
"errors"
"regexp"
)
// CreateRepo will always create a new repository if one does not exist
func CreateRepo(reponame string) bool {
return true
}
// DenyCreateRepo will always deny creation of new repositories over git push
func DenyCreateRepo(reponame string) bool {
return false
}
var repoRegex = regexp.MustCompile("^(?:[\\w]+)/([\\w]+)")
// UseGithubRepoNames enforces paths like /username/projectname.git
func UseGithubRepoNames(reponame string) bool {
return repoRegex.MatchString(reponame)
}
// MasterOnly is a pre receive hook that only allows pushes to master
func MasterOnly(h *HookContext) error {
if h.Branch == "refs/heads/master" {
return nil
}
h.Fatal("Only ref updates to refs/heads/master are allowed.")
return errors.New("hook declined")
}
// CombinePreHooks combines several PreReceiveHooks into one
func CombinePreHooks(hooks ...PreReceiveHook) PreReceiveHook {
return func(h *HookContext) error {
for _, prh := range hooks {
if err := prh(h); err != nil {
return err
}
}
return nil
}
}
// NoopPreReceive is a pre receive hook that is always successfull. This is the default if no hook is defined
func NoopPreReceive(h *HookContext) error {
return nil
}