Skip to content

Commit

Permalink
fix: decouple project_name guessing from the release pipe
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Sep 29, 2023
1 parent b7218b0 commit 5acd57e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/pipe/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"
"strings"

"github.com/goreleaser/goreleaser/internal/git"
"github.com/goreleaser/goreleaser/pkg/context"
)

Expand All @@ -27,6 +28,7 @@ func (Pipe) Default(ctx *context.Context) error {
ctx.Config.Release.GitLab.Name,
ctx.Config.Release.Gitea.Name,
moduleName(),
gitRemote(ctx),
} {
if candidate == "" {
continue
Expand Down Expand Up @@ -55,3 +57,14 @@ func moduleName() string {
parts := strings.Split(mod, "/")
return strings.TrimSpace(parts[len(parts)-1])
}

func gitRemote(ctx *context.Context) string {
repo, err := git.ExtractRepoFromConfig(ctx)
if err != nil {
return ""
}
if err := repo.CheckSCM(); err != nil {
return ""
}
return repo.Name
}
17 changes: 17 additions & 0 deletions internal/pipe/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ func TestEmptyProjectName_DefaultsToGoModPath(t *testing.T) {
require.Equal(t, "bar", ctx.Config.ProjectName)
}

func TestEmptyProjectName_DefaultsToGitURL(t *testing.T) {
_ = testlib.Mktmp(t)
ctx := testctx.New()
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "bar", ctx.Config.ProjectName)
}

func TestEmptyProjectName_DefaultsToNonSCMGitURL(t *testing.T) {
_ = testlib.Mktmp(t)
ctx := testctx.New()
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "git@myhost.local:bar.git")
require.EqualError(t, Pipe{}.Default(ctx), "couldn't guess project_name, please add it to your config")
}

func TestEmptyProjectNameAndRelease(t *testing.T) {
_ = testlib.Mktmp(t)
ctx := testctx.NewWithCfg(config.Project{
Expand Down

0 comments on commit 5acd57e

Please sign in to comment.