Skip to content

Commit 6f97d5d

Browse files
lunnyearl-warren
authored andcommitted
Add pubdate for repository rss and add some tests (go-gitea#33411)
Fix go-gitea#33291 (cherry picked from commit dcd3014) Conflicts: tests/integration/feed_user_test.go trivial context conflict
1 parent 6bd9867 commit 6f97d5d

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

routers/web/feed/branch.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func ShowBranchFeed(ctx *context.Context, repo *repo.Repository, formatType stri
4343
},
4444
Description: commit.Message(),
4545
Content: commit.Message(),
46+
Created: commit.Committer.When,
4647
})
4748
}
4849

routers/web/feed/file.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func ShowFileFeed(ctx *context.Context, repo *repo.Repository, formatType string
5555
},
5656
Description: commit.Message(),
5757
Content: commit.Message(),
58+
Created: commit.Committer.When,
5859
})
5960
}
6061

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package integration
5+
6+
import (
7+
"encoding/xml"
8+
"net/http"
9+
"testing"
10+
11+
"code.gitea.io/gitea/tests"
12+
13+
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
15+
)
16+
17+
func TestFeedRepo(t *testing.T) {
18+
t.Run("RSS", func(t *testing.T) {
19+
defer tests.PrepareTestEnv(t)()
20+
21+
req := NewRequest(t, "GET", "/user2/repo1.rss")
22+
resp := MakeRequest(t, req, http.StatusOK)
23+
24+
data := resp.Body.String()
25+
assert.Contains(t, data, `<rss version="2.0"`)
26+
27+
var rss RSS
28+
err := xml.Unmarshal(resp.Body.Bytes(), &rss)
29+
require.NoError(t, err)
30+
assert.Contains(t, rss.Channel.Link, "/user2/repo1")
31+
assert.NotEmpty(t, rss.Channel.PubDate)
32+
assert.Len(t, rss.Channel.Items, 1)
33+
assert.EqualValues(t, "issue5", rss.Channel.Items[0].Description)
34+
assert.NotEmpty(t, rss.Channel.Items[0].PubDate)
35+
})
36+
}

tests/integration/api_feed_user_test.go renamed to tests/integration/feed_user_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package integration
55

66
import (
7+
"encoding/xml"
78
"net/http"
89
"testing"
910

@@ -15,6 +16,22 @@ import (
1516
"github.com/stretchr/testify/require"
1617
)
1718

19+
// RSS is a struct to unmarshal RSS feeds test only
20+
type RSS struct {
21+
Channel struct {
22+
Title string `xml:"title"`
23+
Link string `xml:"link"`
24+
Description string `xml:"description"`
25+
PubDate string `xml:"pubDate"`
26+
Items []struct {
27+
Title string `xml:"title"`
28+
Link string `xml:"link"`
29+
Description string `xml:"description"`
30+
PubDate string `xml:"pubDate"`
31+
} `xml:"item"`
32+
} `xml:"channel"`
33+
}
34+
1835
func TestFeed(t *testing.T) {
1936
defer tests.AddFixtures("tests/integration/fixtures/TestFeed/")()
2037
defer tests.PrepareTestEnv(t)()
@@ -38,6 +55,12 @@ func TestFeed(t *testing.T) {
3855

3956
data := resp.Body.String()
4057
assert.Contains(t, data, `<rss version="2.0"`)
58+
59+
var rss RSS
60+
err := xml.Unmarshal(resp.Body.Bytes(), &rss)
61+
require.NoError(t, err)
62+
assert.Contains(t, rss.Channel.Link, "/user2")
63+
assert.NotEmpty(t, rss.Channel.PubDate)
4164
})
4265
})
4366

0 commit comments

Comments
 (0)