From 2244bba1e0f39839a7ea0ca47440f29eef3d1061 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 11 Sep 2022 14:28:50 -0300 Subject: [PATCH] fix: templates in release URLs (#3365) closes #3356 Signed-off-by: Carlos A Becker --- internal/pipe/release/scm.go | 21 +++++++++------------ internal/pipe/release/scm_test.go | 12 ++++++++++++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/internal/pipe/release/scm.go b/internal/pipe/release/scm.go index c2c4f7940d9..1397d505ffb 100644 --- a/internal/pipe/release/scm.go +++ b/internal/pipe/release/scm.go @@ -28,15 +28,14 @@ func setupGitHub(ctx *context.Context) error { } ctx.Config.Release.GitHub.Name = name - ctx.ReleaseURL = fmt.Sprintf( + ctx.ReleaseURL, err = tmpl.New(ctx).Apply(fmt.Sprintf( "%s/%s/%s/releases/tag/%s", ctx.Config.GitHubURLs.Download, ctx.Config.Release.GitHub.Owner, ctx.Config.Release.GitHub.Name, ctx.Git.CurrentTag, - ) - - return nil + )) + return err } func setupGitLab(ctx *context.Context) error { @@ -60,15 +59,14 @@ func setupGitLab(ctx *context.Context) error { } ctx.Config.Release.GitLab.Name = name - ctx.ReleaseURL = fmt.Sprintf( + ctx.ReleaseURL, err = tmpl.New(ctx).Apply(fmt.Sprintf( "%s/%s/%s/-/releases/%s", ctx.Config.GitLabURLs.Download, ctx.Config.Release.GitLab.Owner, ctx.Config.Release.GitLab.Name, ctx.Git.CurrentTag, - ) - - return nil + )) + return err } func setupGitea(ctx *context.Context) error { @@ -92,13 +90,12 @@ func setupGitea(ctx *context.Context) error { } ctx.Config.Release.Gitea.Name = name - ctx.ReleaseURL = fmt.Sprintf( + ctx.ReleaseURL, err = tmpl.New(ctx).Apply(fmt.Sprintf( "%s/%s/%s/releases/tag/%s", ctx.Config.GiteaURLs.Download, ctx.Config.Release.Gitea.Owner, ctx.Config.Release.Gitea.Name, ctx.Git.CurrentTag, - ) - - return nil + )) + return err } diff --git a/internal/pipe/release/scm_test.go b/internal/pipe/release/scm_test.go index 8e6598f4f4e..d9ad912d312 100644 --- a/internal/pipe/release/scm_test.go +++ b/internal/pipe/release/scm_test.go @@ -20,6 +20,9 @@ func TestSetupGitLab(t *testing.T) { t.Run("with templates", func(t *testing.T) { ctx := context.New(config.Project{ Env: []string{"NAME=foo", "OWNER=bar"}, + GitLabURLs: config.GitLabURLs{ + Download: "https://{{ .Env.OWNER }}/download", + }, Release: config.Release{ GitLab: config.Repo{ Owner: "{{.Env.OWNER}}", @@ -31,6 +34,7 @@ func TestSetupGitLab(t *testing.T) { require.NoError(t, setupGitLab(ctx)) require.Equal(t, "bar", ctx.Config.Release.GitLab.Owner) require.Equal(t, "foo", ctx.Config.Release.GitLab.Name) + require.Equal(t, "https://bar/download/bar/foo/-/releases/", ctx.ReleaseURL) }) t.Run("with invalid templates", func(t *testing.T) { @@ -73,6 +77,9 @@ func TestSetupGitea(t *testing.T) { t.Run("with templates", func(t *testing.T) { ctx := context.New(config.Project{ Env: []string{"NAME=foo", "OWNER=bar"}, + GiteaURLs: config.GiteaURLs{ + Download: "https://{{ .Env.OWNER }}/download", + }, Release: config.Release{ Gitea: config.Repo{ Owner: "{{.Env.OWNER}}", @@ -84,6 +91,7 @@ func TestSetupGitea(t *testing.T) { require.NoError(t, setupGitea(ctx)) require.Equal(t, "bar", ctx.Config.Release.Gitea.Owner) require.Equal(t, "foo", ctx.Config.Release.Gitea.Name) + require.Equal(t, "https://bar/download/bar/foo/releases/tag/", ctx.ReleaseURL) }) t.Run("with invalid templates", func(t *testing.T) { @@ -126,6 +134,9 @@ func TestSetupGitHub(t *testing.T) { t.Run("with templates", func(t *testing.T) { ctx := context.New(config.Project{ Env: []string{"NAME=foo", "OWNER=bar"}, + GitHubURLs: config.GitHubURLs{ + Download: "https://{{ .Env.OWNER }}/download", + }, Release: config.Release{ GitHub: config.Repo{ Owner: "{{.Env.OWNER}}", @@ -137,6 +148,7 @@ func TestSetupGitHub(t *testing.T) { require.NoError(t, setupGitHub(ctx)) require.Equal(t, "bar", ctx.Config.Release.GitHub.Owner) require.Equal(t, "foo", ctx.Config.Release.GitHub.Name) + require.Equal(t, "https://bar/download/bar/foo/releases/tag/", ctx.ReleaseURL) }) t.Run("with invalid templates", func(t *testing.T) {