<commit_before>// Copyright 2021 Google LLC
//
// 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 defines the schema for Kptfile version v1alpha2.
package v1alpha2

import (
	"fmt"

	"sigs.k8s.io/kustomize/kyaml/yaml"
)

const (
	KptFileName       = "Kptfile"
	KptFileKind       = "Kptfile"
	KptFileGroup      = "kpt.dev"
	KptFileVersion    = "v1alpha2"
	KptFileAPIVersion = KptFileGroup + "/" + KptFileVersion
)

// TypeMeta is the TypeMeta for KptFile instances.
var TypeMeta = yaml.ResourceMeta{
	TypeMeta: yaml.TypeMeta{
		APIVersion: KptFileAPIVersion,
		Kind:       KptFileName,
	},
}

// KptFile contains information about a package managed with kpt.
type KptFile struct {
	yaml.ResourceMeta `yaml:",inline"`

	Upstream *Upstream `yaml:"upstream,omitempty"`

	// UpstreamLock is a resolved locator for the last fetch of the package.
	UpstreamLock *UpstreamLock `yaml:"upstreamLock,omitempty"`

	// Info contains metadata such as license, documentation, etc.
	Info *PackageInfo `yaml:"info,omitempty"`

	// Pipeline declares the pipeline of functions.
	Pipeline *Pipeline `yaml:"pipeline,omitempty"`

	// Inventory contains parameters for the inventory object used in apply.
	Inventory *Inventory `yaml:"inventory,omitempty"`
}

// OriginType defines the type of origin for a package.
type OriginType string

const (
	// GitOrigin specifies a package as having been cloned from a git repository.
	GitOrigin OriginType = "git"
)

// UpdateStrategyType defines the strategy for updating a package from upstream.
type UpdateStrategyType string

// ToUpdateStrategy takes a string representing an update strategy and will
// return the strategy as an UpdateStrategyType. If the provided string does
// not match any known update strategies, an error will be returned.
func ToUpdateStrategy(strategy string) (UpdateStrategyType, error) {
	switch strategy {
	case string(ResourceMerge):
		return ResourceMerge, nil
	case string(FastForward):
		return FastForward, nil
	case string(ForceDeleteReplace):
		return ForceDeleteReplace, nil
	default:
		return "", fmt.Errorf("unknown update strategy %q", strategy)
	}<commit_msg>Add Ignore property to Kptfile (#2148)<commit_after>// Copyright 2021 Google LLC
//
// 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 defines the schema for Kptfile version v1alpha2.
package v1alpha2

import (
	"fmt"

	"sigs.k8s.io/kustomize/kyaml/yaml"
)

const (
	KptFileName       = "Kptfile"
	KptFileKind       = "Kptfile"
	KptFileGroup      = "kpt.dev"
	KptFileVersion    = "v1alpha2"
	KptFileAPIVersion = KptFileGroup + "/" + KptFileVersion
)

// TypeMeta is the TypeMeta for KptFile instances.
var TypeMeta = yaml.ResourceMeta{
	TypeMeta: yaml.TypeMeta{
		APIVersion: KptFileAPIVersion,
		Kind:       KptFileName,
	},
}

// KptFile contains information about a package managed with kpt.
type KptFile struct {
	yaml.ResourceMeta `yaml:",inline"`

	Upstream *Upstream `yaml:"upstream,omitempty"`

	// UpstreamLock is a resolved locator for the last fetch of the package.
	UpstreamLock *UpstreamLock `yaml:"upstreamLock,omitempty"`

	// Info contains metadata such as license, documentation, etc.
	Info *PackageInfo `yaml:"info,omitempty"`

	// Pipeline declares the pipeline of functions.
	Pipeline *Pipeline `yaml:"pipeline,omitempty"`

	// Inventory contains parameters for the inventory object used in apply.
	Inventory *Inventory `yaml:"inventory,omitempty"`

	// Ignore contains a list of .gitignore patterns for files and directories
	// that should be ignored by kpt. Files/directories that match will be
	// fetched and updated as part of the package, but will be ignored by the other
	// kpt functionality. The patterns will only impact resources within the
	// same package, and it is not possible to ignore subpackages.
	//
	// The following patterns are supported:
	// * Absolute path (/path/to/ignore): If the pattern has a leading slash, it will
	//   only match the specific path underneath the package root.
	//   Example: "/ignore.me" will only match the file if it is in the root of
	//   the package.
	// * Relative path (path/to/ignore): If the pattern does not have a leading slash,
	//   it will match at any depth in the package.
	//   Example: "ignore.me" will match all files called "ignore.me" within the
	//   package.
	// * Accept pattern (!path/to/accept): Negate a previous pattern so the path
	//   will be included.
	// * Directory pattern (path/to/directory/): If the pattern has a slash at the
	//   end, it will only match directories.
	// * Glob pattern (path/to/*.txt): * matches all characters except slash.
	//
	// Recursive patterns (path/**/ignore) are not supported.
	Ignore []string `yaml:"ignore,omitempty"`
}

// OriginType defines the type of origin for a package.
type OriginType string

const (
	// GitOrigin specifies a package as having been cloned from a git repository.
	GitOrigin OriginType = "git"
)

// UpdateStrategyType defines the strategy for updating a package from upstream.
type UpdateStrategyType string

// ToUpdateStrategy takes a string representing an update strategy and will
// return the strategy as an UpdateStrategyType. If the provided string does
// not match any known update strategies, an error will be returned.
func ToUpdateStrategy(strategy string) (UpdateStrategyType, error) {
	switch strategy {
	case string(ResourceMerge):
		return ResourceMerge, nil
	case string(FastForward):
		return FastForward, nil
	case string(ForceDeleteReplace):
		return ForceDeleteReplace, nil
	default:
		return "", fmt.Errorf("unknown update strategy %q", strategy)
	}
{'fraction_non_alphanumeric': 0.08583560812860176, 'fraction_numerical': 0.005156202608431908, 'mean_word_length': 3.8851851851851853, 'pattern_counts': {'":': 0, '<': 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': '6519403', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1802, 'n_words': 765}