Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YAML marshalling functionality to VcsProvider #138

Merged
merged 2 commits into from
Jul 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading