config

package
v0.0.0-...-b41f85f Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package config provides configuration management for DependaBot

Index

Constants

View Source
const (
	// HookRuleStrategyFillEmpty injects hook only when target hook is not configured
	HookRuleStrategyFillEmpty = "fillEmpty"
	// HookRuleStrategyOverride always overrides target hook when source hook is configured
	HookRuleStrategyOverride = "override"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigReader

type ConfigReader struct{}

ConfigReader handles reading and merging configuration files

func NewConfigReader

func NewConfigReader() *ConfigReader

NewConfigReader creates a new configuration reader

func (*ConfigReader) ApplyDefaults

func (c *ConfigReader) ApplyDefaults(config *DependaBotConfig) *DependaBotConfig

ApplyDefaults applies default values to configuration

func (*ConfigReader) ApplyHookRules

func (c *ConfigReader) ApplyHookRules(config *DependaBotConfig) error

ApplyHookRules applies conditional hook rules based on repository context.

func (*ConfigReader) MergeConfigs

func (c *ConfigReader) MergeConfigs(configs ...*DependaBotConfig) *DependaBotConfig

MergeConfigs merges multiple configurations with priority order Later configurations override earlier ones

func (*ConfigReader) ReadExternalConfig

func (c *ConfigReader) ReadExternalConfig(configPath string) (*DependaBotConfig, error)

ReadExternalConfig reads configuration from external file specified by CLI

func (*ConfigReader) ReadRepoConfig

func (c *ConfigReader) ReadRepoConfig(projectPath string) (*DependaBotConfig, error)

ReadRepoConfig reads configuration from repository configuration files Supports both legacy format and GitHub Dependabot format Searches for configuration files in the following order: 1. .dependabot.yml in project root directory 2. .dependabot.yaml in project root directory 3. .github/dependabot.yml 4. .github/dependabot.yaml

type DependaBotConfig

type DependaBotConfig struct {
	// Repo contains repository information
	Repo RepoConfig `yaml:"repo" json:"repo" mapstructure:"repo"`
	// PR contains PR-specific configuration
	PR PRConfig `yaml:"pr" json:"pr" mapstructure:"pr"`
	// Scanner contains scanner configuration (supports multiple scanner types)
	Scanner ScannerConfig `yaml:"scanner" json:"scanner" mapstructure:"scanner"`
	// Git contains git provider configuration
	Git GitProviderConfig `yaml:"git" json:"git" mapstructure:"git"`
	// Notice contains notice configuration
	Notice NoticeConfig `yaml:"notice" json:"notice" mapstructure:"notice"`
	// Hooks contains custom script configuration for pipeline hooks
	Hooks HooksConfig `yaml:"hooks" json:"hooks" mapstructure:"hooks"`
	// Updater contains updater-specific configuration
	Updater UpdaterConfig `yaml:"updater" json:"updater" mapstructure:"updater"`
	// Runtime contains runtime behavior configuration
	Runtime RuntimeConfig `yaml:"runtime" json:"runtime" mapstructure:"runtime"`
}

DependaBotConfig represents the complete configuration for DependaBot (legacy format)

func (*DependaBotConfig) String

func (c *DependaBotConfig) String() string

String implements fmt.Stringer interface for better debugging experience

type GitHubDependabotConfig

type GitHubDependabotConfig struct {
	Version int                            `yaml:"version" json:"version"`
	Updates []GitHubDependabotUpdateConfig `yaml:"updates" json:"updates"`
}

GitHubDependabotConfig represents GitHub Dependabot compatible configuration

type GitHubDependabotUpdateConfig

type GitHubDependabotUpdateConfig struct {
	PackageEcosystem string   `yaml:"package-ecosystem" json:"package-ecosystem"`
	Labels           []string `yaml:"labels,omitempty" json:"labels,omitempty"`
	Assignees        []string `yaml:"assignees,omitempty" json:"assignees,omitempty"`
}

GitHubDependabotUpdateConfig represents a single package ecosystem update configuration

type GitProviderConfig

type GitProviderConfig struct {
	// Provider is the type of git provider (e.g., "github", "gitlab")
	Provider string `yaml:"provider" json:"provider" mapstructure:"provider"`
	// BaseURL is the base URL of the git provider (e.g., "https://github.com")
	BaseURL string `yaml:"baseURL" json:"baseURL" mapstructure:"baseURL"`
	// Token is the authentication token for the git provider
	Token string `yaml:"token" json:"token" mapstructure:"token"`
}

type GoUpdaterConfig

type GoUpdaterConfig struct {
	// CommandOutputFile is the file path to output successful go get commands
	// If empty, no output will be written
	CommandOutputFile string `yaml:"commandOutputFile" json:"commandOutputFile" mapstructure:"commandOutputFile"`
}

GoUpdaterConfig contains Go-specific updater configuration

type HookConfig

type HookConfig struct {
	// Script contains the script content to execute
	Script string `yaml:"script" json:"script" mapstructure:"script"`
	// Timeout for script execution (e.g., "5m", "30s")
	Timeout string `yaml:"timeout" json:"timeout" mapstructure:"timeout"`
	// ContinueOnError determines whether to continue pipeline execution if script fails
	ContinueOnError bool `yaml:"continueOnError" json:"continueOnError" mapstructure:"continueOnError"`
}

HookConfig contains configuration for a single pipeline hook

type HookRule

type HookRule struct {
	Name     string       `yaml:"name" json:"name" mapstructure:"name"`
	When     HookRuleWhen `yaml:"when" json:"when" mapstructure:"when"`
	Strategy string       `yaml:"strategy" json:"strategy" mapstructure:"strategy"`
	Hooks    HooksConfig  `yaml:"hooks" json:"hooks" mapstructure:"hooks"`
}

HookRule defines one conditional hook injection rule.

type HookRuleWhen

type HookRuleWhen struct {
	// RepoNameGlob matches repository name (without .git), e.g. tektoncd-*
	RepoNameGlob string `yaml:"repoNameGlob" json:"repoNameGlob" mapstructure:"repoNameGlob"`
}

HookRuleWhen defines conditions for matching repository context.

type HooksConfig

type HooksConfig struct {
	// PreVerifyScan contains script to execute before verification scanning
	// Use case: apply existing remediation commands to verify if vulnerabilities are already fixed
	PreVerifyScan *HookConfig `yaml:"preVerifyScan" json:"preVerifyScan" mapstructure:"preVerifyScan"`
	// PostVerifyScan contains script to execute after verification scanning
	// Use case: cleanup workspace after verification stage, regardless of verification outcome
	PostVerifyScan *HookConfig `yaml:"postVerifyScan" json:"postVerifyScan" mapstructure:"postVerifyScan"`
	// PreScan contains script to execute before security scanning
	PreScan *HookConfig `yaml:"preScan" json:"preScan" mapstructure:"preScan"`
	// PostScan contains script to execute after security scanning
	PostScan *HookConfig `yaml:"postScan" json:"postScan" mapstructure:"postScan"`
	// PreCommit contains script to execute before committing changes
	PreCommit *HookConfig `yaml:"preCommit" json:"preCommit" mapstructure:"preCommit"`
	// PostCommit contains script to execute after committing changes
	PostCommit *HookConfig `yaml:"postCommit" json:"postCommit" mapstructure:"postCommit"`
	// Rules contains conditional hook injection rules, typically used in global config
	Rules []HookRule `yaml:"rules" json:"rules" mapstructure:"rules"`
}

HooksConfig contains custom script configuration for pipeline hooks

type NoticeConfig

type NoticeConfig struct {
	// Type is the type of notice (e.g., "slack", "dingtalk")
	Type string `yaml:"type" json:"type" mapstructure:"type"`
	// Params contains notice-specific parameters
	Params map[string]interface{} `yaml:"params" json:"params" mapstructure:"params"`
}

type PRConfig

type PRConfig struct {
	AutoCreate *bool `yaml:"autoCreate" json:"autoCreate" mapstructure:"autoCreate"`
	// PushBranch controls whether to push the branch to remote repository
	PushBranch *bool `yaml:"pushBranch" json:"pushBranch" mapstructure:"pushBranch"`
	// Labels are labels to add to the created PR
	Labels []string `yaml:"labels" json:"labels" mapstructure:"labels"`
	// Assignees are users to assign to the created PR
	Assignees []string `yaml:"assignees" json:"assignees" mapstructure:"assignees"`
}

PRConfig contains pull request configuration

func (*PRConfig) NeedCreatePR

func (p *PRConfig) NeedCreatePR() bool

func (*PRConfig) NeedPushBranch

func (p *PRConfig) NeedPushBranch() bool

NeedPushBranch determines whether to push branch based on configuration If autocreate is true, push branch automatically becomes true

type PipelineScannerConfig

type PipelineScannerConfig = ScannerConfig

PipelineScannerConfig represents scanner config for pipeline

type RepoConfig

type RepoConfig struct {
	// URL is the repository URL (e.g., "https://github.com/example/repo")
	URL string `yaml:"url" json:"url" mapstructure:"url"`
	// Branch is the repository branch (e.g., "main")
	Branch string `yaml:"branch" json:"branch" mapstructure:"branch"`
	// IncludeSubmodules indicates whether to clone submodules
	IncludeSubmodules *bool `yaml:"includeSubmodules" json:"includeSubmodules" mapstructure:"includeSubmodules"`
}

func (*RepoConfig) GetIncludeSubmodules

func (r *RepoConfig) GetIncludeSubmodules() bool

GetIncludeSubmodules returns the IncludeSubmodules value with default fallback

type RuntimeConfig

type RuntimeConfig struct {
	// CleanupTempDirs controls whether temporary directories are cleaned up after execution
	CleanupTempDirs *bool `yaml:"cleanupTempDirs" json:"cleanupTempDirs" mapstructure:"cleanupTempDirs"`
}

RuntimeConfig contains runtime behavior configuration

type ScannerConfig

type ScannerConfig struct {
	// Type specifies the scanner type (e.g., "trivy", "govulncheck")
	Type string `yaml:"type" json:"type" mapstructure:"type"`
	// Timeout for scanner execution (e.g., "5m")
	Timeout string `yaml:"timeout" json:"timeout" mapstructure:"timeout"`
	// Params contains scanner-specific parameters
	Params []string `yaml:"params" json:"params" mapstructure:"params"`
}

ScannerConfig contains generic scanner configuration

type UpdaterConfig

type UpdaterConfig struct {
	// Go contains Go-specific updater configuration
	Go *GoUpdaterConfig `yaml:"go" json:"go" mapstructure:"go"`
}

UpdaterConfig contains updater-specific configuration

Jump to

Keyboard shortcuts

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