github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/travis/yaml/git.go (about) 1 // Copyright 2022 Harness, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package yaml 16 17 import "errors" 18 19 type Git struct { 20 Strategy string `yaml:"strategy,omitempty"` // enum: clone, tarball 21 Depth *Depth `yaml:"depth,omitempty"` 22 Quiet bool `yaml:"quiet,omitempty"` 23 Submodules bool `yaml:"submodules,omitempty"` 24 SubmodulesDepth int `yaml:"submodules_depth,omitempty"` 25 LFSSkipSmudge bool `yaml:"lfs_skip_smudge,omitempty"` 26 SparseCheckout string `yaml:"sparse_checkout,omitempty"` 27 Autocrlf string `yaml:"autocrlf,omitempty"` 28 } 29 30 // Depth sets the clone depth. 31 type Depth struct { 32 Value int 33 } 34 35 // UnmarshalYAML implements the unmarshal interface. 36 func (v *Depth) UnmarshalYAML(unmarshal func(interface{}) error) error { 37 var out1 int 38 var out2 bool 39 if err := unmarshal(&out1); err == nil { 40 v.Value = out1 41 return nil 42 } 43 if err := unmarshal(&out2); err == nil { 44 if out2 == true { 45 v.Value = 50 // default depth for travis pipelines 46 } 47 return nil 48 } 49 return errors.New("failed to unmarshal depth") 50 }