Skip to content
Permalink
Browse files
fix: move mastodon server to yaml (#3568)
refs #3567

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Nov 17, 2022
1 parent fe24ee6 commit ab08d0b7063ecc0cfca4aa9fb51f0553c42ae482
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
@@ -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,
@@ -36,22 +36,33 @@ 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) {
t.Run("skip", func(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))
})))
})
}
@@ -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 {
@@ -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

0 comments on commit ab08d0b

Please sign in to comment.