github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/gitlab/yaml/include.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 ( 18 "errors" 19 ) 20 21 // Include includes external yaml files. 22 // https://docs.gitlab.com/ee/ci/yaml/#include 23 type Include struct { 24 Local string `yaml:"local,omitempty"` 25 Project string `yaml:"project,omitempty"` 26 Ref string `yaml:"ref,omitempty"` 27 Remote string `yaml:"remote,omitempty"` 28 Template string `yaml:"template,omitempty"` 29 File Stringorslice `yaml:"file,omitempty"` 30 } 31 32 // UnmarshalYAML implements the unmarshal interface. 33 func (v *Include) UnmarshalYAML(unmarshal func(interface{}) error) error { 34 var out1 string 35 var out2 = struct { 36 Local string `yaml:"local,omitempty"` 37 Project string `yaml:"project,omitempty"` 38 Ref string `yaml:"ref,omitempty"` 39 Remote string `yaml:"remote,omitempty"` 40 Template string `yaml:"template,omitempty"` 41 File Stringorslice `yaml:"file,omitempty"` 42 }{} 43 44 if err := unmarshal(&out1); err == nil { 45 v.Local = out1 46 return nil 47 } 48 49 if err := unmarshal(&out2); err == nil { 50 v.Local = out2.Local 51 v.Project = out2.Project 52 v.Ref = out2.Ref 53 v.Remote = out2.Remote 54 v.Template = out2.Template 55 v.File = out2.File 56 return nil 57 } 58 59 return errors.New("failed to unmarshal include") 60 }