diff --git a/internal/pipe/mastodon/mastodon.go b/internal/pipe/mastodon/mastodon.go index 6654926be92..9d80a7214db 100644 --- a/internal/pipe/mastodon/mastodon.go +++ b/internal/pipe/mastodon/mastodon.go @@ -14,11 +14,13 @@ const defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it o type Pipe struct{} -func (Pipe) String() string { return "mastodon" } -func (Pipe) Skip(ctx *context.Context) bool { return !ctx.Config.Announce.Mastodon.Enabled } +func (Pipe) String() string { return "mastodon" } + +func (Pipe) Skip(ctx *context.Context) bool { + return !ctx.Config.Announce.Mastodon.Enabled || ctx.Config.Announce.Mastodon.Server == "" +} type Config struct { - Server string `env:"MASTODON_SERVER,notEmpty"` ClientID string `env:"MASTODON_CLIENT_ID,notEmpty"` ClientSecret string `env:"MASTODON_CLIENT_SECRET,notEmpty"` AccessToken string `env:"MASTODON_ACCESS_TOKEN,notEmpty"` @@ -43,7 +45,7 @@ func (Pipe) Announce(ctx *context.Context) error { } client := mastodon.NewClient(&mastodon.Config{ - Server: cfg.Server, + Server: ctx.Config.Announce.Mastodon.Server, ClientID: cfg.ClientID, ClientSecret: cfg.ClientSecret, AccessToken: cfg.AccessToken, diff --git a/internal/pipe/mastodon/mastodon_test.go b/internal/pipe/mastodon/mastodon_test.go index bb0d475eb9a..f2472ff5dab 100644 --- a/internal/pipe/mastodon/mastodon_test.go +++ b/internal/pipe/mastodon/mastodon_test.go @@ -36,7 +36,7 @@ func TestAnnounceMissingEnv(t *testing.T) { }, }) require.NoError(t, Pipe{}.Default(ctx)) - require.EqualError(t, Pipe{}.Announce(ctx), `announce: failed to announce to mastodon: env: environment variable "MASTODON_SERVER" should not be empty; environment variable "MASTODON_CLIENT_ID" should not be empty; environment variable "MASTODON_CLIENT_SECRET" should not be empty; environment variable "MASTODON_ACCESS_TOKEN" should not be empty`) + require.EqualError(t, Pipe{}.Announce(ctx), `announce: failed to announce to mastodon: env: environment variable "MASTODON_CLIENT_ID" should not be empty; environment variable "MASTODON_CLIENT_SECRET" should not be empty; environment variable "MASTODON_ACCESS_TOKEN" should not be empty`) } func TestSkip(t *testing.T) { @@ -44,14 +44,25 @@ func TestSkip(t *testing.T) { require.True(t, Pipe{}.Skip(context.New(config.Project{}))) }) + t.Run("skip empty server", func(t *testing.T) { + require.True(t, Pipe{}.Skip(context.New(config.Project{ + Announce: config.Announce{ + Mastodon: config.Mastodon{ + Enabled: true, + Server: "", // empty + }, + }, + }))) + }) + t.Run("dont skip", func(t *testing.T) { - ctx := context.New(config.Project{ + require.False(t, Pipe{}.Skip(context.New(config.Project{ Announce: config.Announce{ Mastodon: config.Mastodon{ Enabled: true, + Server: "https://mastodon.social", }, }, - }) - require.False(t, Pipe{}.Skip(ctx)) + }))) }) } diff --git a/pkg/config/config.go b/pkg/config/config.go index da27d237923..95ceaf8d32e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -986,6 +986,7 @@ type Twitter struct { type Mastodon struct { Enabled bool `yaml:"enabled,omitempty" json:"enabled,omitempty"` MessageTemplate string `yaml:"message_template,omitempty" json:"message_template,omitempty"` + Server string `yaml:"server" json:"server"` } type Reddit struct { diff --git a/www/docs/customization/announce/mastodon.md b/www/docs/customization/announce/mastodon.md index 8dac32e58ab..9bc76a9c80e 100644 --- a/www/docs/customization/announce/mastodon.md +++ b/www/docs/customization/announce/mastodon.md @@ -1,9 +1,10 @@ # Mastodon +> Since: v1.13.0 + For it to work, you'll need to create a new Mastodon app `https://social.yourdomain.tld/settings/applications/new`, and set some environment variables on your pipeline: -- `MASTODON_SERVER` - `MASTODON_CLIENT_ID` - `MASTODON_CLIENT_SECRET` - `MASTODON_ACCESS_TOKEN` @@ -21,6 +22,10 @@ announce: # Message template to use while publishing. # Defaults to `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}` message_template: 'Awesome project {{.Tag}} is out!' + + # Mastodon server URL. + # Defaults to empty. + server: https://mastodon.social ``` !!! tip