fix: allow multiple enviornments
This commit is contained in:
parent
3d2cd78b07
commit
adf47e4810
|
@ -9,9 +9,10 @@ import (
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Secret string `yaml:"secret"`
|
Secret string `yaml:"secret"`
|
||||||
Port int `yaml:"port"`
|
Port int `yaml:"port"`
|
||||||
Projects map[string]map[string]ConfigScript `yaml:"projects"`
|
Projects map[string][]ConfigScript `yaml:"projects"`
|
||||||
}
|
}
|
||||||
type ConfigScript struct {
|
type ConfigScript struct {
|
||||||
|
Environment string `yaml:"environment"`
|
||||||
BinaryPath string `yaml:"binary"`
|
BinaryPath string `yaml:"binary"`
|
||||||
ScriptPath string `yaml:"script"`
|
ScriptPath string `yaml:"script"`
|
||||||
}
|
}
|
||||||
|
|
12
main.go
12
main.go
|
@ -31,7 +31,7 @@ func main() {
|
||||||
http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), nil)
|
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) {
|
return (func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Read the request body
|
// Read the request body
|
||||||
body, err := io.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
|
@ -64,8 +64,16 @@ func handlePayload(secret string, projects map[string]map[string]config.ConfigSc
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
branchName := strings.Split(payload.Ref, "/")[len(strings.Split(payload.Ref, "/"))-1]
|
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 {
|
if !found {
|
||||||
http.Error(w, "not found", http.StatusNotFound)
|
http.Error(w, "not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue