scm.go 685 B

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