hook

package
v16.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ReferenceTransactionPrepared indicates all reference updates have been queued to the
	// transaction and were locked on disk.
	ReferenceTransactionPrepared = ReferenceTransactionState(iota)
	// ReferenceTransactionCommitted indicates the reference transaction was committed and all
	// references now have their respective new value.
	ReferenceTransactionCommitted
	// ReferenceTransactionAborted indicates the transaction was aborted, no changes were
	// performed and the reference locks have been released.
	ReferenceTransactionAborted
)

Variables

View Source
var (
	// NopPreReceive does nothing for the pre-receive hook
	NopPreReceive = func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error {
		return nil
	}

	// NopPostReceive does nothing for the post-receive hook
	NopPostReceive = func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error {
		return nil
	}

	// NopUpdate does nothing for the update hook
	NopUpdate = func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error {
		return nil
	}

	// NopReferenceTransaction does nothing for the reference transaction hook
	NopReferenceTransaction = func(t *testing.T, ctx context.Context, state ReferenceTransactionState, env []string, stdin io.Reader) error {
		return nil
	}
)

Functions

func GetSidechannel

func GetSidechannel(ctx context.Context) (net.Conn, error)

GetSidechannel looks for a sidechannel address in an incoming context and establishes a connection if it finds an address.

Types

type ConcurrencyTracker

type ConcurrencyTracker struct {
	// contains filtered or unexported fields
}

ConcurrencyTracker tracks concurrency of pack object calls

func NewConcurrencyTracker

func NewConcurrencyTracker() *ConcurrencyTracker

NewConcurrencyTracker creates a new ConcurrencyTracker.

func (*ConcurrencyTracker) Collect

func (c *ConcurrencyTracker) Collect(ch chan<- prometheus.Metric)

Collect allows ConcurrencyTracker to adhere to the prometheus.Collector interface for collecting metrics.

func (*ConcurrencyTracker) Describe

func (c *ConcurrencyTracker) Describe(ch chan<- *prometheus.Desc)

Describe allows ConcurrencyTracker to adhere to the prometheus.Collector interface for collecing metrics

func (*ConcurrencyTracker) LogConcurrency

func (c *ConcurrencyTracker) LogConcurrency(ctx context.Context, keyType, key string) func()

LogConcurrency logs the number of concurrent calls for a keyType, key combination

type CustomHookError

type CustomHookError struct {
	// contains filtered or unexported fields
}

CustomHookError is returned in case custom hooks return an error.

func NewCustomHookError

func NewCustomHookError(e error) CustomHookError

NewCustomHookError creates a new CustomHookError.

func (CustomHookError) Error

func (e CustomHookError) Error() string

func (CustomHookError) Unwrap

func (e CustomHookError) Unwrap() error

type DisabledManager

type DisabledManager struct{}

DisabledManager never executes hooks and simply returns a nil error.

func (DisabledManager) PostReceiveHook

PostReceiveHook ignores its parameters and returns a nil error.

func (DisabledManager) PreReceiveHook

PreReceiveHook ignores its parameters and returns a nil error.

func (DisabledManager) ReferenceTransactionHook

ReferenceTransactionHook ignores its parameters and returns a nil error.

func (DisabledManager) UpdateHook

UpdateHook ignores its parameters and returns a nil error.

type GitLabHookManager

type GitLabHookManager struct {
	// contains filtered or unexported fields
}

GitLabHookManager is a hook manager containing Git hook business logic. It uses the GitLab API to authenticate and track ongoing hook calls.

func NewManager

func NewManager(
	cfg config.Cfg,
	locator storage.Locator,
	gitCmdFactory git.CommandFactory,
	txManager transaction.Manager,
	gitlabClient gitlab.Client,
) *GitLabHookManager

NewManager returns a new hook manager

func (*GitLabHookManager) Check

func (*GitLabHookManager) PostReceiveHook

func (m *GitLabHookManager) PostReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error

func (*GitLabHookManager) PreReceiveHook

func (m *GitLabHookManager) PreReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error

PreReceiveHook will try to authenticate the changes against the GitLab API. If successful, it will execute custom hooks with the given parameters, push options and environment.

func (*GitLabHookManager) ReferenceTransactionHook

func (m *GitLabHookManager) ReferenceTransactionHook(ctx context.Context, state ReferenceTransactionState, env []string, stdin io.Reader) error

func (*GitLabHookManager) UpdateHook

func (m *GitLabHookManager) UpdateHook(ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error

type InvalidSidechannelAddressError

type InvalidSidechannelAddressError struct {
	// contains filtered or unexported fields
}

InvalidSidechannelAddressError is returned by GetSidechannel if improper address is used.

func (InvalidSidechannelAddressError) Error

type Manager

type Manager interface {
	// PreReceiveHook executes the pre-receive Git hook and any installed custom hooks. stdin
	// must contain all references to be updated and match the format specified in githooks(5).
	PreReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error

	// PostReceiveHook executes the post-receive Git hook and any installed custom hooks. stdin
	// must contain all references to be updated and match the format specified in githooks(5).
	PostReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error

	// UpdateHook executes the update Git hook and any installed custom hooks for the reference
	// `ref` getting updated from `oldValue` to `newValue`.
	UpdateHook(ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error

	// ReferenceTransactionHook executes the reference-transaction Git hook. stdin must contain
	// all references to be updated and match the format specified in githooks(5).
	ReferenceTransactionHook(ctx context.Context, state ReferenceTransactionState, env []string, stdin io.Reader) error
}

Manager is an interface providing the ability to execute Git hooks.

func NewMockManager

func NewMockManager(
	t *testing.T,
	preReceive func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error,
	postReceive func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error,
	update func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error,
	referenceTransaction func(t *testing.T, ctx context.Context, state ReferenceTransactionState, env []string, stdin io.Reader) error,
) Manager

NewMockManager returns a mocked hook Manager with the stubbed functions

type MockManager

type MockManager struct {
	// contains filtered or unexported fields
}

MockManager mocks the Manager interface for Git hooks (e.g. pre-receive, post-receive)

func (*MockManager) PostReceiveHook

func (m *MockManager) PostReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error

PostReceiveHook executes the mocked post-receive hook

func (*MockManager) PreReceiveHook

func (m *MockManager) PreReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error

PreReceiveHook executes the mocked pre-receive hook

func (*MockManager) ReferenceTransactionHook

func (m *MockManager) ReferenceTransactionHook(ctx context.Context, state ReferenceTransactionState, env []string, stdin io.Reader) error

ReferenceTransactionHook executes the mocked reference transaction hook

func (*MockManager) UpdateHook

func (m *MockManager) UpdateHook(ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error

UpdateHook executes the mocked update hook

type NotAllowedError

type NotAllowedError struct {
	// Message is the error message returned by Rails.
	Message string
	// Protocol is the protocol used.
	Protocol string
	// userID is the ID of the user as whom we have performed access checks.
	UserID string
	// Changes is the changes we have requested.
	Changes []byte
}

NotAllowedError is needed to report internal API errors that are made by the pre-receive hook.

func (NotAllowedError) Error

func (e NotAllowedError) Error() string

type ReferenceTransactionState

type ReferenceTransactionState int

ReferenceTransactionState is the state of the Git reference transaction. It reflects the first parameter of the reference-transaction hook. See githooks(1) for more information.

type SidechannelWaiter

type SidechannelWaiter struct {
	// contains filtered or unexported fields
}

SidechannelWaiter provides cleanup and error propagation for a sidechannel callback.

func SetupSidechannel

func SetupSidechannel(ctx context.Context, payload git.HooksPayload, callback func(*net.UnixConn) error) (_ context.Context, _ *SidechannelWaiter, err error)

SetupSidechannel creates a sidechannel listener in a tempdir and launches a goroutine that will run the callback if the listener receives a connection. The address of the listener is stored in the returned context, so that the caller can propagate it to a server. The caller must Close the SidechannelWaiter to prevent resource leaks.

func (*SidechannelWaiter) Close

func (wt *SidechannelWaiter) Close() error

Close cleans up sidechannel resources. If the callback is already running, Close will block until the callback is done.

func (*SidechannelWaiter) Wait

func (wt *SidechannelWaiter) Wait() error

Wait waits for the callback to run and returns its error value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL