Skip to content

Commit

Permalink
fix: templates in release URLs (#3365)
Browse files Browse the repository at this point in the history
closes #3356

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Sep 11, 2022
1 parent 5185b5b commit 2244bba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
21 changes: 9 additions & 12 deletions internal/pipe/release/scm.go
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
}
12 changes: 12 additions & 0 deletions internal/pipe/release/scm_test.go
Expand Up @@ -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}}",
Expand All @@ -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) {
Expand Down Expand Up @@ -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}}",
Expand All @@ -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) {
Expand Down Expand Up @@ -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}}",
Expand All @@ -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) {
Expand Down

0 comments on commit 2244bba

Please sign in to comment.