mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-01 13:07:49 +02:00
fix: move mastodon server to yaml (#3568)
refs #3567 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
fe24ee6741
commit
ab08d0b706
@ -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,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("dont skip", func(t *testing.T) {
|
||||
ctx := 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
|
||||
},
|
||||
},
|
||||
})
|
||||
require.False(t, Pipe{}.Skip(ctx))
|
||||
})))
|
||||
})
|
||||
|
||||
t.Run("dont skip", func(t *testing.T) {
|
||||
require.False(t, Pipe{}.Skip(context.New(config.Project{
|
||||
Announce: config.Announce{
|
||||
Mastodon: config.Mastodon{
|
||||
Enabled: true,
|
||||
Server: "https://mastodon.social",
|
||||
},
|
||||
},
|
||||
})))
|
||||
})
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user