2023-03-08 13:40:04 +00:00
|
|
|
package gitea
|
|
|
|
|
|
|
|
import (
|
2023-03-08 15:13:49 +00:00
|
|
|
"errors"
|
|
|
|
|
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"`
|
|
|
|
}
|
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
|
|
|
|
}
|