githook

package
v1.0.0-gitspaces-beta Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func FMTDuration

func FMTDuration(d time.Duration) string

func GetBaseSHAForScanningChanges

func GetBaseSHAForScanningChanges(
	ctx context.Context,
	rgit RestrictedGIT,
	repo *types.Repository,
	env hook.Environment,
	refUpdates []hook.ReferenceUpdate,
	findBaseFor hook.ReferenceUpdate,
) (sha.SHA, bool, error)

GetBaseSHAForScanningChanges returns the commit sha to which the new sha of the reference should be compared against when scanning incoming changes. NOTE: If no such a sha exists, then (sha.None, false, nil) is returned. This will happen in case the default branch doesn't exist yet.

func ProvideFactory

func ProvideFactory() hook.ClientFactory

Types

type Controller

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

func NewController

func NewController(
	authorizer authz.Authorizer,
	principalStore store.PrincipalStore,
	repoStore store.RepoStore,
	gitReporter *eventsgit.Reporter,
	repoReporter *eventsrepo.Reporter,
	git git.Interface,
	pullreqStore store.PullReqStore,
	urlProvider url.Provider,
	protectionManager *protection.Manager,
	limiter limiter.ResourceLimiter,
	settings *settings.Service,
	preReceiveExtender PreReceiveExtender,
	updateExtender UpdateExtender,
	postReceiveExtender PostReceiveExtender,
) *Controller

func ProvideController

func ProvideController(
	authorizer authz.Authorizer,
	principalStore store.PrincipalStore,
	repoStore store.RepoStore,
	gitReporter *eventsgit.Reporter,
	repoReporter *eventsrepo.Reporter,
	git git.Interface,
	pullreqStore store.PullReqStore,
	urlProvider url.Provider,
	protectionManager *protection.Manager,
	githookFactory hook.ClientFactory,
	limiter limiter.ResourceLimiter,
	settings *settings.Service,
	preReceiveExtender PreReceiveExtender,
	updateExtender UpdateExtender,
	postReceiveExtender PostReceiveExtender,
) *Controller

func (*Controller) PostReceive

func (c *Controller) PostReceive(
	ctx context.Context,
	rgit RestrictedGIT,
	session *auth.Session,
	in types.GithookPostReceiveInput,
) (hook.Output, error)

PostReceive executes the post-receive hook for a git repository.

func (*Controller) PreReceive

func (c *Controller) PreReceive(
	ctx context.Context,
	rgit RestrictedGIT,
	session *auth.Session,
	in types.GithookPreReceiveInput,
) (hook.Output, error)

PreReceive executes the pre-receive hook for a git repository.

func (*Controller) Update

func (c *Controller) Update(
	ctx context.Context,
	rgit RestrictedGIT,
	session *auth.Session,
	in types.GithookUpdateInput,
) (hook.Output, error)

Update executes the update hook for a git repository.

type ControllerClient

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

ControllerClient directly calls the controller to execute githooks.

func (*ControllerClient) PostReceive

func (c *ControllerClient) PostReceive(
	ctx context.Context,
	in hook.PostReceiveInput,
) (hook.Output, error)

func (*ControllerClient) PreReceive

func (c *ControllerClient) PreReceive(
	ctx context.Context,
	in hook.PreReceiveInput,
) (hook.Output, error)

func (*ControllerClient) Update

func (c *ControllerClient) Update(
	ctx context.Context,
	in hook.UpdateInput,
) (hook.Output, error)

type ControllerClientFactory

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

ControllerClientFactory creates clients that directly call the controller to execute githooks.

func (*ControllerClientFactory) NewClient

func (f *ControllerClientFactory) NewClient(envVars map[string]string) (hook.Client, error)

type NoOpPostReceiveExtender

type NoOpPostReceiveExtender struct {
}

type NoOpPreReceiveExtender

type NoOpPreReceiveExtender struct {
}

type NoOpUpdateExtender

type NoOpUpdateExtender struct {
}

type PostReceiveExtender

type PostReceiveExtender interface {
	Extend(
		context.Context,
		RestrictedGIT,
		*auth.Session,
		*types.Repository,
		types.GithookPostReceiveInput,
		*hook.Output,
	) error
}

func NewPostReceiveExtender

func NewPostReceiveExtender() PostReceiveExtender

func ProvidePostReceiveExtender

func ProvidePostReceiveExtender() (PostReceiveExtender, error)

type PreReceiveExtender

type PreReceiveExtender interface {
	Extend(
		context.Context,
		RestrictedGIT,
		*auth.Session,
		*types.Repository,
		types.GithookPreReceiveInput,
		*hook.Output,
	) error
}

func NewPreReceiveExtender

func NewPreReceiveExtender() PreReceiveExtender

func ProvidePreReceiveExtender

func ProvidePreReceiveExtender() (PreReceiveExtender, error)

type RestrictedGIT

type RestrictedGIT interface {
	IsAncestor(ctx context.Context, params git.IsAncestorParams) (git.IsAncestorOutput, error)
	ScanSecrets(ctx context.Context, param *git.ScanSecretsParams) (*git.ScanSecretsOutput, error)
	GetBranch(ctx context.Context, params *git.GetBranchParams) (*git.GetBranchOutput, error)
	Diff(ctx context.Context, in *git.DiffParams, files ...api.FileDiffRequest) (<-chan *git.FileDiff, <-chan error)
	GetBlob(ctx context.Context, params *git.GetBlobParams) (*git.GetBlobOutput, error)
	FindOversizeFiles(
		ctx context.Context,
		params *git.FindOversizeFilesParams,
	) (*git.FindOversizeFilesOutput, error)
}

RestrictedGIT is a git client that is restricted to a subset of operations of git.Interface which can be executed on quarantine data that is part of git-hooks (e.g. pre-receive, update, ..) and don't alter the repo (so only read operations). NOTE: While it doesn't apply to all git-hooks (e.g. post-receive), we still use the interface across the board to "soft enforce" no write operations being executed as part of githooks.

type UpdateExtender

type UpdateExtender interface {
	Extend(
		context.Context,
		RestrictedGIT,
		*auth.Session,
		*types.Repository,
		types.GithookUpdateInput,
		*hook.Output,
	) error
}

func NewUpdateExtender

func NewUpdateExtender() UpdateExtender

func ProvideUpdateExtender

func ProvideUpdateExtender() (UpdateExtender, error)

Jump to

Keyboard shortcuts

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