mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 05:56:38 +08:00
aa4faddade
Result: {"status":"keep","total_issues":8,"golint_canonicalheader":0,"golint_errname":0,"golint_errorlint":1,"golint_exhaustive":0,"golint_forcetypeassert":0,"golint_gosec":0,"golint_intrange":0,"golint_modernize":3,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":0,"golint_recvcheck":1,"golint_usestdlibvars":0,"golint_wastedassign":0,"golint_total":8,"golint_test_testifylint":0,"golint_test_thelper":0,"golint_test_usetesting":0,"golint_test_total":0,"golint_vetx_total":0,"eslint_problems":0,"eslint_errors":0,"eslint_warnings":0,"tsc_errors":0,"vitest_failed":0,"vitest_total":116,"measure_s":81}
109 lines
2.2 KiB
Go
109 lines
2.2 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package util
|
|
|
|
import "strconv"
|
|
|
|
func compareVersionNumbers(left, right VersionInfo) int {
|
|
maxLen := max(len(right.Numbers), len(left.Numbers))
|
|
for index := range maxLen {
|
|
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 := range maxLen {
|
|
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 := range maxLen {
|
|
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
|
|
}
|