Ejemplo n.º 1
0
func addHook(w http.ResponseWriter, r *http.Request) {
	name := r.URL.Query().Get(":name")
	if name != "post-receive" && name != "pre-receive" && name != "update" {
		http.Error(w,
			"Unsupported hook, valid options are: post-receive, pre-receive or update",
			http.StatusBadRequest)
		return
	}
	defer r.Body.Close()
	var params repositoryHook
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	repos := []string{}
	if err := json.Unmarshal(body, &params); err != nil {
		if err := hook.Add(name, repos, body); err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
	} else {
		repos = params.Repositories
		if err := hook.Add(name, repos, []byte(params.Content)); err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
	}
	if len(repos) > 0 {
		fmt.Fprint(w, "hook ", name, " successfully created for ", repos, "\n")
	} else {
		fmt.Fprint(w, "hook ", name, " successfully created\n")
	}
}
Ejemplo n.º 2
0
func AddHook(w http.ResponseWriter, r *http.Request) {
	name := r.URL.Query().Get(":name")
	if name != "post-receive" && name != "pre-receive" && name != "update" {
		http.Error(w,
			"Unsupported hook, valid options are: post-receive, pre-receive or update",
			http.StatusBadRequest)
		return
	}
	defer r.Body.Close()
	if err := hook.Add(name, r.Body); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	fmt.Fprint(w, "hook ", name, " successfully created\n")
}