// Copyright 2020 The Gogs Authors. All rights reserved.// Use of this source code is governed by a MIT-style// license that can be found in the LICENSE file.packagesemverutilimport("strings""github.com/Masterminds/semver/v3")// 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.funcCompare(version1,comparison,version2string)bool{clean:=func(vstring)string{ifstrings.Count(v,".")>2{fields:=strings.SplitN(v,".",4)v=strings.Join(fields[:3],".")}returnv}v,err:=semver.NewVersion(clean(version1))iferr!=nil{returnfalse}c,err:=semver.NewConstraint(comparison+" "+clean(version2))iferr!=nil{returnfalse}returnc.Check(v)}