1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/pipe/release/scm.go
Carlos Alexandro Becker f3d2864db3
refactor: improve releases/scm.go a bit (#4334)
use `ApplyAll`

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2023-09-29 13:37:43 -03:00

90 lines
1.8 KiB
Go

package release
import (
"fmt"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/context"
)
func setupGitHub(ctx *context.Context) error {
if ctx.Config.Release.GitHub.Name == "" {
repo, err := getRepository(ctx)
if err != nil && !ctx.Snapshot {
return err
}
ctx.Config.Release.GitHub = repo
}
if err := tmpl.New(ctx).ApplyAll(
&ctx.Config.Release.GitHub.Name,
&ctx.Config.Release.GitHub.Owner,
); err != nil {
return err
}
url, 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,
))
ctx.ReleaseURL = url
return err
}
func setupGitLab(ctx *context.Context) error {
if ctx.Config.Release.GitLab.Name == "" {
repo, err := getRepository(ctx)
if err != nil {
return err
}
ctx.Config.Release.GitLab = repo
}
if err := tmpl.New(ctx).ApplyAll(
&ctx.Config.Release.GitLab.Name,
&ctx.Config.Release.GitLab.Owner,
); err != nil {
return err
}
url, 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,
))
ctx.ReleaseURL = url
return err
}
func setupGitea(ctx *context.Context) error {
if ctx.Config.Release.Gitea.Name == "" {
repo, err := getRepository(ctx)
if err != nil {
return err
}
ctx.Config.Release.Gitea = repo
}
if err := tmpl.New(ctx).ApplyAll(
&ctx.Config.Release.Gitea.Name,
&ctx.Config.Release.Gitea.Owner,
); err != nil {
return err
}
url, 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,
))
ctx.ReleaseURL = url
return err
}