-
Notifications
You must be signed in to change notification settings - Fork 342
/
hooks_handler.go
61 lines (49 loc) · 1.34 KB
/
hooks_handler.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
53
54
55
56
57
58
59
60
61
package graveler
import (
"context"
"time"
nanoid "github.com/matoous/go-nanoid/v2"
)
type EventType string
const (
EventTypePreCommit EventType = "pre-commit"
EventTypePostCommit EventType = "post-commit"
EventTypePreMerge EventType = "pre-merge"
EventTypePostMerge EventType = "post-merge"
)
type HookRecord struct {
RunID string
EventType EventType
RepositoryID RepositoryID
StorageNamespace StorageNamespace
BranchID BranchID
SourceRef Ref
Commit Commit
CommitID CommitID
PreRunID string
}
type HooksHandler interface {
PreCommitHook(ctx context.Context, record HookRecord) error
PostCommitHook(ctx context.Context, record HookRecord) error
PreMergeHook(ctx context.Context, record HookRecord) error
PostMergeHook(ctx context.Context, record HookRecord) error
}
type HooksNoOp struct{}
func (h *HooksNoOp) PreCommitHook(context.Context, HookRecord) error {
return nil
}
func (h *HooksNoOp) PostCommitHook(context.Context, HookRecord) error {
return nil
}
func (h *HooksNoOp) PreMergeHook(context.Context, HookRecord) error {
return nil
}
func (h *HooksNoOp) PostMergeHook(context.Context, HookRecord) error {
return nil
}
func NewRunID() string {
const nanoLen = 8
id := nanoid.Must(nanoLen)
tm := time.Now().UTC().Format("20060102150405")
return tm + id
}