mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-12 22:10:25 +00:00
[v14.0/forgejo] fix: webook/discord: omit empty embeds.footer from the payload for Spacebar compatibility (#11613)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/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/<pull request number>.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. Co-authored-by: oliverpool <git@olivier.pfad.fr> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11613 Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
parent
71df8827a9
commit
021d8b198f
2 changed files with 12 additions and 3 deletions
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue