diff options
| author | 2026-03-07 21:21:26 +0800 | |
|---|---|---|
| committer | 2026-03-07 21:21:26 +0800 | |
| commit | 344d0c4d3c968506f5641da40fce581ea5bcdbbc (patch) | |
| tree | b3a03c39dda50cee5154a756a57e4a9d1754d6ae /receivepack/hook.go | |
| parent | receivepack: Add hooks (diff) | |
| signature | No signature | |
receivepack: Re-organize things around
Diffstat (limited to 'receivepack/hook.go')
| -rw-r--r-- | receivepack/hook.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/receivepack/hook.go b/receivepack/hook.go index 4c4a44ef..c96911ac 100644 --- a/receivepack/hook.go +++ b/receivepack/hook.go @@ -5,6 +5,7 @@ import ( "codeberg.org/lindenii/furgit/objectid" "codeberg.org/lindenii/furgit/objectstore" + "codeberg.org/lindenii/furgit/receivepack/internal/service" "codeberg.org/lindenii/furgit/refstore" ) @@ -37,3 +38,41 @@ type HookRequest struct { // promotion or ref updates. The returned decisions must have the same length as // HookRequest.Updates. type Hook func(context.Context, HookRequest) ([]UpdateDecision, error) + +func translateHook(hook Hook) service.Hook { + if hook == nil { + return nil + } + + return func(ctx context.Context, req service.HookRequest) ([]service.UpdateDecision, error) { + translatedUpdates := make([]RefUpdate, 0, len(req.Updates)) + for _, update := range req.Updates { + translatedUpdates = append(translatedUpdates, RefUpdate{ + Name: update.Name, + OldID: update.OldID, + NewID: update.NewID, + }) + } + + decisions, err := hook(ctx, HookRequest{ + Refs: req.Refs, + ExistingObjects: req.ExistingObjects, + QuarantinedObjects: req.QuarantinedObjects, + Updates: translatedUpdates, + PushOptions: append([]string(nil), req.PushOptions...), + }) + if err != nil { + return nil, err + } + + out := make([]service.UpdateDecision, 0, len(decisions)) + for _, decision := range decisions { + out = append(out, service.UpdateDecision{ + Accept: decision.Accept, + Message: decision.Message, + }) + } + + return out, nil + } +} |
