hook

package
v14.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 27 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

This section is empty.

Types

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(locator storage.Locator, txManager transaction.Manager, gitlabClient gitlab.Client, cfg config.Cfg) *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 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 added in v14.1.0

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 added in v14.1.0

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 added in v14.1.0

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 added in v14.1.0

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 added in v14.1.0

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 added in v14.1.0

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 string
}

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.

Jump to

Keyboard shortcuts

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