aboutsummaryrefslogtreecommitdiff
path: root/network/receivepack/service/hook.go
blob: e3afa375b0ec35ac2e5ec1eaeb951755dda42be4 (about) (plain) (blame)
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
package service

import (
	"context"
	"io"

	commitgraphread "codeberg.org/lindenii/furgit/format/commitgraph/read"
	objectid "codeberg.org/lindenii/furgit/object/id"
	objectstore "codeberg.org/lindenii/furgit/object/store"
	refstore "codeberg.org/lindenii/furgit/ref/store"
)

type HookIO struct {
	Progress io.Writer
	Error    io.Writer
}

type RefUpdate struct {
	Name  string
	OldID objectid.ObjectID
	NewID objectid.ObjectID
}

type UpdateDecision struct {
	Accept  bool
	Message string
}

// HookRequest is the borrowed view passed to one Hook invocation.
//
// Refs, ExistingObjects, QuarantinedObjects, and CommitGraph are borrowed and
// are only valid for the duration of the hook call.
type HookRequest struct {
	Refs               refstore.ReadingStore
	ExistingObjects    objectstore.ReadingStore
	QuarantinedObjects objectstore.ReadingStore
	CommitGraph        *commitgraphread.Reader
	Updates            []RefUpdate
	PushOptions        []string
	IO                 HookIO
}

// Hook is an optional per-request validation hook.
//
// Hook borrows the data and stores in HookRequest only for the duration of the
// call.
type Hook func(context.Context, HookRequest) ([]UpdateDecision, error)