branch

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("branch not found")
	ErrAlreadyExists = errors.New("branch already exists")
)

Functions

func AlreadyExistsError

func AlreadyExistsError(name string) error

AlreadyExistsError returns a formatted already exists error.

func NotFoundError

func NotFoundError(name string) error

NotFoundError returns a formatted not found error.

Types

type Branch

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

Branch represents a git branch in a repository. Branch belongs to Repository (via RepositoryExtension), not generic Asset.

func NewBranch

func NewBranch(
	repositoryID shared.ID,
	name string,
	branchType Type,
) (*Branch, error)

NewBranch creates a new Branch with required fields. repositoryID must reference a valid repository (asset_repositories.asset_id).

func Reconstitute

func Reconstitute(
	id shared.ID,
	repositoryID shared.ID,
	name string,
	branchType Type,
	isDefault bool,
	isProtected bool,
	lastCommitSHA string,
	lastCommitMessage string,
	lastCommitAuthor string,
	lastCommitAuthorAvatar string,
	lastCommitAt *time.Time,
	scanOnPush bool,
	scanOnPR bool,
	lastScanID *shared.ID,
	lastScannedAt *time.Time,
	scanStatus ScanStatus,
	qualityGateStatus QualityGateStatus,
	findingsTotal int,
	findingsCritical int,
	findingsHigh int,
	findingsMedium int,
	findingsLow int,
	keepWhenInactive bool,
	retentionDays *int,
	createdAt time.Time,
	updatedAt time.Time,
) *Branch

Reconstitute recreates a Branch from persistence.

func (*Branch) CreatedAt

func (b *Branch) CreatedAt() time.Time

func (*Branch) FindingsCritical

func (b *Branch) FindingsCritical() int

func (*Branch) FindingsHigh

func (b *Branch) FindingsHigh() int

func (*Branch) FindingsLow

func (b *Branch) FindingsLow() int

func (*Branch) FindingsMedium

func (b *Branch) FindingsMedium() int

func (*Branch) FindingsTotal

func (b *Branch) FindingsTotal() int

func (*Branch) HasCriticalFindings

func (b *Branch) HasCriticalFindings() bool

func (*Branch) HasFindings

func (b *Branch) HasFindings() bool

func (*Branch) ID

func (b *Branch) ID() shared.ID

func (*Branch) IsDefault

func (b *Branch) IsDefault() bool

func (*Branch) IsPassing

func (b *Branch) IsPassing() bool

func (*Branch) IsProtected

func (b *Branch) IsProtected() bool

func (*Branch) KeepWhenInactive

func (b *Branch) KeepWhenInactive() bool

func (*Branch) LastCommitAt

func (b *Branch) LastCommitAt() *time.Time

func (*Branch) LastCommitAuthor

func (b *Branch) LastCommitAuthor() string

func (*Branch) LastCommitAuthorAvatar

func (b *Branch) LastCommitAuthorAvatar() string

func (*Branch) LastCommitMessage

func (b *Branch) LastCommitMessage() string

func (*Branch) LastCommitSHA

func (b *Branch) LastCommitSHA() string

func (*Branch) LastScanID

func (b *Branch) LastScanID() *shared.ID

func (*Branch) LastScannedAt

func (b *Branch) LastScannedAt() *time.Time

func (*Branch) MarkScanned

func (b *Branch) MarkScanned(scanID shared.ID, status ScanStatus, qualityGate QualityGateStatus)

func (*Branch) Name

func (b *Branch) Name() string

func (*Branch) NeedsScan

func (b *Branch) NeedsScan() bool

func (*Branch) QualityGateStatus

func (b *Branch) QualityGateStatus() QualityGateStatus

func (*Branch) RepositoryID

func (b *Branch) RepositoryID() shared.ID

func (*Branch) RetentionDays

func (b *Branch) RetentionDays() *int

func (*Branch) ScanOnPR

func (b *Branch) ScanOnPR() bool

func (*Branch) ScanOnPush

func (b *Branch) ScanOnPush() bool

func (*Branch) ScanStatus

func (b *Branch) ScanStatus() ScanStatus

func (*Branch) SetDefault

func (b *Branch) SetDefault(isDefault bool)

func (*Branch) SetProtected

func (b *Branch) SetProtected(isProtected bool)

func (*Branch) SetRetention

func (b *Branch) SetRetention(keepWhenInactive bool, days *int)

func (*Branch) SetScanConfig

func (b *Branch) SetScanConfig(scanOnPush, scanOnPR bool)

func (*Branch) Type

func (b *Branch) Type() Type

func (*Branch) UpdateFindingStats

func (b *Branch) UpdateFindingStats(total, critical, high, medium, low int)

func (*Branch) UpdateLastCommit

func (b *Branch) UpdateLastCommit(sha, message, author, avatar string, at time.Time)

func (*Branch) UpdatedAt

func (b *Branch) UpdatedAt() time.Time

type BranchTypeRule

type BranchTypeRule struct {
	Pattern    string `json:"pattern"`     // e.g., "feat/", "main", "dev/"
	MatchType  string `json:"match_type"`  // "exact" or "prefix"
	BranchType Type   `json:"branch_type"` // one of the six valid types
}

BranchTypeRule maps a branch name pattern to a branch type. Pattern can be matched exactly (e.g., "main" -> TypeMain) or by prefix (e.g., "feat/" -> TypeFeature).

type BranchTypeRules

type BranchTypeRules []BranchTypeRule

BranchTypeRules is an ordered list of rules. First match wins.

func DefaultBranchTypeRules

func DefaultBranchTypeRules() BranchTypeRules

DefaultBranchTypeRules returns the system default rules, equivalent to the previous hardcoded detection logic.

func ParseRulesFromProperties

func ParseRulesFromProperties(properties map[string]any) BranchTypeRules

ParseRulesFromProperties extracts BranchTypeRules from an asset's properties map. Returns nil if not present or invalid.

func (BranchTypeRules) Detect

func (rules BranchTypeRules) Detect(branchName string) Type

Detect applies rules to a branch name and returns the first matching type. Returns TypeOther if no rule matches.

func (BranchTypeRules) Validate

func (rules BranchTypeRules) Validate() error

Validate checks that all rules have valid fields.

type Filter

type Filter struct {
	RepositoryID *shared.ID // Repository ID (asset_repositories.asset_id)
	Name         string
	Types        []Type
	IsDefault    *bool
	ScanStatus   *ScanStatus
}

Filter defines criteria for filtering branches.

type ListOptions

type ListOptions struct {
	SortBy    string // name, created_at, last_scanned_at
	SortOrder string // asc, desc
}

ListOptions defines sorting options.

type QualityGateStatus

type QualityGateStatus string

QualityGateStatus represents the quality gate status.

const (
	QualityGatePassed      QualityGateStatus = "passed"
	QualityGateFailed      QualityGateStatus = "failed"
	QualityGateWarning     QualityGateStatus = "warning"
	QualityGateNotComputed QualityGateStatus = "not_computed"
)

func ParseQualityGateStatus

func ParseQualityGateStatus(s string) QualityGateStatus

func (QualityGateStatus) IsValid

func (q QualityGateStatus) IsValid() bool

func (QualityGateStatus) String

func (q QualityGateStatus) String() string

type Repository

type Repository interface {
	// Create persists a new branch.
	Create(ctx context.Context, branch *Branch) error

	// GetByID retrieves a branch by ID.
	GetByID(ctx context.Context, id shared.ID) (*Branch, error)

	// GetByName retrieves a branch by repository ID and name.
	GetByName(ctx context.Context, repositoryID shared.ID, name string) (*Branch, error)

	// Update updates an existing branch.
	Update(ctx context.Context, branch *Branch) error

	// Delete removes a branch.
	Delete(ctx context.Context, id shared.ID) error

	// List returns branches matching the filter.
	List(ctx context.Context, filter Filter, opts ListOptions, page pagination.Pagination) (pagination.Result[*Branch], error)

	// ListByRepository returns all branches for a repository.
	ListByRepository(ctx context.Context, repositoryID shared.ID) ([]*Branch, error)

	// GetDefaultBranch returns the default branch for a repository.
	GetDefaultBranch(ctx context.Context, repositoryID shared.ID) (*Branch, error)

	// SetDefaultBranch sets a branch as the default for a repository.
	SetDefaultBranch(ctx context.Context, repositoryID shared.ID, branchID shared.ID) error

	// Count returns the number of branches matching the filter.
	Count(ctx context.Context, filter Filter) (int64, error)

	// ExistsByName checks if a branch exists by repository ID and name.
	ExistsByName(ctx context.Context, repositoryID shared.ID, name string) (bool, error)
}

Repository defines the branch repository interface.

type ScanStatus

type ScanStatus string

ScanStatus represents the branch scan status.

const (
	ScanStatusPassed     ScanStatus = "passed"
	ScanStatusFailed     ScanStatus = "failed"
	ScanStatusWarning    ScanStatus = "warning"
	ScanStatusScanning   ScanStatus = "scanning"
	ScanStatusNotScanned ScanStatus = "not_scanned"
)

func ParseScanStatus

func ParseScanStatus(s string) ScanStatus

func (ScanStatus) IsValid

func (s ScanStatus) IsValid() bool

func (ScanStatus) String

func (s ScanStatus) String() string

type Type

type Type string

Type represents the branch type.

const (
	TypeMain    Type = "main"
	TypeDevelop Type = "develop"
	TypeFeature Type = "feature"
	TypeRelease Type = "release"
	TypeHotfix  Type = "hotfix"
	TypeOther   Type = "other"
)

func DetectBranchType

func DetectBranchType(branchName string, assetRules, tenantRules BranchTypeRules) Type

DetectBranchType resolves branch type using the fallback chain: per-asset rules > per-tenant rules > system defaults. Each level is an ordered list of rules; first match within a level wins. If a level has rules but none match, it falls through to the next level.

func ParseType

func ParseType(s string) Type

func (Type) IsValid

func (t Type) IsValid() bool

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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