diff --git a/configuration.go b/configuration.go new file mode 100644 index 0000000..f65fcb9 --- /dev/null +++ b/configuration.go @@ -0,0 +1,35 @@ +package main + +import ( + "os" + + "gopkg.in/yaml.v2" +) + +type Config struct { + Gitea struct { + InstanceURL string `yaml:"instance_url"` + Owner string `yaml:"owner"` + Repository string `yaml:"repository"` + } `yaml:"gitea"` + Language struct { + OpeningOnSeparateLine bool `yaml:"separate_opening"` + Opening string `yaml:"opening"` + Continuation string `yaml:"continuation"` + Closing string `yaml:"closing"` + } `yaml:"language"` +} + +func LoadConfig(config *Config, filename string) { + if filename == "" { + filename = ".frag_review.yml" + } + + configFile, err := os.Open(filename) + ExitOnError(err) + defer configFile.Close() + + decoder := yaml.NewDecoder(configFile) + err = decoder.Decode(&config) + ExitOnError(err) +} diff --git a/main.go b/main.go index 9c123c4..6635f03 100644 --- a/main.go +++ b/main.go @@ -9,25 +9,8 @@ import ( "strconv" "code.gitea.io/sdk/gitea" - "gopkg.in/yaml.v2" ) -type Config struct { - Gitea struct { - InstanceURL string `yaml:"instance_url"` - Owner string `yaml:"owner"` - Repository string `yaml:"repository"` - } `yaml:"gitea"` - Language struct { - OpeningOnSeparateLine bool `yaml:"separate_opening"` - Opening string `yaml:"opening"` - Continuation string `yaml:"continuation"` - Closing string `yaml:"closing"` - } `yaml:"language"` -} - -var config Config = Config{} - type ByLineNum []*gitea.PullReviewComment func (a ByLineNum) Len() int { return len(a) } @@ -138,23 +121,11 @@ func GetReviewsPerPR(client *gitea.Client, prID int64) []int64 { return result } -func LoadConfig(filename string) { - if filename == "" { - filename = ".frag_review.yml" - } - - configFile, err := os.Open(filename) - ExitOnError(err) - defer configFile.Close() - - decoder := yaml.NewDecoder(configFile) - err = decoder.Decode(&config) - ExitOnError(err) -} +var config Config = Config{} func main() { token := os.Getenv("GITEA_TOKEN") - LoadConfig(os.Getenv("FRAG_REVIEW_CONFIG")) + LoadConfig(&config, os.Getenv("FRAG_REVIEW_CONFIG")) client, err := gitea.NewClient(config.Gitea.InstanceURL, gitea.SetToken(token)) ExitOnError(err)