diff options
author | Reo <112817228+reopt999@users.noreply.github.com> | 2022-12-22 04:06:26 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-21 15:06:26 -0600 |
commit | 48d71b7d6b0ddefdc1db76d5b5f3b3eabc4ae9e4 (patch) | |
tree | 98399f876a26694162178f4dd6deef6deaff4eb9 /routers/web/feed/convert.go | |
parent | 9914b21493784793fb4a3660369befb98a9bd073 (diff) | |
download | gitea-48d71b7d6b0ddefdc1db76d5b5f3b3eabc4ae9e4.tar.gz gitea-48d71b7d6b0ddefdc1db76d5b5f3b3eabc4ae9e4.zip |
Add Feed for Releases and Tags (#21696)
Fixes #19091
Add Feed for Releases and Tags, can be accessed through
`reponame/releases.rss`, `reponame/releases.atom`, `reponame/tags.rss`,
and `reponame/tags.atom`
Signed-off-by: Reo <reo_999@proton.me>
Diffstat (limited to 'routers/web/feed/convert.go')
-rw-r--r-- | routers/web/feed/convert.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/routers/web/feed/convert.go b/routers/web/feed/convert.go index 7d472a7f87..7c375a085f 100644 --- a/routers/web/feed/convert.go +++ b/routers/web/feed/convert.go @@ -12,6 +12,7 @@ import ( "strings" activities_model "code.gitea.io/gitea/models/activities" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" @@ -268,3 +269,46 @@ func GetFeedType(name string, req *http.Request) (bool, string, string) { return false, name, "" } + +// feedActionsToFeedItems convert gitea's Repo's Releases to feeds Item +func releasesToFeedItems(ctx *context.Context, releases []*repo_model.Release, isReleasesOnly bool) (items []*feeds.Item, err error) { + for _, rel := range releases { + err := rel.LoadAttributes(ctx) + if err != nil { + return nil, err + } + + var title, content string + + if rel.IsTag { + title = rel.TagName + } else { + title = rel.Title + } + + link := &feeds.Link{Href: rel.HTMLURL()} + content, err = markdown.RenderString(&markup.RenderContext{ + Ctx: ctx, + URLPrefix: rel.Repo.Link(), + Metas: rel.Repo.ComposeMetas(), + }, rel.Note) + + if err != nil { + return nil, err + } + + items = append(items, &feeds.Item{ + Title: title, + Link: link, + Created: rel.CreatedUnix.AsTime(), + Author: &feeds.Author{ + Name: rel.Publisher.DisplayName(), + Email: rel.Publisher.GetEmail(), + }, + Id: fmt.Sprintf("%v: %v", strconv.FormatInt(rel.ID, 10), link.Href), + Content: content, + }) + } + + return items, err +} |