github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/travis/yaml/addons_coverity.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 Coverity struct {
    20  	Enabled             bool             `yaml:"enabled,omitempty"`
    21  	Project             *CoverityProject `yaml:"project,omitempty"`
    22  	BuildScriptURL      string           `yaml:"build_script_url,omitempty"`
    23  	BranchPattern       string           `yaml:"branch_pattern,omitempty"`
    24  	NotificationEmail   *Secure          `yaml:"notification_email,omitempty"`
    25  	BuildCommand        string           `yaml:"build_command,omitempty"`
    26  	BuildCommandPrepend string           `yaml:"build_command_prepend,omitempty"`
    27  }
    28  
    29  // UnmarshalYAML implements the unmarshal interface.
    30  func (v *Coverity) UnmarshalYAML(unmarshal func(interface{}) error) error {
    31  	var out1 bool
    32  	var out2 = struct {
    33  		Enabled             *bool            `yaml:"enabled"`
    34  		Project             *CoverityProject `yaml:"project,omitempty"`
    35  		BuildScriptURL      string           `yaml:"build_script_url,omitempty"`
    36  		BranchPattern       string           `yaml:"branch_pattern,omitempty"`
    37  		NotificationEmail   *Secure          `yaml:"notification_email,omitempty"`
    38  		BuildCommand        string           `yaml:"build_command,omitempty"`
    39  		BuildCommandPrepend string           `yaml:"build_command_prepend,omitempty"`
    40  	}{}
    41  	if err := unmarshal(&out1); err == nil {
    42  		v.Enabled = out1
    43  		return nil
    44  	}
    45  	if err := unmarshal(&out2); err == nil {
    46  		v.Enabled = true
    47  		if out2.Enabled != nil {
    48  			v.Enabled = *out2.Enabled
    49  		}
    50  		v.Project = out2.Project
    51  		v.BuildScriptURL = out2.BuildScriptURL
    52  		v.BranchPattern = out2.BranchPattern
    53  		v.NotificationEmail = out2.NotificationEmail
    54  		v.BuildCommand = out2.BuildCommand
    55  		v.BuildCommandPrepend = out2.BuildCommandPrepend
    56  		return nil
    57  	}
    58  	return errors.New("failed to unmarshal coverity_scan")
    59  }
    60  
    61  type CoverityProject struct {
    62  	Name        string `yaml:"name,omitempty"`
    63  	Version     string `yaml:"version,omitempty"`
    64  	Description string `yaml:"description,omitempty"`
    65  }
    66  
    67  // UnmarshalYAML implements the unmarshal interface.
    68  func (v *CoverityProject) UnmarshalYAML(unmarshal func(interface{}) error) error {
    69  	var out1 string
    70  	var out2 = struct {
    71  		Name        string `yaml:"name,omitempty"`
    72  		Version     string `yaml:"version,omitempty"`
    73  		Description string `yaml:"description,omitempty"`
    74  	}{}
    75  	if err := unmarshal(&out1); err == nil {
    76  		v.Name = out1
    77  		return nil
    78  	}
    79  	if err := unmarshal(&out2); err == nil {
    80  		v.Name = out2.Name
    81  		v.Version = out2.Version
    82  		v.Description = out2.Description
    83  		return nil
    84  	}
    85  	return errors.New("failed to unmarshal coverity project")
    86  }