Skip to content

Commit

Permalink
Add VcsProvider marshal yaml.
Browse files Browse the repository at this point in the history
  • Loading branch information
gailazar300 committed Jul 17, 2024
1 parent 8b10260 commit 25ca006
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions vcsutils/consts.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package vcsutils

import (
"fmt"
"strings"
)

const (
branchPrefix = "refs/heads/"
TagPrefix = "refs/tags/"
Expand All @@ -23,6 +28,38 @@ const (
AzureRepos
)

func (v *VcsProvider) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
}

switch strings.ToLower(s) {
case "github":
*v = GitHub
case "gitlab":
*v = GitLab
case "bitbucket":
*v = BitbucketServer
default:
return fmt.Errorf("invalid VcsProvider: %s", s)
}
return nil
}

func (v VcsProvider) MarshalYAML() (interface{}, error) {
switch v {
case GitHub:
return "github", nil
case GitLab:
return "gitlab", nil
case BitbucketServer:
return "bitbucket", nil
default:
return nil, fmt.Errorf("invalid VcsProvider: %d", v)
}
}

// String representation of the VcsProvider
func (v VcsProvider) String() string {
switch v {
Expand Down

0 comments on commit 25ca006

Please sign in to comment.