mirror of
1
Fork 0

Add pubdate for repository rss and add some tests (#33411)

Fix #33291

(cherry picked from commit dcd3014567f2b8be3fca01c20c2b3eabdc8f519e)

Conflicts:
	tests/integration/feed_user_test.go
  trivial context conflict
This commit is contained in:
Lunny Xiao 2025-01-27 07:58:46 -08:00 committed by Earl Warren
parent 6bd9867c3e
commit 6f97d5d625
No known key found for this signature in database
GPG Key ID: 0579CB2928A78A00
4 changed files with 61 additions and 0 deletions

View File

@ -43,6 +43,7 @@ func ShowBranchFeed(ctx *context.Context, repo *repo.Repository, formatType stri
},
Description: commit.Message(),
Content: commit.Message(),
Created: commit.Committer.When,
})
}

View File

@ -55,6 +55,7 @@ func ShowFileFeed(ctx *context.Context, repo *repo.Repository, formatType string
},
Description: commit.Message(),
Content: commit.Message(),
Created: commit.Committer.When,
})
}

View File

@ -0,0 +1,36 @@
// 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"
"github.com/stretchr/testify/require"
)
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)
require.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)
})
}

View File

@ -4,6 +4,7 @@
package integration
import (
"encoding/xml"
"net/http"
"testing"
@ -15,6 +16,22 @@ import (
"github.com/stretchr/testify/require"
)
// 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 TestFeed(t *testing.T) {
defer tests.AddFixtures("tests/integration/fixtures/TestFeed/")()
defer tests.PrepareTestEnv(t)()
@ -38,6 +55,12 @@ func TestFeed(t *testing.T) {
data := resp.Body.String()
assert.Contains(t, data, `<rss version="2.0"`)
var rss RSS
err := xml.Unmarshal(resp.Body.Bytes(), &rss)
require.NoError(t, err)
assert.Contains(t, rss.Channel.Link, "/user2")
assert.NotEmpty(t, rss.Channel.PubDate)
})
})