Example #1
0
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)

}
Example #2
0
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)

}
Example #3
0
func DeleteRepo(w http.ResponseWriter, r *http.Request) {
	body, _ := ioutil.ReadAll(r.Body)
	vars := mux.Vars(r)

	var cfg = database.Repository{}
	json.Unmarshal(body, &cfg)

	cfg.Name = vars["name"]

	oldConfig := database.GetRepositoryByName(cfg.Name)

	cfg.ID = oldConfig.ID

	ok := cfg.DeleteRepository()

	if ok {
		json.NewEncoder(w).Encode(cfg)
	} else {
		json.NewEncoder(w).Encode(models.ApiError{
			Code:    "error",
			Message: "Error on execute",
		})
	}
}