From 81ec54ed090eae63beb5675d774580ce8a9fbc56 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 23 Aug 2025 10:54:09 -0700 Subject: [PATCH 1/2] Fix atom/rss mixed error --- routers/web/feed/render.go | 15 +++++++++++---- routers/web/web.go | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/routers/web/feed/render.go b/routers/web/feed/render.go index d1a229e5b2723..28e7070da088a 100644 --- a/routers/web/feed/render.go +++ b/routers/web/feed/render.go @@ -8,11 +8,18 @@ import ( ) // RenderBranchFeed render format for branch or file -func RenderBranchFeed(ctx *context.Context) { - _, showFeedType := GetFeedType(ctx.PathParam("reponame"), ctx.Req) +func RenderBranchFeedRSS(ctx *context.Context) { if ctx.Repo.TreePath == "" { - ShowBranchFeed(ctx, ctx.Repo.Repository, showFeedType) + ShowBranchFeed(ctx, ctx.Repo.Repository, "rss") } else { - ShowFileFeed(ctx, ctx.Repo.Repository, showFeedType) + ShowFileFeed(ctx, ctx.Repo.Repository, "rss") + } +} + +func RenderBranchFeedAtom(ctx *context.Context) { + if ctx.Repo.TreePath == "" { + ShowBranchFeed(ctx, ctx.Repo.Repository, "atom") + } else { + ShowFileFeed(ctx, ctx.Repo.Repository, "atom") } } diff --git a/routers/web/web.go b/routers/web/web.go index 4a274c171a3a0..5bdf62b581c3b 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1615,8 +1615,8 @@ func registerWebRoutes(m *web.Router) { m.Get("/cherry-pick/{sha:([a-f0-9]{7,64})$}", repo.SetEditorconfigIfExists, context.RepoRefByDefaultBranch(), repo.CherryPick) }, repo.MustBeNotEmpty) - m.Get("/rss/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeed) - m.Get("/atom/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeed) + m.Get("/rss/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeedRSS) + m.Get("/atom/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeedAtom) m.Group("/src", func() { m.Get("", func(ctx *context.Context) { ctx.Redirect(ctx.Repo.RepoLink) }) // there is no "{owner}/{repo}/src" page, so redirect to "{owner}/{repo}" to avoid 404 From 580a54fb86d95410faf95826d15c81d40bce50c3 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 23 Aug 2025 14:33:44 -0400 Subject: [PATCH 2/2] refactor to reduce duplication --- routers/web/feed/render.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/routers/web/feed/render.go b/routers/web/feed/render.go index 28e7070da088a..014da253bdfbf 100644 --- a/routers/web/feed/render.go +++ b/routers/web/feed/render.go @@ -8,18 +8,18 @@ import ( ) // RenderBranchFeed render format for branch or file -func RenderBranchFeedRSS(ctx *context.Context) { +func RenderBranchFeed(ctx *context.Context, feedType string) { if ctx.Repo.TreePath == "" { - ShowBranchFeed(ctx, ctx.Repo.Repository, "rss") + ShowBranchFeed(ctx, ctx.Repo.Repository, feedType) } else { - ShowFileFeed(ctx, ctx.Repo.Repository, "rss") + ShowFileFeed(ctx, ctx.Repo.Repository, feedType) } } +func RenderBranchFeedRSS(ctx *context.Context) { + RenderBranchFeed(ctx, "rss") +} + func RenderBranchFeedAtom(ctx *context.Context) { - if ctx.Repo.TreePath == "" { - ShowBranchFeed(ctx, ctx.Repo.Repository, "atom") - } else { - ShowFileFeed(ctx, ctx.Repo.Repository, "atom") - } + RenderBranchFeed(ctx, "atom") }