Repository: goreleaser/goreleaser
Pull request #1364 (2020-02-26 12:11:40)

fix: infer project name from GitLab/Gitea release
<!--

Hi, thanks for contributing!

Please make sure you read our CONTRIBUTING guide.

Please fill the fields above:

-->

<!-- If applied, this commit will... -->

<!-- Why is this change being made? -->

<!-- # Provide links to any relevant tickets, URLs or other resources -->

When a GitLab release is configured, the project name will default to the repository name, if not set explicitly. This is already the behaviour with GitHub releases.

This should fix https://github.com/goreleaser/goreleaser/issues/1337.

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1364?src=pr&el=h1) Report
> Merging [#1364](https://codecov.io/gh/goreleaser/goreleaser/pull/1364?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/d03c0aa0bea79543b65a6c5e893fa87b2b44f260?src=pr&el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/1364/graphs/tree.svg?width=650&token=3bJvv6b7hN&height=150&src=pr)](https://codecov.io/gh/goreleaser/goreleaser/pull/1364?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master   #1364      +/-   ##
=========================================
+ Coverage   83.89%   83.9%   +0.01%     
=========================================
  Files          57      57              
  Lines        3328    3331       +3     
=========================================
+ Hits         2792    2795       +3     
  Misses        456     456              
  Partials       80      80
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1364?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/pipe/project/project.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1364/diff?src=pr&el=tree#diff-aW50ZXJuYWwvcGlwZS9wcm9qZWN0L3Byb2plY3QuZ28=) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1364?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1364?src=pr&el=footer). Last update [d03c0aa...c49cb44](https://codecov.io/gh/goreleaser/goreleaser/pull/1364?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/internal/pipe/project/project.go b/internal/pipe/project/project.go
index 0c2f1d45..38f9c5e6 100644
--- a/internal/pipe/project/project.go
+++ b/internal/pipe/project/project.go
@@ -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
 }
diff --git a/www/content/project.md b/www/content/project.md
index bd42bc7f..1c55f023 100644
--- a/www/content/project.md
+++ b/www/content/project.md
@@ -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


Test patch:
diff --git a/internal/pipe/project/project_test.go b/internal/pipe/project/project_test.go
index 15b7e55f..25adb7d6 100644
--- a/internal/pipe/project/project_test.go
+++ b/internal/pipe/project/project_test.go
@@ -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{
@@ -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)
+}