github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/travis/yaml/addons_sonarcloud.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 Sonarcloud struct { 20 Enabled bool `yaml:"enabled,omitempty"` 21 Organization string `yaml:"organization,omitempty"` 22 Token *Secure `yaml:"token,omitempty"` 23 GithubToken *Secure `yaml:"github_token,omitempty"` 24 Branches []string `yaml:"branches,omitempty"` 25 } 26 27 // UnmarshalYAML implements the unmarshal interface. 28 func (v *Sonarcloud) UnmarshalYAML(unmarshal func(interface{}) error) error { 29 var out1 bool 30 var out2 = struct { 31 Enabled *bool `yaml:"enabled"` 32 Organization string `yaml:"organization"` 33 Token *Secure `yaml:"token"` 34 GithubToken *Secure `yaml:"github_token"` 35 Branches Stringorslice `yaml:"branches"` 36 }{} 37 if err := unmarshal(&out1); err == nil { 38 v.Enabled = out1 39 return nil 40 } 41 if err := unmarshal(&out2); err == nil { 42 v.Enabled = true 43 if out2.Enabled != nil { 44 v.Enabled = *out2.Enabled 45 } 46 v.Organization = out2.Organization 47 v.Token = out2.Token 48 v.GithubToken = out2.GithubToken 49 v.Branches = out2.Branches 50 return nil 51 } 52 return errors.New("failed to unmarshal sonarcloud") 53 }