scm.go 555 B

123456789101112131415161718192021222324252627282930313233343536
  1. package scm
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. type Platform int
  7. const (
  8. NoPlatform Platform = iota
  9. GitHubPlatform
  10. GitLabPlatform
  11. // TODO: Add others.
  12. )
  13. func (p Platform) String() string {
  14. return [...]string{
  15. "none",
  16. "github",
  17. "gitlab",
  18. }[p]
  19. }
  20. func PlatformFromString(s string) (Platform, error) {
  21. switch strings.ToLower(s) {
  22. case "", "none":
  23. return NoPlatform, nil
  24. case "github":
  25. return GitHubPlatform, nil
  26. case "gitlab":
  27. return GitLabPlatform, nil
  28. default:
  29. return NoPlatform, fmt.Errorf("invalid scm platform value: %s", s)
  30. }
  31. }