Skip to content

Commit

Permalink
[CR] pass hook values by value
Browse files Browse the repository at this point in the history
  • Loading branch information
arielshaqed committed Nov 25, 2020
1 parent 74527c9 commit 99770f8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions catalog/cataloger.go
Expand Up @@ -167,8 +167,8 @@ type ExportConfigurationForBranch struct {
IsContinuous bool `db:"continuous"`
}

type PostCommitFunc = func(ctx context.Context, repo, branch string, commitLog *CommitLog) error
type PostMergeFunc = func(ctx context.Context, repo, branch string, mergeResult *MergeResult) error
type PostCommitFunc func(ctx context.Context, repo, branch string, commitLog CommitLog) error
type PostMergeFunc func(ctx context.Context, repo, branch string, mergeResult MergeResult) error

// CatalogerHooks describes the hooks available for some operations on the catalog. Hooks are
// called after the transaction ends; if they return an error they do not affect commit/merge.
Expand Down
2 changes: 1 addition & 1 deletion catalog/mvcc/cataloger_commit.go
Expand Up @@ -83,7 +83,7 @@ func (c *cataloger) Commit(ctx context.Context, repository, branch string, messa
}
commitLog := res.(*catalog.CommitLog)
for _, hook := range c.Hooks().PostCommit {
anotherErr := hook(ctx, repository, branch, commitLog)
anotherErr := hook(ctx, repository, branch, *commitLog)
if anotherErr != nil && err == nil {
err = anotherErr
}
Expand Down
9 changes: 5 additions & 4 deletions catalog/mvcc/cataloger_commit_test.go
Expand Up @@ -290,8 +290,9 @@ func TestCataloger_CommitTombstoneShouldNotChangeHistory(t *testing.T) {
}

type CommitData struct {
Repo, Branch string
Log catalog.CommitLog
Repo string
Branch string
Log catalog.CommitLog
}

// CommitHookLogger - commit hook that will return an error if set by Err.
Expand All @@ -300,8 +301,8 @@ type CommitHookLogger struct {
Commits []CommitData
}

func (h *CommitHookLogger) Hook(_ context.Context, repo, branch string, log *catalog.CommitLog) error {
h.Commits = append(h.Commits, CommitData{Repo: repo, Branch: branch, Log: *log})
func (h *CommitHookLogger) Hook(_ context.Context, repo, branch string, log catalog.CommitLog) error {
h.Commits = append(h.Commits, CommitData{Repo: repo, Branch: branch, Log: log})
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion catalog/mvcc/cataloger_merge.go
Expand Up @@ -94,7 +94,7 @@ func (c *cataloger) Merge(ctx context.Context, repository, leftBranch, rightBran

if err == nil {
for _, hook := range c.Hooks().PostMerge {
anotherErr := hook(ctx, repository, rightBranch, mergeResult)
anotherErr := hook(ctx, repository, rightBranch, *mergeResult)
if anotherErr != nil && err == nil {
err = anotherErr
}
Expand Down
9 changes: 5 additions & 4 deletions catalog/mvcc/cataloger_merge_test.go
Expand Up @@ -1187,8 +1187,9 @@ func TestCataloger_MergeFromChildAfterMergeFromParent(t *testing.T) {
}

type MergeData struct {
Repo, Branch string
Result catalog.MergeResult
Repo string
Branch string
Result catalog.MergeResult
}

// MergeHookLogger - merge hook that will return an error if set by Err.
Expand All @@ -1198,11 +1199,11 @@ type MergeHookLogger struct {
Merges []MergeData
}

func (h *MergeHookLogger) Hook(_ context.Context, repo, branch string, result *catalog.MergeResult) error {
func (h *MergeHookLogger) Hook(_ context.Context, repo, branch string, result catalog.MergeResult) error {
if h.Err != nil {
return h.Err
}
h.Merges = append(h.Merges, MergeData{Repo: repo, Branch: branch, Result: *result})
h.Merges = append(h.Merges, MergeData{Repo: repo, Branch: branch, Result: result})
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions export/export_handler.go
Expand Up @@ -338,15 +338,15 @@ func startExport(l logging.Logger, p parade.Parade, c catalog.Cataloger, op inte
}

// exportCommitHook is a cataloger PostCommit hook for continuous export.
func (h *Handler) exportCommitHook(ctx context.Context, repo, branch string, log *catalog.CommitLog) error {
func (h *Handler) exportCommitHook(ctx context.Context, repo, branch string, log catalog.CommitLog) error {
l := logging.Default().
WithFields(logging.Fields{"repo": repo, "branch": branch, "message": log.Message, "at": log.CreationDate.String()})
return startExport(l, h.parade, h.cataloger, *log, repo, branch)
return startExport(l, h.parade, h.cataloger, log, repo, branch)
}

// exportMergeHook is a cataloger PostMerge hook for continuous export.
func (h *Handler) exportMergeHook(ctx context.Context, repo, branch string, merge *catalog.MergeResult) error {
func (h *Handler) exportMergeHook(ctx context.Context, repo, branch string, merge catalog.MergeResult) error {
l := logging.Default().
WithFields(logging.Fields{"repo": repo, "branch": branch, "reference": merge.Reference})
return startExport(l, h.parade, h.cataloger, *merge, repo, branch)
return startExport(l, h.parade, h.cataloger, merge, repo, branch)
}

0 comments on commit 99770f8

Please sign in to comment.