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: templates in release URLs #3365

Merged
merged 1 commit into from Sep 11, 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
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