From e50a07eb055486028372ac52198296dd8bb43b6e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 26 Jan 2025 19:59:38 -0800 Subject: [PATCH 1/2] Add pubdate for repository rss and add some tests --- routers/web/feed/branch.go | 1 + routers/web/feed/file.go | 1 + tests/integration/feed_repo_test.go | 35 +++++++++++++++++++ ...pi_feed_user_test.go => feed_user_test.go} | 25 ++++++++++++- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/integration/feed_repo_test.go rename tests/integration/{api_feed_user_test.go => feed_user_test.go} (52%) diff --git a/routers/web/feed/branch.go b/routers/web/feed/branch.go index 6c4cc11ca0565..d3dae9503e843 100644 --- a/routers/web/feed/branch.go +++ b/routers/web/feed/branch.go @@ -43,6 +43,7 @@ func ShowBranchFeed(ctx *context.Context, repo *repo.Repository, formatType stri }, Description: commit.Message(), Content: commit.Message(), + Created: commit.Committer.When, }) } diff --git a/routers/web/feed/file.go b/routers/web/feed/file.go index 518d995ccbcb7..407e4fa2d5daf 100644 --- a/routers/web/feed/file.go +++ b/routers/web/feed/file.go @@ -55,6 +55,7 @@ func ShowFileFeed(ctx *context.Context, repo *repo.Repository, formatType string }, Description: commit.Message(), Content: commit.Message(), + Created: commit.Committer.When, }) } diff --git a/tests/integration/feed_repo_test.go b/tests/integration/feed_repo_test.go new file mode 100644 index 0000000000000..76bcf31205e1e --- /dev/null +++ b/tests/integration/feed_repo_test.go @@ -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, ` Date: Sun, 26 Jan 2025 22:30:34 -0800 Subject: [PATCH 2/2] Fix test --- tests/integration/feed_repo_test.go | 2 +- tests/integration/feed_user_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/feed_repo_test.go b/tests/integration/feed_repo_test.go index 76bcf31205e1e..132ed32ced803 100644 --- a/tests/integration/feed_repo_test.go +++ b/tests/integration/feed_repo_test.go @@ -26,7 +26,7 @@ func TestFeedRepo(t *testing.T) { var rss RSS err := xml.Unmarshal(resp.Body.Bytes(), &rss) assert.NoError(t, err) - assert.Equal(t, "http://localhost:3003/user2/repo1", rss.Channel.Link) + 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) diff --git a/tests/integration/feed_user_test.go b/tests/integration/feed_user_test.go index e9aa9ed068cc5..4315c67f4830b 100644 --- a/tests/integration/feed_user_test.go +++ b/tests/integration/feed_user_test.go @@ -53,7 +53,7 @@ func TestFeedUser(t *testing.T) { var rss RSS err := xml.Unmarshal(resp.Body.Bytes(), &rss) assert.NoError(t, err) - assert.Equal(t, "http://localhost:3003/user2", rss.Channel.Link) + assert.Contains(t, rss.Channel.Link, "/user2") assert.NotEmpty(t, rss.Channel.PubDate) }) })