hook

package
v0.0.0-...-bc69434 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BranchPushAction a branch is pushed
	BranchPushAction = "branch.push"
	// BranchCreateAction a branch is created
	BranchCreateAction = "branch.create"
	// BranchDeleteAction a branch is deleted
	BranchDeleteAction = "branch.delete"
	// TagCreateAction a tag is created
	TagCreateAction = "tag.create"
	// TagDeleteAction a tag is deleted
	TagDeleteAction = "tag.delete"
	// ZeroCommit hash if no commit
	ZeroCommit = "0000000000000000000000000000000000000000"
)

Variables

View Source
var (
	// ConfigFilename Git hooks configuration filename to be parsed
	ConfigFilename = ".githooks.yml"
	// ErrFileNotFound File not found error
	ErrFileNotFound = errors.New("configuration file .githooks.(yaml|yml) not found")
)
View Source
var (
	// ErrNoHookData no hook data error
	ErrNoHookData = errors.New("Hook data is mandatory")
	// ErrInvalidHookData invalid hook input
	ErrInvalidHookData = errors.New("invalid hook input")
	// HookTypes that are supported by Watchdog
	HookTypes = [...]string{
		"pre-receive",
		"update",
		"post-receive",
	}
)

Functions

This section is empty.

Types

type Condition

type Condition struct {
	Condition        string `yaml:"condition"`
	FailFast         string `yaml:"fail_fast"`
	Ignore           bool   `yaml:"ignore"`
	Only             []string
	RejectionMessage string        `yaml:"rejection_message"`
	Skip             string        `yaml:"skip"`
	Type             ConditionType `yaml:"type"`
}

Condition used in hook's rules

type ConditionType

type ConditionType string

ConditionType condition type

const (
	// ConditionEmail email condition
	ConditionEmail ConditionType = "email"
	// ConditionExtension file extension condition
	ConditionExtension ConditionType = "extension"
	// ConditionIP ip condition
	ConditionIP ConditionType = "ip"
	// ConditionIssue issue condition
	ConditionIssue ConditionType = "issue"
	// ConditionLength length condition
	ConditionLength ConditionType = "length"
	// ConditionPattern pattern condition
	ConditionPattern ConditionType = "pattern"
	// ConditionProtected protected condition
	ConditionProtected ConditionType = "protected"
	// ConditionSecret secret condition
	ConditionSecret ConditionType = "secret"
	// ConditionSemVer semver condition
	ConditionSemVer ConditionType = "semver"
	// ConditionSignature secret condition
	ConditionSignature ConditionType = "signature"
	// ConditionSize file size condition
	ConditionSize ConditionType = "size"
)

type GitHooks

type GitHooks struct {
	Hooks   []Hook `yaml:"hooks,omitempty"`
	Locked  bool   `yaml:"locked"`
	Version string `yaml:"version,omitempty"`
}

GitHooks data structure

func ExtractConfigFile

func ExtractConfigFile(ctx context.Context, commit *object.Commit) (gitHooks *GitHooks, err error)

ExtractConfigFile extract .githooks.yml file from Git bare repository

func LoadGitHooks

func LoadGitHooks(filePath string) (*GitHooks, error)

LoadGitHooks load and return Configuration struct

func LoadGitHooksFromRaw

func LoadGitHooksFromRaw(fileContent string) (*GitHooks, error)

LoadGitHooksFromRaw load config file from raw data

func (*GitHooks) Validate

func (gitHooks *GitHooks) Validate() error

Validate Check if version is supported

type HandlerType

type HandlerType string

HandlerType handler type

const (
	// TypeBranch constant for branch handler
	TypeBranch HandlerType = "branch"
	// TypeCommit constant for commit handler
	TypeCommit HandlerType = "commit"
	// TypeFile constant for file handler
	TypeFile HandlerType = "file"
	// TypeJira constant for jira handler
	TypeJira HandlerType = "jira"
	// TypeSecurity constant for security handler
	TypeSecurity HandlerType = "security"
	// TypeTag constant for tag handler
	TypeTag HandlerType = "tag"
)

type Hook

type Hook struct {
	Description      string  `yaml:"description"`
	Name             string  `yaml:"name,omitempty"`
	RejectionMessage string  `yaml:"rejection_message"`
	Rules            []*Rule `yaml:"rules,omitempty"`
}

Hook hook aggregate model

type Hooks

type Hooks struct {
	PreReceive  string
	Update      string
	PostReceive string
}

Hooks server side git hooks

type Info

type Info struct {
	Action   string
	NewRev   *object.Commit         // New object name to be stored in the ref. When you delete a ref, this equals 40 zeroes.
	OldRev   *object.Commit         // Old object name stored in the ref. When you create a new ref, this equals 40 zeroes.
	Ref      plumbing.ReferenceName // The full name of the ref.
	RefType  string                 // One of : heads / remotes / tags
	RepoName string
	RepoPath string
	// contains filtered or unexported fields
}

Info git hook data structure

func ParseInfo

func ParseInfo(repository *git.Repository) (*Info, error)

ParseInfo parse info for the current working directory

func (*Info) GetAction

func (info *Info) GetAction() string

GetAction return hook action

func (*Info) ParseHookInput

func (info *Info) ParseHookInput(input io.Reader) error

ParseHookInput parse git hook input data and return Info object format: <old-value> SP <new-value> SP <ref-name> LF to models.Info

type Rule

type Rule struct {
	Conditions  []Condition `yaml:"conditions,omitempty"`
	Description string      `yaml:"description,omitempty"`
	Disabled    bool        `yaml:"disabled,omitempty"`
	Type        HandlerType `yaml:"type,omitempty"`
}

Rule data structure Use similar mechanism as Gitlab, see https://docs.gitlab.com/ee/push_rules/push_rules.html

Jump to

Keyboard shortcuts

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