nitter/nitters/gitea/config.go
Peter Kurfer c1c1667d9f
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is passing
feat(gitea): add lint-pr command
lint-pr runs golangci-lint, captures the result and uses it directly without temporary files
It also allows to automatically retrieve the PRs base commit and run golangci-lint only against changes in the current PR
2023-03-09 12:15:35 +01:00

65 lines
1.3 KiB
Go

package gitea
import (
"errors"
"code.gitea.io/sdk/gitea"
"code.icb4dc0.de/prskr/nitter/nitters"
)
var (
ErrMissingBaseAddress = errors.New("API base address is required")
ErrMissingToken = errors.New("API token is required")
ErrMissingPRIndex = errors.New("PR index is required")
)
type GiteaConfig struct {
nitters.Config `mapstructure:",squash"`
BaseAddress string `mapstructure:"base-address"`
Token string `mapstructure:"token"`
}
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
}
type GiteaPRConfig struct {
GiteaConfig `mapstructure:",squash"`
PRIndex int64 `mapstructure:"pull-index"`
ReviewState gitea.ReviewStateType `mapstructure:"review-state"`
}
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()
}