Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion internal/latestrelease/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,29 @@ func VersionFromTag(ver string) string {
return ver
}

// isValidTagForTool reports whether a release tag belongs to MongoCLI and
// carries a valid version. It accepts both the legacy "mongocli/vX.Y.Z" tags
// and the new bare "vX.Y.Z" tags, while rejecting tags for other tools such as
// "atlascli/vX.Y.Z" (which exist in this repo from before it was renamed to
// mongodb-atlas-cli).
func isValidTagForTool(tag string) bool {
return !strings.Contains(tag, "atlascli")
switch {
case strings.HasPrefix(tag, config.MongoCLI+"/"):
// Legacy format: mongocli/vX.Y.Z
return isVersionTag(VersionFromTag(tag))
case strings.Contains(tag, "/"):
// Another tool's tag, e.g. atlascli/vX.Y.Z
return false
default:
// New format: vX.Y.Z. The "v" prefix is required so unrelated tags
// (e.g. a bare "2024") are not coerced into a version.
return strings.HasPrefix(tag, "v") && isVersionTag(tag)
}
}

func isVersionTag(tag string) bool {
_, err := semver.NewVersion(tag)
return err == nil
}

func (f *finder) loadOrGet() (*ReleaseInformation, *semver.Version, error) {
Expand Down
14 changes: 13 additions & 1 deletion internal/latestrelease/finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,21 @@ func TestOutputOpts_testIsValidTag(t *testing.T) {
tag string
isValid bool
}{
{"atlascli/v1.0.0", false},
// Legacy format.
{"mongocli/v1.0.0", true},
{"mongocli/v2.0.9", true},
{"mongocli/v1.0.0-rc0", true},
// New bare format.
{"v1.0.0", true},
{"v2.3.4", true},
// Other tools' tags. atlascli tags exist in this repo from before it
// was renamed to mongodb-atlas-cli, so they must never match.
{"atlascli/v1.0.0", false},
{"atlascli/v1.59.0", false},
// Tags that do not carry a version.
{"nightly", false},
{"mongocli/nightly", false},
{"2024", false},
}

for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion internal/version/release_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type releaseVersionFetcher struct {

const (
owner = "mongodb"
project = "mongodb-atlas-cli"
project = "mongodb-cli"
)

// LatestWithCriteria retrieves the first release version that matches the criteria. We assume that ListReleases returns releases sorted by created_at value.
Expand Down
Loading