MCPcopy Create free account
hub / github.com/gogs/gogs / Compare

Function Compare

internal/semverutil/semverutil.go:13–33  ·  view source on GitHub ↗

Compare returns true if the comparison is true for given versions. It returns false if comparison is false, or failed to parse one or both versions as Semantic Versions. See https://github.com/Masterminds/semver#basic-comparisons for supported comparisons.

(version1, comparison, version2 string)

Source from the content-addressed store, hash-verified

11//
12// See https://github.com/Masterminds/semver#basic-comparisons for supported comparisons.
13func Compare(version1, comparison, version2 string) bool {
14 clean := func(v string) string {
15 if strings.Count(v, ".") > 2 {
16 fields := strings.SplitN(v, ".", 4)
17 v = strings.Join(fields[:3], ".")
18 }
19 return v
20 }
21
22 v, err := semver.NewVersion(clean(version1))
23 if err != nil {
24 return false
25 }
26
27 c, err := semver.NewConstraint(comparison + " " + clean(version2))
28 if err != nil {
29 return false
30 }
31
32 return c.Check(v)
33}

Callers 4

InitFunction · 0.92
NewRepoContextFunction · 0.92
runRestoreFunction · 0.92
TestCheckFunction · 0.85

Calls 1

CountMethod · 0.45

Tested by 1

TestCheckFunction · 0.68