Skip to content

Commit

Permalink
api documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ptgoetz committed Nov 10, 2024
1 parent c647419 commit dd961ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/semver/prerelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

// PreReleaseVersion is similar to Version, but its string representation is reduced by removing trailing ".0"
// All PreReleaseVersion instances have an associated `label`.
type PreReleaseVersion struct {
version *Version
label string
Expand Down Expand Up @@ -86,10 +87,12 @@ func parsePrereleaseVersion(versionStr string) (*PreReleaseVersion, error) {
return newPrereleaseVersion(label, major, minor, patch), nil
}

// Label returns the pre-release label
func (v *PreReleaseVersion) Label() string {
return v.label
}

// Version returns the pre-release Version
func (v *PreReleaseVersion) Version() Version {
return *v.version
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/semver/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,29 @@ func versionPartInt(part VersionPart) int {
}
}

// SemanticVersion represents a parsed and validated semantic version
type SemanticVersion struct {
rootVersion *Version
preReleaseVersion *PreReleaseVersion
buildVersion *BuildVersion
}

// RootVersion returns the root version part of the SemanticVersion
func (v *SemanticVersion) RootVersion() Version {
return *v.rootVersion
}

// PreReleaseVersion returns the pre-release version part of the SemanticVersion
func (v *SemanticVersion) PreReleaseVersion() PreReleaseVersion {
return *v.preReleaseVersion
}

// BuildVersion returns the BuildVersion part of the SemanticVersion
func (v *SemanticVersion) BuildVersion() BuildVersion {
return *v.buildVersion
}

// String returns the rootVersion string
// String returns the string representation of the SemanticVersion instance
func (v *SemanticVersion) String() string {
if v == nil {
return ""
Expand Down Expand Up @@ -252,6 +256,7 @@ func ValidatePreReleaseLabelsString(preReleaseLabels string) bool {
return ValidatePreReleaseLabels(labels)
}

// SortVersions sorts a slice of SemanticVersion instances in descending order (latest to oldest)
func SortVersions(versions []*SemanticVersion) {
sort.Slice(versions, func(i, j int) bool {
return versions[i].Compare(versions[j]) > 0
Expand Down

0 comments on commit dd961ea

Please sign in to comment.