Documentation ¶
Index ¶
- Constants
- Variables
- func GetSidechannel(ctx context.Context) (net.Conn, error)
- type CustomHookError
- type DisabledManager
- func (DisabledManager) PostReceiveHook(context.Context, *gitalypb.Repository, []string, []string, io.Reader, ...) error
- func (DisabledManager) PreReceiveHook(context.Context, *gitalypb.Repository, []string, []string, io.Reader, ...) error
- func (DisabledManager) ReferenceTransactionHook(context.Context, ReferenceTransactionState, []string, io.Reader) error
- func (DisabledManager) UpdateHook(context.Context, *gitalypb.Repository, string, string, string, []string, ...) error
- type GitLabHookManager
- func (m *GitLabHookManager) Check(ctx context.Context) (*gitlab.CheckInfo, error)
- func (m *GitLabHookManager) PostReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, ...) error
- func (m *GitLabHookManager) PreReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, ...) error
- func (m *GitLabHookManager) ReferenceTransactionHook(ctx context.Context, state ReferenceTransactionState, env []string, ...) error
- func (m *GitLabHookManager) UpdateHook(ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, ...) error
- type Manager
- type MockManager
- func (m *MockManager) PostReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, ...) error
- func (m *MockManager) PreReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, ...) error
- func (m *MockManager) ReferenceTransactionHook(ctx context.Context, state ReferenceTransactionState, env []string, ...) error
- func (m *MockManager) UpdateHook(ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, ...) error
- type NotAllowedError
- type ReferenceTransactionState
- type SidechannelWaiter
Constants ¶
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 ¶
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 ¶
Types ¶
type CustomHookError ¶ added in v14.6.0
type CustomHookError error
CustomHookError is returned in case custom hooks return an error.
type DisabledManager ¶
type DisabledManager struct{}
DisabledManager never executes hooks and simply returns a nil error.
func (DisabledManager) PostReceiveHook ¶
func (DisabledManager) PostReceiveHook(context.Context, *gitalypb.Repository, []string, []string, io.Reader, io.Writer, io.Writer) error
PostReceiveHook ignores its parameters and returns a nil error.
func (DisabledManager) PreReceiveHook ¶
func (DisabledManager) PreReceiveHook(context.Context, *gitalypb.Repository, []string, []string, io.Reader, io.Writer, io.Writer) error
PreReceiveHook ignores its parameters and returns a nil error.
func (DisabledManager) ReferenceTransactionHook ¶
func (DisabledManager) ReferenceTransactionHook(context.Context, ReferenceTransactionState, []string, io.Reader) error
ReferenceTransactionHook 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 ¶
nolint: revive,stylecheck // This is unintentionally missing documentation.
func (*GitLabHookManager) PostReceiveHook ¶
func (m *GitLabHookManager) PostReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error
nolint: revive,stylecheck // This is unintentionally missing documentation.
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
nolint: revive,stylecheck // This is unintentionally missing documentation.
func (*GitLabHookManager) UpdateHook ¶
func (m *GitLabHookManager) UpdateHook(ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error
nolint: revive,stylecheck // This is unintentionally missing documentation.
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 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 ¶ added in v14.3.0
type SidechannelWaiter struct {
// contains filtered or unexported fields
}
SidechannelWaiter provides cleanup and error propagation for a sidechannel callback.
func SetupSidechannel ¶ added in v14.3.0
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 ¶ added in v14.3.0
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 ¶ added in v14.3.0
func (wt *SidechannelWaiter) Wait() error
Wait waits for the callback to run and returns its error value.