2022-03-14 01:40:47 +09:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package feed
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
|
|
|
|
|
|
|
"github.com/gorilla/feeds"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ShowRepoFeed shows user activity on the repo as RSS / Atom feed
|
|
|
|
func ShowRepoFeed(ctx *context.Context, repo *repo_model.Repository, formatType string) {
|
|
|
|
actions, err := models.GetFeeds(ctx, models.GetFeedsOptions{
|
|
|
|
RequestedRepo: repo,
|
2022-03-22 16:03:22 +09:00
|
|
|
Actor: ctx.Doer,
|
2022-03-14 01:40:47 +09:00
|
|
|
IncludePrivate: true,
|
|
|
|
Date: ctx.FormString("date"),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetFeeds", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
feed := &feeds.Feed{
|
|
|
|
Title: ctx.Tr("home.feed_of", repo.FullName()),
|
|
|
|
Link: &feeds.Link{Href: repo.HTMLURL()},
|
|
|
|
Description: repo.Description,
|
|
|
|
Created: time.Now(),
|
|
|
|
}
|
|
|
|
|
|
|
|
feed.Items, err = feedActionsToFeedItems(ctx, actions)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("convert feed", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
writeFeed(ctx, feed, formatType)
|
|
|
|
}
|