Esempio n. 1
0
func (self *repository) updateBranchTracking() {
	branch, _ := self.runGitCommand("symbolic-ref", "--short", "HEAD")
	self.branch = strings.Join(branch, "\n")

	branches, _ := self.runGitCommand("branch", "--list", "--no-color")
	for _, b := range branches {
		b = strings.TrimLeft(b, " *")
		self.branches[b] = true
	}

	grip.Debug("updated branch tracking information.")
}
Esempio n. 2
0
// WriteJSONResponse writes a JSON document to the body of an HTTP
// request, setting the return status of to 500 if the JSON
// seralization process encounters an error, otherwise return
func WriteJSONResponse(w http.ResponseWriter, code int, data interface{}) {
	j := &JSONMessage{data: data}

	out, err := j.MarshalPretty()

	if err != nil {
		grip.CatchDebug(err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	grip.Debug(j)

	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	w.WriteHeader(code)
	size, err := w.Write(out)
	if err == nil {
		grip.Debugf("response object was %d", size)
	} else {
		grip.Warningf("encountered error %s writing a %d response", err.Error(), size)
	}
}