mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-28 05:46:36 +08:00
b76f707c8b
Result: {"status":"keep","total_issues":74,"golint_canonicalheader":8,"golint_errname":1,"golint_errorlint":12,"golint_forcetypeassert":3,"golint_gosec":0,"golint_intrange":3,"golint_modernize":5,"golint_nilnil":3,"golint_perfsprint":18,"golint_prealloc":3,"golint_recvcheck":7,"golint_usestdlibvars":3,"golint_wastedassign":7,"golint_total":73,"eslint_problems":1,"eslint_errors":0,"eslint_warnings":1,"tsc_errors":0,"measure_s":38}
106 lines
2.2 KiB
Go
106 lines
2.2 KiB
Go
package util
|
|
|
|
import "strconv"
|
|
|
|
func compareVersionNumbers(left, right VersionInfo) int {
|
|
maxLen := max(len(right.Numbers), len(left.Numbers))
|
|
for index := 0; index < maxLen; index++ {
|
|
leftValue := 0
|
|
rightValue := 0
|
|
if index < len(left.Numbers) {
|
|
leftValue = left.Numbers[index]
|
|
}
|
|
if index < len(right.Numbers) {
|
|
rightValue = right.Numbers[index]
|
|
}
|
|
if leftValue < rightValue {
|
|
return -1
|
|
}
|
|
if leftValue > rightValue {
|
|
return 1
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func compareGitDescribeDistance(left, right VersionInfo) int {
|
|
if left.GitDescribeDistance == right.GitDescribeDistance {
|
|
return 0
|
|
}
|
|
if left.GitDescribeDistance < right.GitDescribeDistance {
|
|
return -1
|
|
}
|
|
return 1
|
|
}
|
|
|
|
func compareGitDescribeTails(left, right VersionInfo) int {
|
|
maxLen := max(len(right.GitDescribeTail), len(left.GitDescribeTail))
|
|
for index := 0; index < maxLen; index++ {
|
|
if index >= len(left.GitDescribeTail) {
|
|
return -1
|
|
}
|
|
if index >= len(right.GitDescribeTail) {
|
|
return 1
|
|
}
|
|
if left.GitDescribeTail[index] < right.GitDescribeTail[index] {
|
|
return -1
|
|
}
|
|
if left.GitDescribeTail[index] > right.GitDescribeTail[index] {
|
|
return 1
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func comparePrereleaseIdentifiers(left, right VersionInfo) int {
|
|
if len(left.Prerelease) == 0 && len(right.Prerelease) == 0 {
|
|
return 0
|
|
}
|
|
if len(left.Prerelease) == 0 {
|
|
return 1
|
|
}
|
|
if len(right.Prerelease) == 0 {
|
|
return -1
|
|
}
|
|
|
|
maxLen := max(len(right.Prerelease), len(left.Prerelease))
|
|
for index := 0; index < maxLen; index++ {
|
|
if index >= len(left.Prerelease) {
|
|
return -1
|
|
}
|
|
if index >= len(right.Prerelease) {
|
|
return 1
|
|
}
|
|
if result := comparePrereleasePart(left.Prerelease[index], right.Prerelease[index]); result != 0 {
|
|
return result
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func comparePrereleasePart(leftPart, rightPart string) int {
|
|
leftNumber, leftErr := strconv.Atoi(leftPart)
|
|
rightNumber, rightErr := strconv.Atoi(rightPart)
|
|
switch {
|
|
case leftErr == nil && rightErr == nil:
|
|
if leftNumber < rightNumber {
|
|
return -1
|
|
}
|
|
if leftNumber > rightNumber {
|
|
return 1
|
|
}
|
|
case leftErr == nil:
|
|
return -1
|
|
case rightErr == nil:
|
|
return 1
|
|
default:
|
|
if leftPart < rightPart {
|
|
return -1
|
|
}
|
|
if leftPart > rightPart {
|
|
return 1
|
|
}
|
|
}
|
|
return 0
|
|
}
|