Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove a patch number from the recommendation link #2891

Merged
merged 3 commits into from Sep 16, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/commands/artifact/run.go
Expand Up @@ -3,6 +3,7 @@ package artifact
import (
"context"
"errors"
"fmt"
"os"

"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -564,7 +565,6 @@ func canonicalVersion(ver string) string {
if v.IsPreRelease() || v.Metadata() != "" {
return devVersion
}

// Add "v" prefix, "0.34.0" => "v0.34.0" for the url
return "v" + ver
// Add "v" prefix and cut a patch number, "0.34.0" => "v0.34" for the url
return fmt.Sprintf("v%d.%d", v.Major(), v.Minor())
}
48 changes: 48 additions & 0 deletions pkg/commands/artifact/run_test.go
@@ -0,0 +1,48 @@
package artifact

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestCanonicalVersion(t *testing.T) {
tests := []struct {
title string
input string
want string
}{
{
title: "good way",
input: "0.34.0",
want: "v0.34",
},
{
title: "version with v - isn't right semver version",
input: "v0.34.0",
want: devVersion,
},
{
title: "dev version",
input: devVersion,
want: devVersion,
},
{
title: "pre-release",
input: "v0.34.0-beta1+snapshot-1",
want: devVersion,
},
{
title: "no version",
input: "",
want: devVersion,
},
}

for _, test := range tests {
t.Run(test.title, func(t *testing.T) {
got := canonicalVersion(test.input)
require.Equal(t, test.want, got)
})
}
}