config

package
v2.3.10 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	StoragePath: "./storage/",
	Logger: Logger{
		File:  "./bot.log",
		Level: "info",
	},
	OpenWeather: OpenWeather{
		Units: "metric",
	},

	Jira: Jira{
		Fields: []JiraField{
			{
				Name: "type",
				Icons: map[string]string{
					"Bug": ":bug:",
				},
			},
		},
	},
	PullRequest: PullRequest{
		Notifications: Notifications{
			BuildStatusInProgress:      false,
			BuildStatusSuccess:         false,
			BuildStatusFailed:          false,
			PullRequestStatusMergeable: false,
		},
		Reactions: PullRequestReactions{
			InReview:     "eyes",
			Approved:     "white_check_mark",
			Merged:       "twisted_rightwards_arrows",
			Closed:       "x",
			BuildSuccess: "white_check_mark",
			BuildFailed:  "fire",
			BuildRunning: "arrows_counterclockwise",
			Error:        "x",
		},
	},
	BranchLookup: VCS{
		UpdateInterval: time.Minute * 2,
	},
}

DefaultConfig with some common values

Functions

func Dump

func Dump(cfg Config) string

Dump the given config in a yaml string

Types

type Aws added in v2.2.6

type Aws struct {
	Enabled    bool                `mapstructure:"enabled"`
	CloudFront []AwsCfDistribution `mapstructure:"cloud_front"`
}

func (Aws) IsEnabled added in v2.2.6

func (c Aws) IsEnabled() bool

type AwsCfDistribution added in v2.2.6

type AwsCfDistribution struct {
	ID   string `mapstructure:"id"`
	Name string `mapstructure:"name"`
}

type Bitbucket

type Bitbucket struct {
	Host       string `mapstructure:"host"`
	Username   string `mapstructure:"username"`
	Password   string `mapstructure:"password"`
	APIKey     string `mapstructure:"api_key"`
	Project    string `mapstructure:"project"`
	Repository string `mapstructure:"repository"`
}

Bitbucket credentials/options. Either add Username+Password OR a APIKey

func (*Bitbucket) IsEnabled

func (c *Bitbucket) IsEnabled() bool

IsEnabled checks if a host is defined in the Bitbucket config

type Command

type Command struct {
	Name        string
	Description string
	Trigger     string
	Category    string
	Commands    []string
	Examples    []string
}

Command represents a single macro which is defined by a trigger regexp and a list of executed commands

type Config

type Config struct {
	Slack Slack `mapstructure:"slack"`

	// authentication/authorization
	NoAuthentication bool     `mapstructure:"no_authentication"`
	AllowedUsers     UserList `mapstructure:"allowed_users,flow"`
	AdminUsers       UserList `mapstructure:"admin_users,flow"`

	Pool        Pool      `mapstructure:"pool"`
	Jenkins     Jenkins   `mapstructure:"jenkins"`
	Jira        Jira      `mapstructure:"jira"`
	StoragePath string    `mapstructure:"storage_path"`
	Bitbucket   Bitbucket `mapstructure:"bitbucket"`
	Github      Github    `mapstructure:"github"`
	Gitlab      struct {
		AccessToken string
		Host        string
	} `mapstructure:"gitlab"`
	Aws      Aws       `mapstructure:"aws"`
	Commands []Command `mapstructure:"commands"`
	Crons    []Cron    `mapstructure:"crons"`
	Logger   Logger    `mapstructure:"logger"`

	BranchLookup VCS `mapstructure:"branch_lookup"`

	// Metrics, like Prometheus
	Metrics Metrics `mapstructure:"metrics"`

	OpenWeather OpenWeather `mapstructure:"open_weather"`
	PullRequest PullRequest `mapstructure:"pullrequest"`
	Timezone    string      `mapstructure:"timezone"`

	// list of slack-bot plugins to load
	Plugins []string `mapstructure:"plugins"`
	// contains filtered or unexported fields
}

Config contains the full config structure of this bot

func Load

func Load(configFile string) (Config, error)

Load all yaml config from a directory or a single .yaml file

func (*Config) LoadCustom added in v2.2.10

func (c *Config) LoadCustom(key string, value any) error

LoadCustom does a dynamic config lookup with a given key and unmarshal it into the value

func (*Config) Set added in v2.2.10

func (c *Config) Set(key string, value any)

Set a dynamic config value...please only set it in tests!

type Cron

type Cron struct {
	Channel  string   `mapstructure:"channel"`
	Schedule string   `mapstructure:"schedule"`
	Commands []string `mapstructure:"commands"`
}

Cron is represents a single cron which can be configured

type Github

type Github struct {
	AccessToken string `mapstructure:"access_token"`
}

Github config, currently just an access token

type Jenkins

type Jenkins struct {
	Host     string
	Username string
	Password string
	Jobs     JenkinsJobs
}

Jenkins is the main Jenkins config, including credentials and the whitelisted jobs

func (Jenkins) IsEnabled

func (c Jenkins) IsEnabled() bool

IsEnabled checks if a host was defined...by default it's not set

type JenkinsJobs

type JenkinsJobs map[string]JobConfig

JenkinsJobs is the list of all (whitelisted) Jenkins jobs

func (JenkinsJobs) GetSortedNames

func (j JenkinsJobs) GetSortedNames() []string

GetSortedNames get all defined job names, sorted by name

type Jira

type Jira struct {
	Host        string
	Username    string
	Password    string
	AccessToken string
	Project     string
	Fields      []JiraField
}

Jira configuration: credentials and custom formatting options

func (*Jira) IsEnabled

func (c *Jira) IsEnabled() bool

IsEnabled checks if a host is defined (username/password) is not needed for public projects

type JiraField

type JiraField struct {
	Name  string
	Icons map[string]string
}

JiraField are custom Jira issue fields which should be displayed in the search/output Icons can be provided to have special mapping, e.g. for bug type or different priorities

type JobConfig

type JobConfig struct {
	Parameters []JobParameter
	Trigger    string
	OnStart    []string
	OnSuccess  []string
	OnFailure  []string
}

JobConfig concrete job configuration -> only defined jobs are (re)startable

type JobParameter

type JobParameter struct {
	Name    string
	Default string
	Type    string
}

JobParameter are defined build parameters per job

type Logger

type Logger struct {
	Level string `mapstructure:"level"`
	File  string `mapstructure:"file"`
}

Logger configuration to define log target or log levels

type Metrics added in v2.2.10

type Metrics struct {
	// e.g. use ":8082" to expose metrics on all interfaces
	PrometheusListener string `mapstructure:"prometheus_listener"`
}

func (*Metrics) IsEnabled added in v2.2.10

func (c *Metrics) IsEnabled() bool

IsEnabled returns true if the metrics are enabled by config

type Notifications added in v2.2.9

type Notifications struct {
	BuildStatusInProgress      bool `mapstructure:"build_status_in_progress"`
	BuildStatusSuccess         bool `mapstructure:"build_status_success"`
	BuildStatusFailed          bool `mapstructure:"build_status_failed"`
	PullRequestStatusMergeable bool `mapstructure:"pr_status_mergeable"`
}

Notifications can be defined in the config.yaml to enable notifications for pull request builds. the defaults are defined in default.go

type OpenWeather

type OpenWeather struct {
	Apikey   string
	Location string
	URL      string
	Units    string
}

OpenWeather is an optional feature to get current weather

type Pool added in v2.2.10

type Pool struct {
	LockDuration time.Duration
	NotifyExpire time.Duration
	Resources    []*Resource
}

Pool config contains the Resources of the Pool

func (*Pool) IsEnabled added in v2.2.10

func (c *Pool) IsEnabled() bool

IsEnabled checks if there are resources in the pool

type PullRequest

type PullRequest struct {
	// overwrite reactions, default ones, see default.go
	Reactions PullRequestReactions `mapstructure:"reactions"`

	// enable private notifications for the build status
	Notifications Notifications `mapstructure:"notifications"`

	// able to set a custom "approved" reactions to see directly who or which component/department approved a pullrequest
	CustomApproveReaction map[string]util.Reaction `mapstructure:"custom_approve_reaction"`
}

PullRequest special configuration to change the pull request behavior

type PullRequestReactions

type PullRequestReactions struct {
	InReview     util.Reaction `mapstructure:"in_review"`
	Approved     util.Reaction `mapstructure:"approved"`
	Merged       util.Reaction `mapstructure:"merged"`
	Closed       util.Reaction `mapstructure:"closed"`
	BuildSuccess util.Reaction `mapstructure:"build_success"`
	BuildRunning util.Reaction `mapstructure:"build_running"`
	BuildFailed  util.Reaction `mapstructure:"build_failed"`
	Error        util.Reaction `mapstructure:"error"`
}

PullRequestReactions can be defined in the config.yaml to have custom reactions for pull requests. the defaults are defined in default.go

type Resource added in v2.2.10

type Resource struct {
	Name         string
	ExplicitLock bool
	Addresses    []string
	Features     []string
}

Resource config contains definitions about the

type Slack

type Slack struct {
	Token         string   `mapstructure:"token"`
	SocketToken   string   `mapstructure:"socket_token"`
	AllowedGroups []string `mapstructure:"allowed_groups,flow"`
	ErrorChannel  string   `mapstructure:"error_channel"`

	Debug bool `mapstructure:"debug"`

	// only used for integration tests
	TestEndpointURL string `mapstructure:"-"`
}

Slack contains the credentials and configuration of the Slack client

func (Slack) IsFakeServer added in v2.2.4

func (s Slack) IsFakeServer() bool

IsFakeServer is set for the "cli" tool which is spawning a fake test server which is mocking parts of the Slack API

type UserList

type UserList []string

UserList is a wrapper for []string with some helper to check is a user is in the list (e.g. used for AdminUser list)

func (UserList) Contains

func (l UserList) Contains(givenUserID string) bool

Contains checks if the given user is in the UserList

type UserMap

type UserMap map[string]string

UserMap indexed by user id, value is the user name

func (UserMap) Contains

func (m UserMap) Contains(givenUserID string) bool

Contains checks if the given user is in the UserMap

type VCS added in v2.2.10

type VCS struct {
	Type           string        `mapstructure:"type"` // stash/bitbucket/git/null
	Repository     string        `mapstructure:"repository"`
	UpdateInterval time.Duration `mapstructure:"update_interval"`
}

func (VCS) IsEnabled added in v2.2.10

func (c VCS) IsEnabled() bool

Jump to

Keyboard shortcuts

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