@@ -21,7 +21,6 @@ import (
2121 "sort"
2222 "strings"
2323
24- "github.com/Masterminds/semver/v3"
2524 rclient "github.com/tektoncd/hub/api/v1/gen/http/resource/client"
2625)
2726
@@ -232,8 +231,9 @@ func (t *tektonHubClient) GetResourceVersionslist(r ResourceOption) ([]string, e
232231 for i := range opts .hubResVersions .Versions {
233232 ver = append (ver , * opts .hubResVersions .Versions [i ].Version )
234233 }
234+ sort .Sort (sort .Reverse (sort .StringSlice (ver )))
235235
236- return sortVersionsSemanticaly ( ver ) , nil
236+ return ver , nil
237237}
238238
239239// Endpoint computes the endpoint url using input provided
@@ -484,58 +484,7 @@ func findArtifactHubResourceVersions(data []byte) ([]string, error) {
484484 for _ , r := range resp .AvailableVersions {
485485 versions = append (versions , r .Version )
486486 }
487+ sort .Sort (sort .Reverse (sort .StringSlice (versions )))
487488
488- return sortVersionsSemanticaly (versions ), nil
489- }
490-
491- // sortVersionsSemanticaly sorts version strings using semantic versioning rules
492- // Returns versions in descending order (latest first), preserving original format
493- func sortVersionsSemanticaly (versions []string ) []string {
494- if len (versions ) <= 1 {
495- return versions
496- }
497-
498- // Create a struct to hold both original string and parsed version
499- type versionPair struct {
500- original string
501- semver * semver.Version
502- }
503-
504- var validVersions []versionPair
505- var invalidVersions []string
506-
507- // Parse versions, keeping original strings and invalid ones separate
508- for _ , v := range versions {
509- // Try to parse as semantic version
510- version , err := semver .NewVersion (v )
511- if err != nil {
512- // If it's not a valid semver, keep it as string for fallback sorting
513- invalidVersions = append (invalidVersions , v )
514- } else {
515- validVersions = append (validVersions , versionPair {
516- original : v ,
517- semver : version ,
518- })
519- }
520- }
521-
522- // Sort valid versions by their semver objects in descending order (latest first)
523- sort .Slice (validVersions , func (i , j int ) bool {
524- return validVersions [i ].semver .GreaterThan (validVersions [j ].semver )
525- })
526-
527- // Sort invalid versions alphabetically in descending order as fallback
528- sort .Sort (sort .Reverse (sort .StringSlice (invalidVersions )))
529-
530- // Convert back to original strings and combine results
531- var result []string
532-
533- // Add properly sorted semantic versions first (in original format)
534- for _ , vp := range validVersions {
535- result = append (result , vp .original )
536- }
537-
538- result = append (result , invalidVersions ... )
539-
540- return result
489+ return versions , nil
541490}
0 commit comments