mirror of
https://github.com/go-gitea/gitea
synced 2025-02-07 07:14:44 +00:00
Backport #33411 by @lunny Fix #33291 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
6f3837284d
commit
2674d27fb8
@ -43,6 +43,7 @@ func ShowBranchFeed(ctx *context.Context, repo *repo.Repository, formatType stri
|
|||||||
},
|
},
|
||||||
Description: commit.Message(),
|
Description: commit.Message(),
|
||||||
Content: commit.Message(),
|
Content: commit.Message(),
|
||||||
|
Created: commit.Committer.When,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ func ShowFileFeed(ctx *context.Context, repo *repo.Repository, formatType string
|
|||||||
},
|
},
|
||||||
Description: commit.Message(),
|
Description: commit.Message(),
|
||||||
Content: commit.Message(),
|
Content: commit.Message(),
|
||||||
|
Created: commit.Committer.When,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
tests/integration/feed_repo_test.go
Normal file
35
tests/integration/feed_repo_test.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package integration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFeedRepo(t *testing.T) {
|
||||||
|
t.Run("RSS", func(t *testing.T) {
|
||||||
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
|
req := NewRequest(t, "GET", "/user2/repo1.rss")
|
||||||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
data := resp.Body.String()
|
||||||
|
assert.Contains(t, data, `<rss version="2.0"`)
|
||||||
|
|
||||||
|
var rss RSS
|
||||||
|
err := xml.Unmarshal(resp.Body.Bytes(), &rss)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Contains(t, rss.Channel.Link, "/user2/repo1")
|
||||||
|
assert.NotEmpty(t, rss.Channel.PubDate)
|
||||||
|
assert.Len(t, rss.Channel.Items, 1)
|
||||||
|
assert.EqualValues(t, "issue5", rss.Channel.Items[0].Description)
|
||||||
|
assert.NotEmpty(t, rss.Channel.Items[0].PubDate)
|
||||||
|
})
|
||||||
|
}
|
@ -4,6 +4,7 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/xml"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -12,7 +13,23 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFeed(t *testing.T) {
|
// RSS is a struct to unmarshal RSS feeds test only
|
||||||
|
type RSS struct {
|
||||||
|
Channel struct {
|
||||||
|
Title string `xml:"title"`
|
||||||
|
Link string `xml:"link"`
|
||||||
|
Description string `xml:"description"`
|
||||||
|
PubDate string `xml:"pubDate"`
|
||||||
|
Items []struct {
|
||||||
|
Title string `xml:"title"`
|
||||||
|
Link string `xml:"link"`
|
||||||
|
Description string `xml:"description"`
|
||||||
|
PubDate string `xml:"pubDate"`
|
||||||
|
} `xml:"item"`
|
||||||
|
} `xml:"channel"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFeedUser(t *testing.T) {
|
||||||
t.Run("User", func(t *testing.T) {
|
t.Run("User", func(t *testing.T) {
|
||||||
t.Run("Atom", func(t *testing.T) {
|
t.Run("Atom", func(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
@ -32,6 +49,12 @@ func TestFeed(t *testing.T) {
|
|||||||
|
|
||||||
data := resp.Body.String()
|
data := resp.Body.String()
|
||||||
assert.Contains(t, data, `<rss version="2.0"`)
|
assert.Contains(t, data, `<rss version="2.0"`)
|
||||||
|
|
||||||
|
var rss RSS
|
||||||
|
err := xml.Unmarshal(resp.Body.Bytes(), &rss)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Contains(t, rss.Channel.Link, "/user2")
|
||||||
|
assert.NotEmpty(t, rss.Channel.PubDate)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user