diff --git a/internal/pipe/discord/discord.go b/internal/pipe/discord/discord.go index 5d2e1884f..1959535e7 100644 --- a/internal/pipe/discord/discord.go +++ b/internal/pipe/discord/discord.go @@ -16,7 +16,7 @@ const ( defaultAuthor = `GoReleaser` defaultColor = "3888754" defaultIcon = "https://goreleaser.com/static/avatar.png" - defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` + defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` ) type Pipe struct{} diff --git a/internal/pipe/mattermost/mattermost.go b/internal/pipe/mattermost/mattermost.go index 1a722aa78..4d9671c61 100644 --- a/internal/pipe/mattermost/mattermost.go +++ b/internal/pipe/mattermost/mattermost.go @@ -18,7 +18,7 @@ import ( const ( defaultColor = "#2D313E" defaultUsername = `GoReleaser` - defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` + defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` defaultMessageTitle = `{{ .ProjectName }} {{ .Tag }} is out!` ) diff --git a/internal/pipe/reddit/reddit.go b/internal/pipe/reddit/reddit.go index 8d95d3924..4cea61c10 100644 --- a/internal/pipe/reddit/reddit.go +++ b/internal/pipe/reddit/reddit.go @@ -12,7 +12,7 @@ import ( const ( defaultTitleTemplate = `{{ .ProjectName }} {{ .Tag }} is out!` - defaultURLTemplate = `{{ .GitURL }}/releases/tag/{{ .Tag }}` + defaultURLTemplate = `{{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` ) type Pipe struct{} diff --git a/internal/pipe/slack/slack.go b/internal/pipe/slack/slack.go index 4cf9e397e..190750012 100644 --- a/internal/pipe/slack/slack.go +++ b/internal/pipe/slack/slack.go @@ -12,7 +12,7 @@ import ( const ( defaultUsername = `GoReleaser` - defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` + defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` ) type Pipe struct{} diff --git a/internal/pipe/smtp/smtp.go b/internal/pipe/smtp/smtp.go index e31f378a7..7b2a426e5 100644 --- a/internal/pipe/smtp/smtp.go +++ b/internal/pipe/smtp/smtp.go @@ -13,7 +13,7 @@ import ( const ( defaultSubjectTemplate = `{{ .ProjectName }} {{ .Tag }} is out!` - defaultBodyTemplate = `You can view details from: {{ .GitURL }}/releases/tag/{{ .Tag }}` + defaultBodyTemplate = `You can view details from: {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` ) type Pipe struct{} diff --git a/internal/pipe/teams/teams.go b/internal/pipe/teams/teams.go index 039adb536..9fee248b5 100644 --- a/internal/pipe/teams/teams.go +++ b/internal/pipe/teams/teams.go @@ -13,7 +13,7 @@ import ( const ( defaultColor = "#2D313E" defaultIcon = "https://goreleaser.com/static/avatar.png" - defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` + defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` defaultMessageTitle = `{{ .ProjectName }} {{ .Tag }} is out!` ) diff --git a/internal/pipe/telegram/telegram.go b/internal/pipe/telegram/telegram.go index 9f9065955..8e9849242 100644 --- a/internal/pipe/telegram/telegram.go +++ b/internal/pipe/telegram/telegram.go @@ -10,7 +10,7 @@ import ( "github.com/goreleaser/goreleaser/pkg/context" ) -const defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` +const defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` type Pipe struct{} diff --git a/internal/pipe/twitter/twitter.go b/internal/pipe/twitter/twitter.go index 4528c6fdf..0dbf17348 100644 --- a/internal/pipe/twitter/twitter.go +++ b/internal/pipe/twitter/twitter.go @@ -11,7 +11,7 @@ import ( "github.com/goreleaser/goreleaser/pkg/context" ) -const defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` +const defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` type Pipe struct{} diff --git a/internal/tmpl/tmpl.go b/internal/tmpl/tmpl.go index d29eaa243..287f73d8b 100644 --- a/internal/tmpl/tmpl.go +++ b/internal/tmpl/tmpl.go @@ -169,6 +169,7 @@ func (t *Template) Apply(s string) (string, error) { "toupper": strings.ToUpper, "trim": strings.TrimSpace, "trimprefix": strings.TrimPrefix, + "trimsuffix": strings.TrimSuffix, "dir": filepath.Dir, "abs": filepath.Abs, "incmajor": incMajor, diff --git a/internal/tmpl/tmpl_test.go b/internal/tmpl/tmpl_test.go index b698e832c..8f27c1bcb 100644 --- a/internal/tmpl/tmpl_test.go +++ b/internal/tmpl/tmpl_test.go @@ -155,6 +155,7 @@ func TestFuncMap(t *testing.T) { wd, err := os.Getwd() require.NoError(t, err) + ctx.Git.URL = "https://github.com/foo/bar.git" ctx.Git.CurrentTag = "v1.2.4" for _, tc := range []struct { Template string @@ -198,6 +199,11 @@ func TestFuncMap(t *testing.T) { Name: "trimprefix", Expected: "1.2.4", }, + { + Template: `{{ trimsuffix .GitURL ".git" }}`, + Name: "trimsuffix", + Expected: "https://github.com/foo/bar", + }, { Template: `{{ toupper "test" }}`, Name: "toupper", diff --git a/www/docs/customization/announce/discord.md b/www/docs/customization/announce/discord.md index f55dff7f7..ea5c96c76 100644 --- a/www/docs/customization/announce/discord.md +++ b/www/docs/customization/announce/discord.md @@ -18,7 +18,7 @@ announce: enabled: true # Message template to use while publishing. - # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` + # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` message_template: 'Awesome project {{.Tag}} is out!' # Set author of the embed. diff --git a/www/docs/customization/announce/index.md b/www/docs/customization/announce/index.md index 478d604ae..9a36429dc 100644 --- a/www/docs/customization/announce/index.md +++ b/www/docs/customization/announce/index.md @@ -4,6 +4,8 @@ GoReleaser can also announce new releases on social networks, chat rooms and via It runs at the very end of the pipeline and can be skipped with the `--skip-announce` flag of the [`release`](/cmd/goreleaser_release/) command, or via the skip property: +By default, ".git" suffix is removing from `{{ .GitURL }}` variable like this `{{ trimsuffix .GitURL ".git" }}`. + ```yaml # .goreleaser.yml announce: diff --git a/www/docs/customization/announce/mattermost.md b/www/docs/customization/announce/mattermost.md index e906ef769..127d35558 100644 --- a/www/docs/customization/announce/mattermost.md +++ b/www/docs/customization/announce/mattermost.md @@ -20,7 +20,7 @@ announce: title_template: 'GoReleaser {{ .Tag }} was just released!' # Message template to use while publishing. - # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` + # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` message_template: 'Awesome project {{.Tag}} is out!' # Color code of the message. You have to use hexadecimal. diff --git a/www/docs/customization/announce/reddit.md b/www/docs/customization/announce/reddit.md index aa2d77212..481b4413a 100644 --- a/www/docs/customization/announce/reddit.md +++ b/www/docs/customization/announce/reddit.md @@ -23,7 +23,7 @@ announce: username: "" # URL template to use while publishing. - # Defaults to `{{ .GitURL }}/releases/tag/{{ .Tag }}` + # Defaults to `{{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` url_template: 'https://github.com/goreleaser/goreleaser/releases/tag/{{ .Tag }}' # Title template to use while publishing. diff --git a/www/docs/customization/announce/slack.md b/www/docs/customization/announce/slack.md index f4936752a..e26ca8435 100644 --- a/www/docs/customization/announce/slack.md +++ b/www/docs/customization/announce/slack.md @@ -16,7 +16,7 @@ announce: enabled: true # Message template to use while publishing. - # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` + # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` message_template: 'Awesome project {{.Tag}} is out!' # The name of the channel that the user selected as a destination for webhook messages. diff --git a/www/docs/customization/announce/smtp.md b/www/docs/customization/announce/smtp.md index 8d558688e..4f012152c 100644 --- a/www/docs/customization/announce/smtp.md +++ b/www/docs/customization/announce/smtp.md @@ -32,7 +32,7 @@ announce: username: "" # Body template to use within the email. - # Defaults to `You can view details from: {{ .GitURL }}/releases/tag/{{ .Tag }}` + # Defaults to `You can view details from: {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` body_template: 'https://github.com/goreleaser/goreleaser/releases/tag/{{ .Tag }}' # Subject template to use within the email subject. diff --git a/www/docs/customization/announce/teams.md b/www/docs/customization/announce/teams.md index 103c67f35..30edb3098 100644 --- a/www/docs/customization/announce/teams.md +++ b/www/docs/customization/announce/teams.md @@ -21,7 +21,7 @@ announce: title_template: 'GoReleaser {{ .Tag }} was just released!' # Message template to use while publishing. - # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` + # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` message_template: 'Awesome project {{.Tag}} is out!' # Color code of the message. You have to use hexadecimal. diff --git a/www/docs/customization/announce/telegram.md b/www/docs/customization/announce/telegram.md index 9f8b5802f..7789b49fc 100644 --- a/www/docs/customization/announce/telegram.md +++ b/www/docs/customization/announce/telegram.md @@ -21,7 +21,7 @@ announce: chat_id: 123456 # Message template to use while publishing. - # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` + # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` message_template: 'Awesome project {{.Tag}} is out!' ``` diff --git a/www/docs/customization/announce/twitter.md b/www/docs/customization/announce/twitter.md index eafc66a45..99a7ee191 100644 --- a/www/docs/customization/announce/twitter.md +++ b/www/docs/customization/announce/twitter.md @@ -19,7 +19,7 @@ announce: enabled: true # Message template to use while publishing. - # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL }}/releases/tag/{{ .Tag }}` + # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ trimsuffix .GitURL ".git" }}/releases/tag/{{ .Tag }}` message_template: 'Awesome project {{.Tag}} is out!' ``` diff --git a/www/docs/customization/templates.md b/www/docs/customization/templates.md index a8f29c950..d095a4858 100644 --- a/www/docs/customization/templates.md +++ b/www/docs/customization/templates.md @@ -68,6 +68,7 @@ On all fields, you have these available functions: | `toupper "v1.2"` | makes input string uppercase. See [ToUpper](https://golang.org/pkg/strings/#ToUpper) | | `trim " v1.2 "` | removes all leading and trailing white space. See [TrimSpace](https://golang.org/pkg/strings/#TrimSpace) | | `trimprefix "v1.2" "v"` | removes provided leading prefix string, if present. See [TrimPrefix](https://golang.org/pkg/strings/#TrimPrefix) | +| `trimsuffix "1.2v" "v"` | removes provided trailing suffix string, if present. See [TrimSuffix](https://pkg.go.dev/strings#TrimSuffix) | | `dir .Path` | returns all but the last element of path, typically the path's directory. See [Dir](https://golang.org/pkg/path/filepath/#Dir) | | `abs .ArtifactPath` | returns an absolute representation of path. See [Abs](https://golang.org/pkg/path/filepath/#Abs) |