Skip to content

Commit

Permalink
fix: remove disgo dependency
Browse files Browse the repository at this point in the history
closes #4520
  • Loading branch information
caarlos0 committed Jan 5, 2024
1 parent 0becc41 commit be7b89e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
4 changes: 0 additions & 4 deletions go.mod
Expand Up @@ -20,8 +20,6 @@ require (
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589
github.com/dghubble/go-twitter v0.0.0-20211115160449-93a8679adecb
github.com/dghubble/oauth1 v0.7.2
github.com/disgoorg/disgo v0.17.0
github.com/disgoorg/snowflake/v2 v2.0.1
github.com/distribution/distribution/v3 v3.0.0-20221021092657-c47a966fded8
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
github.com/google/go-containerregistry v0.17.0
Expand Down Expand Up @@ -142,7 +140,6 @@ require (
github.com/davidmz/go-pageant v1.0.2 // indirect
github.com/dghubble/sling v1.4.0 // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/disgoorg/json v1.1.0 // indirect
github.com/docker/cli v24.0.7+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v24.0.7+incompatible // indirect
Expand Down Expand Up @@ -227,7 +224,6 @@ require (
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.4.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sigstore/cosign/v2 v2.2.1 // indirect
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Expand Up @@ -278,12 +278,6 @@ github.com/dghubble/sling v1.4.0 h1:/n8MRosVTthvMbwlNZgLx579OGVjUOy3GNEv5BIqAWY=
github.com/dghubble/sling v1.4.0/go.mod h1:0r40aNsU9EdDUVBNhfCstAtFgutjgJGYbO1oNzkMoM8=
github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U=
github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE=
github.com/disgoorg/disgo v0.17.0 h1:/LcgXgPDhzHt3GkQ4cpjmIJBim1/VYfS31VhGYif3Ms=
github.com/disgoorg/disgo v0.17.0/go.mod h1:AE2J/8oLR2PtYfqcARsk1mgBxQ5z3Z1OD6Lc2SA0gak=
github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=
github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0=
github.com/disgoorg/snowflake/v2 v2.0.1/go.mod h1:SPU9c2CNn5DSyb86QcKtdZgix9osEtKrHLW4rMhfLCs=
github.com/distribution/distribution/v3 v3.0.0-20221021092657-c47a966fded8 h1:zuxvqNfQKyGNH3a1yFh1ofD4Y7ycgdwQhHX6QRH+Cwo=
github.com/distribution/distribution/v3 v3.0.0-20221021092657-c47a966fded8/go.mod h1:6rIc5NMSjXjjnwzWWy3HAm9gDBu+X7aCzL8VrHIKgxM=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
Expand Down Expand Up @@ -759,8 +753,6 @@ github.com/sagikazarmark/locafero v0.3.0 h1:zT7VEGWC2DTflmccN/5T1etyKvxSxpHsjb9c
github.com/sagikazarmark/locafero v0.3.0/go.mod h1:w+v7UsPNFwzF1cHuOajOOzoq4U7v/ig1mpRjqV+Bu1U=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b h1:qYTY2tN72LhgDj2rtWG+LI6TXFl2ygFQQ4YezfVaGQE=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg=
github.com/secure-systems-lab/go-securesystemslib v0.7.0 h1:OwvJ5jQf9LnIAS83waAjPbcMsODrTQUpJ02eNLUoxBg=
github.com/secure-systems-lab/go-securesystemslib v0.7.0/go.mod h1:/2gYnlnHVQ6xeGtfIqFy7Do03K4cdCY0A/GlJLDKLHI=
Expand Down
47 changes: 38 additions & 9 deletions internal/pipe/discord/discord.go
@@ -1,14 +1,15 @@
package discord

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"

"github.com/caarlos0/env/v9"
"github.com/caarlos0/log"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/webhook"
"github.com/disgoorg/snowflake/v2"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/context"
)
Expand Down Expand Up @@ -59,28 +60,56 @@ func (p Pipe) Announce(ctx *context.Context) error {

log.Infof("posting: '%s'", msg)

webhookID, err := snowflake.Parse(cfg.WebhookID)
color, err := strconv.Atoi(ctx.Config.Announce.Discord.Color)

Check warning on line 63 in internal/pipe/discord/discord.go

View check run for this annotation

Codecov / codecov/patch

internal/pipe/discord/discord.go#L63

Added line #L63 was not covered by tests
if err != nil {
return fmt.Errorf("discord: %w", err)
}

color, err := strconv.Atoi(ctx.Config.Announce.Discord.Color)
u, err := url.Parse("https://discord.com/api")

Check warning on line 68 in internal/pipe/discord/discord.go

View check run for this annotation

Codecov / codecov/patch

internal/pipe/discord/discord.go#L68

Added line #L68 was not covered by tests
if err != nil {
return fmt.Errorf("discord: %w", err)
}
if _, err = webhook.New(webhookID, cfg.WebhookToken).CreateMessage(discord.WebhookMessageCreate{
Embeds: []discord.Embed{
u = u.JoinPath("webhooks", cfg.WebhookID, cfg.WebhookToken)

bts, err := json.Marshal(WebhookMessageCreate{
Embeds: []Embed{

Check warning on line 75 in internal/pipe/discord/discord.go

View check run for this annotation

Codecov / codecov/patch

internal/pipe/discord/discord.go#L72-L75

Added lines #L72 - L75 were not covered by tests
{
Author: &discord.EmbedAuthor{
Author: &EmbedAuthor{

Check warning on line 77 in internal/pipe/discord/discord.go

View check run for this annotation

Codecov / codecov/patch

internal/pipe/discord/discord.go#L77

Added line #L77 was not covered by tests
Name: ctx.Config.Announce.Discord.Author,
IconURL: ctx.Config.Announce.Discord.IconURL,
},
Description: msg,
Color: color,
},
},
}); err != nil {
})
if err != nil {

Check warning on line 86 in internal/pipe/discord/discord.go

View check run for this annotation

Codecov / codecov/patch

internal/pipe/discord/discord.go#L85-L86

Added lines #L85 - L86 were not covered by tests
return fmt.Errorf("discord: %w", err)
}

resp, err := http.Post(u.String(), "application/json", bytes.NewReader(bts))
if err != nil {
return fmt.Errorf("discord: %w", err)
}

Check warning on line 93 in internal/pipe/discord/discord.go

View check run for this annotation

Codecov / codecov/patch

internal/pipe/discord/discord.go#L90-L93

Added lines #L90 - L93 were not covered by tests

if resp.StatusCode != 204 && resp.StatusCode != 200 {
return fmt.Errorf("discord: %s", resp.Status)
}

Check warning on line 97 in internal/pipe/discord/discord.go

View check run for this annotation

Codecov / codecov/patch

internal/pipe/discord/discord.go#L95-L97

Added lines #L95 - L97 were not covered by tests

return nil
}

type WebhookMessageCreate struct {
Embeds []Embed `json:"embeds,omitempty"`
}

type Embed struct {
Description string `json:"description,omitempty"`
Color int `json:"color,omitempty"`
Author *EmbedAuthor `json:"author,omitempty"`
}

type EmbedAuthor struct {
Name string `json:"name,omitempty"`
IconURL string `json:"icon_url,omitempty"`
}

0 comments on commit be7b89e

Please sign in to comment.