Skip to content

Commit

Permalink
fix: infer project name from GitLab/Gitea release (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfurman committed Feb 26, 2020
1 parent d03c0aa commit 61fb8f5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
9 changes: 8 additions & 1 deletion internal/pipe/project/project.go
Expand Up @@ -13,7 +13,14 @@ func (Pipe) String() string {
// Default set project defaults
func (Pipe) Default(ctx *context.Context) error {
if ctx.Config.ProjectName == "" {
ctx.Config.ProjectName = ctx.Config.Release.GitHub.Name
switch {
case ctx.Config.Release.GitHub.Name != "":
ctx.Config.ProjectName = ctx.Config.Release.GitHub.Name
case ctx.Config.Release.GitLab.Name != "":
ctx.Config.ProjectName = ctx.Config.Release.GitLab.Name
case ctx.Config.Release.Gitea.Name != "":
ctx.Config.ProjectName = ctx.Config.Release.Gitea.Name
}
}
return nil
}
28 changes: 27 additions & 1 deletion internal/pipe/project/project_test.go
Expand Up @@ -23,7 +23,7 @@ func TestCustomProjectName(t *testing.T) {
require.Equal(t, "foo", ctx.Config.ProjectName)
}

func TestEmptyProjectName(t *testing.T) {
func TestEmptyProjectName_DefaultsToGitHubRelease(t *testing.T) {
var ctx = context.New(config.Project{
Release: config.Release{
GitHub: config.Repo{
Expand All @@ -35,3 +35,29 @@ func TestEmptyProjectName(t *testing.T) {
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "bar", ctx.Config.ProjectName)
}

func TestEmptyProjectName_DefaultsToGitLabRelease(t *testing.T) {
var ctx = context.New(config.Project{
Release: config.Release{
GitLab: config.Repo{
Owner: "bar",
Name: "bar",
},
},
})
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "bar", ctx.Config.ProjectName)
}

func TestEmptyProjectName_DefaultsToGiteaRelease(t *testing.T) {
var ctx = context.New(config.Project{
Release: config.Release{
Gitea: config.Repo{
Owner: "bar",
Name: "bar",
},
},
})
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "bar", ctx.Config.ProjectName)
}
3 changes: 2 additions & 1 deletion www/content/project.md
Expand Up @@ -6,7 +6,8 @@ weight: 10
---

The project name is used in the name of the Brew formula, archives, etc.
If none is given, it will be inferred from the name of the Git project.
If none is given, it will be inferred from the name of the GitHub, GitLab, or
Gitea release.

```yaml
# .goreleaser.yml
Expand Down

0 comments on commit 61fb8f5

Please sign in to comment.