<commit_before>// Copyright Istio Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package model

import (
	"encoding/json"
	"path"
)

type BuildOutput int
type AutoDependency string

const (
	Docker BuildOutput = iota
	Helm
	Debian
	Archive

	// Deps will resolve by looking at the istio.deps file in istio/istio
	Deps string = "deps"
	// Modules will resolve by looking at the go.mod file in istio/istio
	Modules string = "modules"
)

// Dependency defines a git dependency for the build
type Dependency struct {
	// Git repository to pull from. Required if branch or sha is set
	Git string `json:"git,omitempty"`
	// Checkout the git branch
	Branch string `json:"branch,omitempty"`
	// Checkout the git SHA
	Sha string `json:"sha,omitempty"`
	// Copy the local path. Note this still needs to be a git repo.
	LocalPath string `json:"localpath,omitempty"`
	// Auto will fetch the SHA to use based on other repos. Currently this supports reading
	// istio.deps from istio/istio only.
	Auto string `json:"auto,omitempty"`
	// If true, go version semantic will be used for tagging the git repo, e.g. v1.2.3.
	GoVersionEnabled bool `json:"goversionenabled,omitempty"`
}

// Ref returns the git reference of a dependency.
func (d Dependency) Ref() string {
	ref := d.Branch
	if d.Sha != "" {
		ref = d.Sha
	}
	return ref
}

// Dependencies for the build
type IstioDependencies struct {
	Istio        *Dependency `json:"istio"`
	Cni          *Dependency `json:"cni"`
	Operator     *Dependency `json:"operator"`
	Api          *Dependency `json:"api"` //nolint: golint, stylecheck
	Proxy        *Dependency `json:"proxy"`
	Pkg          *Dependency `json:"pkg"`
	ClientGo     *Dependency `json:"client-go"`
	GogoGenproto *Dependency `json:"gogo-genproto"`
	TestInfra    *Dependency `json:"test-infra"`
	Tools        *Dependency `json:"tools"`
}

func (i *IstioDependencies) Get() map[string]*Dependency {
	return map[string]*Dependency{
		"istio":         i.Istio,
		"cni":           i.Cni,
		"operator":      i.Operator,
		"api":           i.Api,
		"proxy":         i.Proxy,
		"pkg":           i.Pkg,
		"client-go":     i.ClientGo,
		"gogo-genproto": i.GogoGenproto,
		"test-infra":    i.TestInfra,
		"tools":         i.Tools,
	}
}

// MarshalJSON writes the dependencies, exposing just the SHA
func (i IstioDependencies) MarshalJSON() ([]byte, error) {
	deps := make(map[string]Dependency)
	for repo, dep := range i.Get() {
		if dep == nil {
			continue
		}
		deps[repo] = Dependency{Sha: dep.Sha}
	}
	return json.Marshal(deps)
}

func (i *IstioDependencies) Set(repo string, dependency Dependency) {
	dp := i.Get()[repo]
	*dp = dependency
}

// Manifest defines what is in a release
type InputManifest struct {<commit_msg>Adding Installer as a configurable dependency in release-builder. (#104)<commit_after>// Copyright Istio Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package model

import (
	"encoding/json"
	"path"
)

type BuildOutput int
type AutoDependency string

const (
	Docker BuildOutput = iota
	Helm
	Debian
	Archive

	// Deps will resolve by looking at the istio.deps file in istio/istio
	Deps string = "deps"
	// Modules will resolve by looking at the go.mod file in istio/istio
	Modules string = "modules"
)

// Dependency defines a git dependency for the build
type Dependency struct {
	// Git repository to pull from. Required if branch or sha is set
	Git string `json:"git,omitempty"`
	// Checkout the git branch
	Branch string `json:"branch,omitempty"`
	// Checkout the git SHA
	Sha string `json:"sha,omitempty"`
	// Copy the local path. Note this still needs to be a git repo.
	LocalPath string `json:"localpath,omitempty"`
	// Auto will fetch the SHA to use based on other repos. Currently this supports reading
	// istio.deps from istio/istio only.
	Auto string `json:"auto,omitempty"`
	// If true, go version semantic will be used for tagging the git repo, e.g. v1.2.3.
	GoVersionEnabled bool `json:"goversionenabled,omitempty"`
}

// Ref returns the git reference of a dependency.
func (d Dependency) Ref() string {
	ref := d.Branch
	if d.Sha != "" {
		ref = d.Sha
	}
	return ref
}

// Dependencies for the build
type IstioDependencies struct {
	Istio        *Dependency `json:"istio"`
	Cni          *Dependency `json:"cni"`
	Operator     *Dependency `json:"operator"`
	Api          *Dependency `json:"api"` //nolint: golint, stylecheck
	Proxy        *Dependency `json:"proxy"`
	Pkg          *Dependency `json:"pkg"`
	ClientGo     *Dependency `json:"client-go"`
	GogoGenproto *Dependency `json:"gogo-genproto"`
	TestInfra    *Dependency `json:"test-infra"`
	Tools        *Dependency `json:"tools"`
	Installer    *Dependency `json:"installer"`
}

func (i *IstioDependencies) Get() map[string]*Dependency {
	return map[string]*Dependency{
		"istio":         i.Istio,
		"cni":           i.Cni,
		"operator":      i.Operator,
		"api":           i.Api,
		"proxy":         i.Proxy,
		"pkg":           i.Pkg,
		"client-go":     i.ClientGo,
		"gogo-genproto": i.GogoGenproto,
		"test-infra":    i.TestInfra,
		"tools":         i.Tools,
		"installer":     i.Installer,
	}
}

// MarshalJSON writes the dependencies, exposing just the SHA
func (i IstioDependencies) MarshalJSON() ([]byte, error) {
	deps := make(map[string]Dependency)
	for repo, dep := range i.Get() {
		if dep == nil {
			continue
		}
		deps[repo] = Dependency{Sha: dep.Sha}
	}
	return json.Marshal(deps)
}

func (i *IstioDependencies) Set(repo string, dependency Dependency) {
	dp := i.Get()[repo]
	*dp = dependency
}

// Manifest defines what is in a release
type InputManifest struct {
{'fraction_non_alphanumeric': 0.11338345864661654, 'fraction_numerical': 0.002556390977443609, 'mean_word_length': 3.3216374269005846, 'pattern_counts': {'":': 21, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7276016', 'n_tokens_mistral': 2124, 'n_tokens_neox': 2055, 'n_words': 745}