Пример #1
0
// lastGreen returns the most recent version for which the supplied variants completely pass.
func (ra *restAPI) lastGreen(w http.ResponseWriter, r *http.Request) {
	projCtx := MustHaveRESTContext(r)
	p := projCtx.Project
	if p == nil {
		http.Error(w, "project not found", http.StatusNotFound)
		return
	}

	// queryParams should list build variants, example:
	// GET /rest/v1/projects/mongodb-mongo-master/last_green?linux-64=1&windows-64=1
	queryParams := r.URL.Query()

	// Make sure all query params are valid variants and put them in an array
	var bvs []string
	for key := range queryParams {
		if p.FindBuildVariant(key) != nil {
			bvs = append(bvs, key)
		} else {
			msg := fmt.Sprintf("build variant '%v' does not exit", key)
			http.Error(w, msg, http.StatusNotFound)
			return
		}
	}

	// Get latest version for which all the given build variants passed.
	version, err := model.FindLastPassingVersionForBuildVariants(p, bvs)
	if err != nil {
		ra.LoggedError(w, r, http.StatusInternalServerError, err)
		return
	}
	if version == nil {
		msg := fmt.Sprintf("Couldn't find latest green version for %v", strings.Join(bvs, ", "))
		http.Error(w, msg, http.StatusNotFound)
		return
	}

	ra.WriteJSON(w, http.StatusOK, version)
}
Пример #2
0
func (uis *UIServer) lastGreenHandler(w http.ResponseWriter, r *http.Request) {
	projCtx := MustHaveProjectContext(r)

	// queryParams should list build variants, example:
	// GET /ui/json/last_green/mongodb-mongo-master?linux-64=1&windows-64=1
	queryParams := r.URL.Query()

	if projCtx.Project == nil {
		http.Error(w, "project not found", http.StatusNotFound)
		return
	}

	// Make sure all query params are valid build variants and put them in an array
	var buildVariantNames []string
	for key, _ := range queryParams {
		if projCtx.Project.FindBuildVariant(key) != nil {
			buildVariantNames = append(buildVariantNames, key)
		} else {
			http.Error(w, "build variant not found", http.StatusNotFound)
			return
		}
	}

	// Get latest version for which all the given build variants passed.
	version, err := model.FindLastPassingVersionForBuildVariants(*projCtx.Project,
		buildVariantNames)
	if err != nil {
		uis.LoggedError(w, r, http.StatusInternalServerError, err)
		return
	}
	if version == nil {
		http.Error(w, "Couldn't find latest green version", http.StatusNotFound)
		return
	}

	uis.WriteJSON(w, http.StatusOK, version)
}