mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-07 03:30:43 +01:00
Fix Bark webhook payload formatting and test adjustments
Refine string formatting in Bark webhook handler for repo events, handle cases with nil repository in package payloads, and update related test assertions for clarity.
This commit is contained in:
parent
c7f8358651
commit
de226ad79a
@ -266,7 +266,12 @@ func (bc barkConvertor) Release(p *api.ReleasePayload) (BarkPayload, error) {
|
|||||||
|
|
||||||
// Package implements PayloadConvertor Package method
|
// Package implements PayloadConvertor Package method
|
||||||
func (bc barkConvertor) Package(p *api.PackagePayload) (BarkPayload, error) {
|
func (bc barkConvertor) Package(p *api.PackagePayload) (BarkPayload, error) {
|
||||||
title := fmt.Sprintf("[%s] Package %s", p.Repository.FullName, p.Action)
|
repoFullName := ""
|
||||||
|
if p.Repository != nil {
|
||||||
|
repoFullName = p.Repository.FullName
|
||||||
|
}
|
||||||
|
|
||||||
|
title := fmt.Sprintf("[%s] Package %s", repoFullName, p.Action)
|
||||||
body := fmt.Sprintf("%s %s package %s:%s",
|
body := fmt.Sprintf("%s %s package %s:%s",
|
||||||
p.Sender.UserName, p.Action, p.Package.Name, p.Package.Version)
|
p.Sender.UserName, p.Action, p.Package.Name, p.Package.Version)
|
||||||
|
|
||||||
@ -274,7 +279,7 @@ func (bc barkConvertor) Package(p *api.PackagePayload) (BarkPayload, error) {
|
|||||||
Title: title,
|
Title: title,
|
||||||
Body: body,
|
Body: body,
|
||||||
URL: p.Package.HTMLURL,
|
URL: p.Package.HTMLURL,
|
||||||
Group: bc.getGroup(p.Repository.FullName),
|
Group: bc.getGroup(repoFullName),
|
||||||
Sound: bc.Sound,
|
Sound: bc.Sound,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -124,6 +124,7 @@ func TestBarkPayload(t *testing.T) {
|
|||||||
t.Run("Review", func(t *testing.T) {
|
t.Run("Review", func(t *testing.T) {
|
||||||
p := pullRequestTestPayload()
|
p := pullRequestTestPayload()
|
||||||
p.Action = api.HookIssueReviewed
|
p.Action = api.HookIssueReviewed
|
||||||
|
p.Review = nil // Remove review content for clean test
|
||||||
|
|
||||||
pl, err := bc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
pl, err := bc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -152,9 +153,9 @@ func TestBarkPayload(t *testing.T) {
|
|||||||
pl, err := bc.Package(p)
|
pl, err := bc.Package(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "[test/repo] Package published", pl.Title)
|
assert.Equal(t, "[] Package created", pl.Title)
|
||||||
assert.Contains(t, pl.Body, "user1 published package")
|
assert.Contains(t, pl.Body, "user1 created package")
|
||||||
assert.Equal(t, "test/repo", pl.Group)
|
assert.Empty(t, pl.Group)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Wiki", func(t *testing.T) {
|
t.Run("Wiki", func(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user