diff --git a/kit/config/config.go b/kit/config/config.go index 6d780e7..fec8164 100755 --- a/kit/config/config.go +++ b/kit/config/config.go @@ -7,13 +7,14 @@ import ( ) type Config struct { - Secret string `yaml:"secret"` - Port int `yaml:"port"` - Projects map[string]map[string]ConfigScript `yaml:"projects"` + Secret string `yaml:"secret"` + Port int `yaml:"port"` + Projects map[string][]ConfigScript `yaml:"projects"` } type ConfigScript struct { - BinaryPath string `yaml:"binary"` - ScriptPath string `yaml:"script"` + Environment string `yaml:"environment"` + BinaryPath string `yaml:"binary"` + ScriptPath string `yaml:"script"` } func LoadConfig(path string) (*Config, error) { diff --git a/main.go b/main.go index 6821b0a..24405d1 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,7 @@ func main() { http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), nil) } -func handlePayload(secret string, projects map[string]map[string]config.ConfigScript) func(w http.ResponseWriter, r *http.Request) { +func handlePayload(secret string, projects map[string][]config.ConfigScript) func(w http.ResponseWriter, r *http.Request) { return (func(w http.ResponseWriter, r *http.Request) { // Read the request body body, err := io.ReadAll(r.Body) @@ -64,8 +64,16 @@ func handlePayload(secret string, projects map[string]map[string]config.ConfigSc return } branchName := strings.Split(payload.Ref, "/")[len(strings.Split(payload.Ref, "/"))-1] + found = false + var scr config.ConfigScript + for i := range proj { + if proj[i].Environment == branchName { + found = true + scr = proj[i] + break + } - scr, found := proj[branchName] + } if !found { http.Error(w, "not found", http.StatusNotFound) return