Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fcea63a

Browse files
Update event type validation method to IsValid and add code generation tool for validation methods. (#9403)
1 parent 42b050a commit fcea63a

File tree

4 files changed

+199
-27
lines changed

4 files changed

+199
-27
lines changed

‎pkg/actions/action.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (a *Action) Validate() error {
101101
}
102102

103103
func validateEvent(event graveler.EventType, on *ActionOn) error {
104-
if !event.Valid() {
104+
if !event.IsValid() {
105105
return fmt.Errorf("event '%s' is not supported: %w", event, ErrInvalidAction)
106106
}
107107
if on != nil {

‎pkg/graveler/hooks_handler.go‎

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package graveler
22

3+
//go:generate go run github.com/treeverse/lakefs/tools/isvalidgen --source ./hooks_handler.go --type EventType
4+
35
import (
46
"context"
57
"time"
@@ -28,34 +30,10 @@ const (
2830
EventTypePostRevert EventType = "post-revert"
2931
EventTypePreCherryPick EventType = "pre-cherry-pick"
3032
EventTypePostCherryPick EventType = "post-cherry-pick"
31-
32-
UnixYear3000 = 32500915200
3333
)
3434

35-
func (e EventType) Valid() bool {
36-
switch e {
37-
case EventTypePrepareCommit,
38-
EventTypePreCommit,
39-
EventTypePostCommit,
40-
EventTypePreMerge,
41-
EventTypePostMerge,
42-
EventTypePreCreateBranch,
43-
EventTypePostCreateBranch,
44-
EventTypePreDeleteBranch,
45-
EventTypePostDeleteBranch,
46-
EventTypePreCreateTag,
47-
EventTypePostCreateTag,
48-
EventTypePreDeleteTag,
49-
EventTypePostDeleteTag,
50-
EventTypePreRevert,
51-
EventTypePostRevert,
52-
EventTypePreCherryPick,
53-
EventTypePostCherryPick:
54-
// Supported events
55-
return true
56-
}
57-
return false
58-
}
35+
// UnixYear3000 used by NewRunID for generating run IDs in reverse order
36+
const UnixYear3000 = 32500915200
5937

6038
// HookRecord is an aggregation of all necessary fields for all event types
6139
type HookRecord struct {

‎pkg/graveler/hooks_handler_isvalid.gen.go‎

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tools/isvalidgen/main.go‎

Lines changed: 166 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /