Documentation
¶
Index ¶
- Variables
- func AlreadyExistsError(name string) error
- func NotFoundError(name string) error
- type Branch
- func (b *Branch) CreatedAt() time.Time
- func (b *Branch) FindingsCritical() int
- func (b *Branch) FindingsHigh() int
- func (b *Branch) FindingsLow() int
- func (b *Branch) FindingsMedium() int
- func (b *Branch) FindingsTotal() int
- func (b *Branch) HasCriticalFindings() bool
- func (b *Branch) HasFindings() bool
- func (b *Branch) ID() shared.ID
- func (b *Branch) IsDefault() bool
- func (b *Branch) IsPassing() bool
- func (b *Branch) IsProtected() bool
- func (b *Branch) KeepWhenInactive() bool
- func (b *Branch) LastCommitAt() *time.Time
- func (b *Branch) LastCommitAuthor() string
- func (b *Branch) LastCommitAuthorAvatar() string
- func (b *Branch) LastCommitMessage() string
- func (b *Branch) LastCommitSHA() string
- func (b *Branch) LastScanID() *shared.ID
- func (b *Branch) LastScannedAt() *time.Time
- func (b *Branch) MarkScanned(scanID shared.ID, status ScanStatus, qualityGate QualityGateStatus)
- func (b *Branch) Name() string
- func (b *Branch) NeedsScan() bool
- func (b *Branch) QualityGateStatus() QualityGateStatus
- func (b *Branch) RepositoryID() shared.ID
- func (b *Branch) RetentionDays() *int
- func (b *Branch) ScanOnPR() bool
- func (b *Branch) ScanOnPush() bool
- func (b *Branch) ScanStatus() ScanStatus
- func (b *Branch) SetDefault(isDefault bool)
- func (b *Branch) SetProtected(isProtected bool)
- func (b *Branch) SetRetention(keepWhenInactive bool, days *int)
- func (b *Branch) SetScanConfig(scanOnPush, scanOnPR bool)
- func (b *Branch) Type() Type
- func (b *Branch) UpdateFindingStats(total, critical, high, medium, low int)
- func (b *Branch) UpdateLastCommit(sha, message, author, avatar string, at time.Time)
- func (b *Branch) UpdatedAt() time.Time
- type BranchTypeRule
- type BranchTypeRules
- type Filter
- type ListOptions
- type QualityGateStatus
- type Repository
- type ScanStatus
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("branch not found") ErrAlreadyExists = errors.New("branch already exists") )
Functions ¶
func AlreadyExistsError ¶
AlreadyExistsError returns a formatted already exists error.
func NotFoundError ¶
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 ¶
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) FindingsCritical ¶
func (*Branch) FindingsHigh ¶
func (*Branch) FindingsLow ¶
func (*Branch) FindingsMedium ¶
func (*Branch) FindingsTotal ¶
func (*Branch) HasCriticalFindings ¶
func (*Branch) HasFindings ¶
func (*Branch) IsProtected ¶
func (*Branch) KeepWhenInactive ¶
func (*Branch) LastCommitAt ¶
func (*Branch) LastCommitAuthor ¶
func (*Branch) LastCommitAuthorAvatar ¶
func (*Branch) LastCommitMessage ¶
func (*Branch) LastCommitSHA ¶
func (*Branch) LastScanID ¶
func (*Branch) LastScannedAt ¶
func (*Branch) MarkScanned ¶
func (b *Branch) MarkScanned(scanID shared.ID, status ScanStatus, qualityGate QualityGateStatus)
func (*Branch) QualityGateStatus ¶
func (b *Branch) QualityGateStatus() QualityGateStatus
func (*Branch) RepositoryID ¶
func (*Branch) RetentionDays ¶
func (*Branch) ScanOnPush ¶
func (*Branch) ScanStatus ¶
func (b *Branch) ScanStatus() ScanStatus
func (*Branch) SetDefault ¶
func (*Branch) SetProtected ¶
func (*Branch) SetRetention ¶
func (*Branch) SetScanConfig ¶
func (*Branch) UpdateFindingStats ¶
func (*Branch) UpdateLastCommit ¶
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.
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.