MCPcopy
hub / github.com/helm/helm / GetTagMatchingVersionOrConstraint

Function GetTagMatchingVersionOrConstraint

pkg/registry/tag.go:25–59  ·  view source on GitHub ↗
(tags []string, versionString string)

Source from the content-addressed store, hash-verified

23)
24
25func GetTagMatchingVersionOrConstraint(tags []string, versionString string) (string, error) {
26 var constraint *semver.Constraints
27 if versionString == "" {
28 // If the string is empty, set a wildcard constraint
29 constraint, _ = semver.NewConstraint("*")
30 } else {
31 // when customer inputs a specific version, check whether there's an exact match first
32 for _, v := range tags {
33 if versionString == v {
34 return v, nil
35 }
36 }
37
38 // Otherwise set constraint to the string given
39 var err error
40 constraint, err = semver.NewConstraint(versionString)
41 if err != nil {
42 return "", err
43 }
44 }
45
46 // Otherwise try to find the first available version matching the string,
47 // in case it is a constraint
48 for _, v := range tags {
49 test, err := semver.NewVersion(v)
50 if err != nil {
51 continue
52 }
53 if constraint.Check(test) {
54 return v, nil
55 }
56 }
57
58 return "", fmt.Errorf("could not locate a version matching provided version string %s", versionString)
59}

Calls 1

CheckMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…