From 1853b7370b294da1ecd9da04ee053dc9eb74a878 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Tue, 10 Mar 2026 16:50:04 +0100 Subject: [PATCH] fix: webook/discord: omit empty embeds.footer from the payload for Spacebar compatibility (#11588) Fixes #11573 ### Tests for Go changes - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I ran... - [x] `make pr-go` before pushing ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [x] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. *The decision if the pull request will be shown in the release notes is up to the mergers / release team.* The content of the `release-notes/.md` file will serve as the basis for the release notes. If the file does not exist, the title of the pull request will be used instead. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11588 Reviewed-by: Mathieu Fenniak Co-authored-by: oliverpool Co-committed-by: oliverpool --- services/webhook/discord.go | 4 ++-- services/webhook/discord_test.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/services/webhook/discord.go b/services/webhook/discord.go index cdab4d6733..2383a1402b 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -77,7 +77,7 @@ func (discordHandler) UnmarshalForm(bind func(any)) forms.WebhookForm { type ( // DiscordEmbedFooter for Embed Footer Structure. DiscordEmbedFooter struct { - Text string `json:"text,omitempty"` + Text string `json:"text"` } // DiscordEmbedAuthor for Embed Author Structure @@ -99,7 +99,7 @@ type ( Description string `json:"description"` URL string `json:"url"` Color int `json:"color"` - Footer DiscordEmbedFooter `json:"footer"` + Footer *DiscordEmbedFooter `json:"footer,omitempty"` Author DiscordEmbedAuthor `json:"author"` Fields []DiscordEmbedField `json:"fields,omitempty"` } diff --git a/services/webhook/discord_test.go b/services/webhook/discord_test.go index e94486def8..23745b421a 100644 --- a/services/webhook/discord_test.go +++ b/services/webhook/discord_test.go @@ -4,6 +4,8 @@ package webhook import ( + "bytes" + "io" "testing" webhook_model "forgejo.org/models/webhook" @@ -354,8 +356,15 @@ func TestDiscordJSONPayload(t *testing.T) { assert.Equal(t, "https://discord.example.com/", req.URL.String()) assert.Equal(t, "sha256=", req.Header.Get("X-Hub-Signature-256")) assert.Equal(t, "application/json", req.Header.Get("Content-Type")) + + buf, err := io.ReadAll(req.Body) + require.NoError(t, err) + + // https://codeberg.org/forgejo/forgejo/issues/11573 + assert.NotContains(t, string(buf), `"footer":`) + var body DiscordPayload - err = json.NewDecoder(req.Body).Decode(&body) + err = json.NewDecoder(bytes.NewReader(buf)).Decode(&body) require.NoError(t, err) assert.Equal(t, "[`2020558`](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message \\- user1\n[`2020558`](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message \\- user1", body.Embeds[0].Description) }