MM-17888 Check plugin Helpers minimum server version comments (#12663)
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
7cc1f19453
Коммит
7d0d7c304e
80
plugin/checker/internal/version/version.go
Обычный файл
80
plugin/checker/internal/version/version.go
Обычный файл
@@ -0,0 +1,80 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package version
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type V string
|
||||
|
||||
func (v V) GreaterThanOrEqualTo(other V) bool {
|
||||
return !v.LessThan(other)
|
||||
}
|
||||
|
||||
func (v V) LessThan(other V) bool {
|
||||
leftParts, leftCount := split(v)
|
||||
rightParts, rightCount := split(other)
|
||||
|
||||
var length int
|
||||
if leftCount < rightCount {
|
||||
length = rightCount
|
||||
} else {
|
||||
length = leftCount
|
||||
}
|
||||
|
||||
for i := 0; i < length; i++ {
|
||||
var left, right string
|
||||
|
||||
if i < leftCount {
|
||||
left = leftParts[i]
|
||||
}
|
||||
|
||||
if i < rightCount {
|
||||
right = rightParts[i]
|
||||
}
|
||||
|
||||
if left == right {
|
||||
continue
|
||||
}
|
||||
|
||||
leftInt := parseInt(left)
|
||||
rightInt := parseInt(right)
|
||||
|
||||
isNumericalComparison := leftInt != nil && rightInt != nil
|
||||
|
||||
if isNumericalComparison {
|
||||
return *leftInt < *rightInt
|
||||
}
|
||||
|
||||
return left < right
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func split(v V) ([]string, int) {
|
||||
var chunks []string
|
||||
|
||||
for _, part := range strings.Split(string(v), ".") {
|
||||
chunks = append(chunks, splitNumericalChunks(part)...)
|
||||
}
|
||||
|
||||
return chunks, len(chunks)
|
||||
}
|
||||
|
||||
var numericalOrAlphaRE = regexp.MustCompile(`(\d+|\D+)`)
|
||||
|
||||
func splitNumericalChunks(s string) []string {
|
||||
return numericalOrAlphaRE.FindAllString(s, -1)
|
||||
}
|
||||
|
||||
func parseInt(s string) *int64 {
|
||||
if n, err := strconv.ParseInt(s, 10, 64); err == nil {
|
||||
return &n
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Ссылка в новой задаче
Block a user