github.com/khulnasoft-lab/gopkg@v0.0.0-20240121181808-81b44d894093/repo/semver.go (about)

     1  package repo
     2  
     3  import (
     4  	"github.com/Khulnasoft-lab/vcs"
     5  )
     6  
     7  // Filter a list of versions to only included semantic versions. The response
     8  // is a mapping of the original version to the semantic version.
     9  func getSemVers(refs []string) []*semver.Version {
    10  	sv := []*semver.Version{}
    11  	for _, r := range refs {
    12  		v, err := semver.NewVersion(r)
    13  		if err == nil {
    14  			sv = append(sv, v)
    15  		}
    16  	}
    17  
    18  	return sv
    19  }
    20  
    21  // Get all the references for a repo. This includes the tags and branches.
    22  func getAllVcsRefs(repo vcs.Repo) ([]string, error) {
    23  	tags, err := repo.Tags()
    24  	if err != nil {
    25  		return []string{}, err
    26  	}
    27  
    28  	branches, err := repo.Branches()
    29  	if err != nil {
    30  		return []string{}, err
    31  	}
    32  
    33  	return append(branches, tags...), nil
    34  }