summaryrefslogtreecommitdiffstats
path: root/routers/web/feed/release.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-12-12 23:57:56 +0100
commite68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch)
tree97775d6c13b0f416af55314eb6a89ef792474615 /routers/web/feed/release.go
parentInitial commit. (diff)
downloadforgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz
forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to '')
-rw-r--r--routers/web/feed/release.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/routers/web/feed/release.go b/routers/web/feed/release.go
new file mode 100644
index 0000000..fb6e3ad
--- /dev/null
+++ b/routers/web/feed/release.go
@@ -0,0 +1,52 @@
+// Copyright 2022 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package feed
+
+import (
+ "time"
+
+ "code.gitea.io/gitea/models/db"
+ repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/services/context"
+
+ "github.com/gorilla/feeds"
+)
+
+// shows tags and/or releases on the repo as RSS / Atom feed
+func ShowReleaseFeed(ctx *context.Context, repo *repo_model.Repository, isReleasesOnly bool, formatType string) {
+ releases, err := db.Find[repo_model.Release](ctx, repo_model.FindReleasesOptions{
+ IncludeTags: !isReleasesOnly,
+ RepoID: ctx.Repo.Repository.ID,
+ })
+ if err != nil {
+ ctx.ServerError("GetReleasesByRepoID", err)
+ return
+ }
+
+ var title string
+ var link *feeds.Link
+
+ if isReleasesOnly {
+ title = ctx.Locale.TrString("repo.release.releases_for", repo.FullName())
+ link = &feeds.Link{Href: repo.HTMLURL() + "/release"}
+ } else {
+ title = ctx.Locale.TrString("repo.release.tags_for", repo.FullName())
+ link = &feeds.Link{Href: repo.HTMLURL() + "/tags"}
+ }
+
+ feed := &feeds.Feed{
+ Title: title,
+ Link: link,
+ Description: repo.Description,
+ Created: time.Now(),
+ }
+
+ feed.Items, err = releasesToFeedItems(ctx, releases)
+ if err != nil {
+ ctx.ServerError("releasesToFeedItems", err)
+ return
+ }
+
+ writeFeed(ctx, feed, formatType)
+}