Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move mastodon server to yaml #3568

Merged
merged 1 commit into from Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions internal/pipe/mastodon/mastodon.go
Expand Up @@ -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"`
Expand All @@ -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,
Expand Down
19 changes: 15 additions & 4 deletions internal/pipe/mastodon/mastodon_test.go
Expand Up @@ -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))
})))
})
}
1 change: 1 addition & 0 deletions pkg/config/config.go
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion 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`
Expand All @@ -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
Expand Down