func DeleteConfiguration(w http.ResponseWriter, r *http.Request){ body, _ := ioutil.ReadAll(r.Body) vars := mux.Vars(r) var cfg = database.Configuration{} json.Unmarshal(body, &cfg) cfg.Name = vars["name"] oldConfig := database.GetConfigurationByName(cfg.Name) cfg.ID = oldConfig.ID ok := cfg.DeleteConfiguration() if ok{ json.NewEncoder(w).Encode(cfg) }else{ json.NewEncoder(w).Encode(models.ApiError{ Code: "error", Message: "Error on execute", }) } }
func GetRepo(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) repo := database.GetRepositoryByName(vars["name"]) repo.Hooks = database.GetHooksByRepo(repo.ID) json.NewEncoder(w).Encode(repo) }
func GetRepoActions(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) action := database.Action{ Repository: vars["repo"], } json.NewEncoder(w).Encode(action.GetByRepository()) }
func UpdateRepoHook(w http.ResponseWriter, r *http.Request) { body, _ := ioutil.ReadAll(r.Body) vars := mux.Vars(r) fmt.Println(vars) hook := database.Hook{} json.Unmarshal(body, &hook) hook.ID, _ = strconv.Atoi(vars["id"]) hook.UpdateHook() json.NewEncoder(w).Encode(hook) }
func CreateRepoHook(w http.ResponseWriter, r *http.Request) { body, _ := ioutil.ReadAll(r.Body) vars := mux.Vars(r) repo := database.GetRepositoryByName(vars["name"]) hook := database.Hook{} json.Unmarshal(body, &hook) hook.RepositoryId = repo.ID hook.SaveHook() json.NewEncoder(w).Encode(hook) }