Пример #1
0
func HandlerGetAllJobs(w http.ResponseWriter, r *http.Request) {
	log.Debugf("%s %s", r.Method, r.URL)
	var jobsData []map[string]interface{}
	w.Header().Set("Content-Type", "application/json")
	w.Header().Set("Access-Control-Allow-Origin", "*")

	cookie, _ := r.Cookie("sessionId")
	//sess, _ := GlobalSessions.SessionStart(w, r)
	sess, _ := GlobalSessions.GetSessionStore(cookie.Value)
	log.Debugf("user:%s", sess.Get("user"))
	fmt.Println(sess)
	log.Debugf("sid: %s", sess.SessionID())
	jc := getJenkinsClient(cookie.Value)
	fmt.Println("jc:", jc)
	jobs, _ := jc.GetAllJobs()
	for _, job := range jobs {
		jobData := utils.AnalysisJob(job.Raw)
		jobsData = append(jobsData, jobData)
	}

	jsonData, err := json.Marshal(jobsData)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Write(jsonData)
}
Пример #2
0
func HandlerGetJob(params martini.Params, w http.ResponseWriter, r *http.Request) {
	jobid := params[":jobid"]

	w.Header().Set("Content-Type", "application/json")
	w.Header().Set("Access-Control-Allow-Origin", "*")

	cookie, _ := r.Cookie("sessionId")
	jc := getJenkinsClient(cookie.Value)
	job, err := jc.GetJob(jobid)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	jobData := utils.AnalysisJob(job.Raw)

	jsonData, err := json.Marshal(jobData)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Write(jsonData)
}