gerritcp/config.go

56 lines
1.1 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"strings"
"gopkg.in/yaml.v2"
)
type Repo struct {
URL string `yaml:"url"`
Repo string `yaml:"repo"`
Branch string `yaml:"branch"`
Authentication string `yaml:"authentication"`
CookieName string `yaml:"cookieName"`
CookieValue string `yaml:"cookieValue"`
}
func (r *Repo) FullURL() string {
return strings.TrimSuffix(r.URL, "/") + "/" + r.Repo
}
type Workstreams struct {
OnlyIfTouching []string `yaml:"onlyIfTouching"`
NeverModify []string `yaml:"neverModify"`
}
type sites struct {
Upstream Repo
Downstream Repo
}
type configFormat struct {
Sites sites `yaml:"sites"`
Workstreams map[string]Workstreams `yaml:"workstreams"`
}
func readConfig(configFile string) *configFormat {
file, err := os.Open(configFile)
if err != nil {
panic(fmt.Sprintf("Could not open '%s': %s", configFile, err))
}
defer file.Close()
cfg := new(configFormat)
configDecoder := yaml.NewDecoder(file)
err = configDecoder.Decode(&cfg)
if err != nil {
panic(fmt.Sprintf("Failed parsing '%s': %s", configFile, err))
}
return cfg
}