<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package builds

import (
	"encoding/json"
	"net/http"

	h "github.com/ernestio/api-gateway/helpers"
	"github.com/ernestio/api-gateway/models"
)

// List : responds to GET /builds/ with a list of all
// builds for current user group
func List(au models.User, env string) (int, []byte) {
	var b models.Build
	var e models.Env
	var list []models.Build
	var body []byte

	err := e.FindByName(env)
	if err != nil {
		h.L.Error(err.Error())
		return 404, []byte("Environment not found")
	}

	if st, res := h.IsAuthorizedToResource(&au, h.GetEnv, e.GetType(), e.Name); st != 200 {
		return st, res
	}

	err = b.FindByEnvironmentName(env, &list)
	if err != nil {
		h.L.Warning(err.Error())
		return 404, []byte("Build not found")
	}

	body, err = json.Marshal(list)
	if err != nil {
		return 500, []byte("Internal error")
	}
<commit_msg>removing completed builds from build list<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package builds

import (
	"encoding/json"
	"net/http"

	h "github.com/ernestio/api-gateway/helpers"
	"github.com/ernestio/api-gateway/models"
)

// List : responds to GET /builds/ with a list of all
// builds for current user group
func List(au models.User, env string) (int, []byte) {
	var b models.Build
	var e models.Env
	var list []models.Build
	var body []byte

	err := e.FindByName(env)
	if err != nil {
		h.L.Error(err.Error())
		return 404, []byte("Environment not found")
	}

	if st, res := h.IsAuthorizedToResource(&au, h.GetEnv, e.GetType(), e.Name); st != 200 {
		return st, res
	}

	err = b.FindByEnvironmentName(env, &list)
	if err != nil {
		h.L.Warning(err.Error())
		return 404, []byte("Build not found")
	}

	for i := len(list) - 1; i >= 0; i-- {
		if list[i].Type == "sync" && list[i].Status == "done" {
			list = append(list[:i], list[i+1:]...)
		}
	}

	body, err = json.Marshal(list)
	if err != nil {
		return 500, []byte("Internal error")
	}

{'fraction_non_alphanumeric': 0.15428571428571428, 'fraction_numerical': 0.015384615384615385, 'mean_word_length': 3.3601532567049808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1651748', 'n_tokens_mistral': 878, 'n_tokens_neox': 817, 'n_words': 264}