nitter/nitters/gitea/config.go

66 lines
1.3 KiB
Go
Raw Normal View History

2023-03-08 13:40:04 +00:00
package gitea
import (
2023-03-08 15:13:49 +00:00
"errors"
"code.gitea.io/sdk/gitea"
2023-03-08 13:40:04 +00:00
"code.icb4dc0.de/prskr/nitter/nitters"
)
2023-03-08 15:13:49 +00:00
var (
ErrMissingBaseAddress = errors.New("API base address is required")
ErrMissingToken = errors.New("API token is required")
ErrMissingPRIndex = errors.New("PR index is required")
)
2023-03-08 13:40:04 +00:00
type GiteaConfig struct {
nitters.Config `mapstructure:",squash"`
BaseAddress string `mapstructure:"base-address"`
Token string `mapstructure:"token"`
}
2023-03-08 15:13:49 +00:00
func (gc GiteaConfig) Validate() error {
if err := gc.Config.Validate(); err != nil {
return err
}
if gc.BaseAddress == "" {
return ErrMissingBaseAddress
}
if gc.Token == "" {
return ErrMissingToken
}
return nil
}
2023-03-08 13:40:04 +00:00
type GiteaPRConfig struct {
GiteaConfig `mapstructure:",squash"`
PRIndex int64 `mapstructure:"pull-index"`
ReviewState gitea.ReviewStateType `mapstructure:"review-state"`
2023-03-08 13:40:04 +00:00
}
2023-03-08 15:13:49 +00:00
func (gpc GiteaPRConfig) Validate() error {
if err := gpc.GiteaConfig.Validate(); err != nil {
return err
}
if gpc.PRIndex < 0 {
return ErrMissingPRIndex
}
return nil
}
type GiteaPRLintConfig struct {
GiteaPRConfig `mapstructure:",squash"`
FromPRBase bool `mapstructure:"from-pr-base"`
ExtraArgs []string `mapstructure:"golangci-lint-extra-args"`
}
func (gpc GiteaPRLintConfig) Validate() error {
return gpc.GiteaPRConfig.Validate()
}