mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-08 03:31:59 +02:00
a6e6e7098d
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package linkedin
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/caarlos0/env/v9"
|
|
"github.com/caarlos0/log"
|
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
)
|
|
|
|
const defaultMessageTemplate = `{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}`
|
|
|
|
type Pipe struct{}
|
|
|
|
func (Pipe) String() string { return "linkedin" }
|
|
func (Pipe) Skip(ctx *context.Context) bool { return !ctx.Config.Announce.LinkedIn.Enabled }
|
|
|
|
type Config struct {
|
|
AccessToken string `env:"LINKEDIN_ACCESS_TOKEN,notEmpty"`
|
|
}
|
|
|
|
func (Pipe) Default(ctx *context.Context) error {
|
|
if ctx.Config.Announce.LinkedIn.MessageTemplate == "" {
|
|
ctx.Config.Announce.LinkedIn.MessageTemplate = defaultMessageTemplate
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (Pipe) Announce(ctx *context.Context) error {
|
|
message, err := tmpl.New(ctx).Apply(ctx.Config.Announce.LinkedIn.MessageTemplate)
|
|
if err != nil {
|
|
return fmt.Errorf("linkedin: %w", err)
|
|
}
|
|
|
|
var cfg Config
|
|
if err := env.Parse(&cfg); err != nil {
|
|
return fmt.Errorf("linkedin: %w", err)
|
|
}
|
|
|
|
c, err := createLinkedInClient(oauthClientConfig{
|
|
Context: ctx,
|
|
AccessToken: cfg.AccessToken,
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("linkedin: %w", err)
|
|
}
|
|
|
|
url, err := c.Share(message)
|
|
if err != nil {
|
|
return fmt.Errorf("linkedin: %w", err)
|
|
}
|
|
|
|
log.Infof("The text post is available at: %s\n", url)
|
|
|
|
return nil
|
|
}
|