stability.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package version
  2. import (
  3. "regexp"
  4. "strings"
  5. )
  6. const (
  7. Development = iota
  8. Alpha
  9. Beta
  10. RC
  11. Stable
  12. )
  13. func expandStability(stability string) string {
  14. stability = strings.ToLower(stability)
  15. switch stability {
  16. case "a":
  17. return "alpha"
  18. case "b":
  19. return "beta"
  20. case "p":
  21. return "patch"
  22. case "pl":
  23. return "patch"
  24. case "rc":
  25. return "RC"
  26. }
  27. return stability
  28. }
  29. func parseStability(version string) string {
  30. version = regexp.MustCompile(`(?i)#.+$`).ReplaceAllString(version, " ")
  31. version = strings.ToLower(version)
  32. if strings.HasPrefix(version, "dev-") || strings.HasSuffix(version, "-dev") {
  33. return "dev"
  34. }
  35. result := RegFind(`(?i)^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?`+modifierRegex+`$`, version)
  36. if result != nil {
  37. if len(result) > 3 {
  38. return "dev"
  39. }
  40. }
  41. if result[1] != "" {
  42. if "beta" == result[1] || "b" == result[1] {
  43. return "beta"
  44. }
  45. if "alpha" == result[1] || "a" == result[1] {
  46. return "alpha"
  47. }
  48. if "rc" == result[1] {
  49. return "RC"
  50. }
  51. }
  52. return "stable"
  53. }
  54. func GetStability(version string) int {
  55. result := RegFind(`(?i)(stable|RC|beta|alpha|dev)`, Normalize(version))
  56. if len(result) == 0 {
  57. return Stable
  58. }
  59. switch result[1] {
  60. case "dev":
  61. return Development
  62. case "alpha":
  63. return Alpha
  64. case "beta":
  65. return Beta
  66. case "RC":
  67. return RC
  68. }
  69. return Stable
  70. }