package release import ( "fmt" "gopkg.in/yaml.v3" ) type Repo interface { String() string Registry() string Name() string } type Repository struct { Repo } func (rr *Repository) UnmarshalYAML(rootNode *yaml.Node) error { gcpRep := &GCPRepository{} gcpRepErr := rootNode.Decode(gcpRep) if gcpRepErr == nil { rr.Repo = gcpRep return nil } rawRep := &RawRepository{} rawRepErr := rootNode.Decode(rawRep) if rawRepErr == nil { rr.Repo = rawRep return nil } return fmt.Errorf("could not unmarshal ReleaseRepository") } type GCPRepository struct { Location string `yaml:"location"` Project string `yaml:"project"` RepoName string `yaml:"name"` } func (gcpr GCPRepository) String() string { return fmt.Sprintf("%s-docker.pkg.dev/%s/%s", gcpr.Location, gcpr.Project, gcpr.Name()) } func (gcpr GCPRepository) Name() string { return gcpr.RepoName } func (gcpr GCPRepository) Registry() string { return fmt.Sprintf("%s-docker.pkg.dev/%s", gcpr.Location, gcpr.Project) } type RawRepository struct { RawRegistry string `yaml:"registry"` RepoName string `yaml:"repo"` } func (rr RawRepository) String() string { return fmt.Sprintf("%s/%s", rr.Registry(), rr.Name()) } func (rr RawRepository) Registry() string { return rr.RawRegistry } func (rr RawRepository) Name() string { return rr.RepoName }