Some checks failed
CI / test (push) Failing after 4s
Watches issue/PR comments and pushes for flagged phrases; warns commenters via reply and opens a redacted correction PR for flagged file content, never rewriting history or deleting content directly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
// Package config loads yaju-keisatsu's YAML configuration file.
|
|
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type Config struct {
|
|
ListenAddr string `yaml:"listen_addr"`
|
|
WebhookSecret string `yaml:"webhook_secret"`
|
|
Forgejo Forgejo `yaml:"forgejo"`
|
|
Bot Bot `yaml:"bot"`
|
|
Phrases []string `yaml:"phrases"`
|
|
}
|
|
|
|
type Forgejo struct {
|
|
BaseURL string `yaml:"base_url"`
|
|
Token string `yaml:"token"`
|
|
}
|
|
|
|
type Bot struct {
|
|
// Username is the Forgejo account the API token belongs to. Comments
|
|
// authored by this account are ignored so the bot never replies to itself.
|
|
Username string `yaml:"username"`
|
|
// BranchPrefix is prepended to the auto-generated correction branch name.
|
|
BranchPrefix string `yaml:"branch_prefix"`
|
|
// TargetExtensions limits which pushed files are scanned for corrections.
|
|
// An empty list scans every file.
|
|
TargetExtensions []string `yaml:"target_extensions"`
|
|
}
|
|
|
|
func Load(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read config: %w", err)
|
|
}
|
|
|
|
cfg := &Config{
|
|
ListenAddr: ":8080",
|
|
Bot: Bot{
|
|
BranchPrefix: "bot/goroku-fix/",
|
|
},
|
|
}
|
|
if err := yaml.Unmarshal(data, cfg); err != nil {
|
|
return nil, fmt.Errorf("parse config: %w", err)
|
|
}
|
|
|
|
if cfg.Forgejo.BaseURL == "" {
|
|
return nil, fmt.Errorf("forgejo.base_url is required")
|
|
}
|
|
if cfg.Forgejo.Token == "" {
|
|
return nil, fmt.Errorf("forgejo.token is required")
|
|
}
|
|
if cfg.WebhookSecret == "" {
|
|
return nil, fmt.Errorf("webhook_secret is required")
|
|
}
|
|
if len(cfg.Phrases) == 0 {
|
|
return nil, fmt.Errorf("phrases list is empty")
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|