From 9f77d5ec118882d01b6d1fefe7ae843ae43f45d3 Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario <653394+eapolinario@users.noreply.github.com> Date: Tue, 15 Feb 2022 18:01:53 -0800 Subject: [PATCH] Use GetLatestRelease to list latest non-pre-release flytesnacks version #minor (#279) * Use GetLatestRelease to list latest non-pre-release flytesnacks version Signed-off-by: Eduardo Apolinario * Use GetLatestVersion Signed-off-by: Eduardo Apolinario * Move GetLatestVersion to its original place Signed-off-by: Eduardo Apolinario Co-authored-by: Eduardo Apolinario --- flytectl/cmd/register/register_util.go | 13 ++----------- flytectl/pkg/util/githubutil/githubutil.go | 3 ++- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/flytectl/cmd/register/register_util.go b/flytectl/cmd/register/register_util.go index 29e83c698d2..c94c990ee2c 100644 --- a/flytectl/cmd/register/register_util.go +++ b/flytectl/cmd/register/register_util.go @@ -561,20 +561,11 @@ func getAllExample(repository, version string) ([]*github.ReleaseAsset, *github. } return filterExampleFromRelease(release), release, nil } - releases, err := githubutil.GetListRelease(repository) + release, err := githubutil.GetLatestVersion(repository) if err != nil { return nil, nil, err } - if len(releases) == 0 { - return nil, nil, fmt.Errorf("repository doesn't have any release") - } - for _, v := range releases { - if !*v.Prerelease { - return filterExampleFromRelease(v), v, nil - } - } - return nil, nil, nil - + return filterExampleFromRelease(release), release, nil } func getRemoteStoragePath(ctx context.Context, s *storage.DataStore, remoteLocation, file, identifier string) (storage.DataReference, error) { diff --git a/flytectl/pkg/util/githubutil/githubutil.go b/flytectl/pkg/util/githubutil/githubutil.go index 075b1cc8df2..257eaad970b 100644 --- a/flytectl/pkg/util/githubutil/githubutil.go +++ b/flytectl/pkg/util/githubutil/githubutil.go @@ -65,7 +65,8 @@ func GetGHClient() *github.Client { return github.NewClient(&http.Client{}) } -// GetLatestVersion returns the latest version of provided repository +// GetLatestVersion returns the latest non-prerelease version of provided repository, as +// described in https://docs.github.com/en/rest/reference/releases#get-the-latest-release func GetLatestVersion(repository string) (*github.RepositoryRelease, error) { client := GetGHClient() release, _, err := client.Repositories.GetLatestRelease(context.Background(), owner, repository)