Skip to content

Commit db7486f

Browse files
committed
rm wrapper func
1 parent 6b0a1fe commit db7486f

File tree

6 files changed

+18
-27
lines changed

6 files changed

+18
-27
lines changed

models/action.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ type GetFeedsOptions struct {
328328
}
329329

330330
// GetFeeds returns actions according to the provided options
331-
func GetFeeds(opts GetFeedsOptions) (ActionList, error) {
331+
func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, error) {
332332
if opts.RequestedUser == nil && opts.RequestedTeam == nil && opts.RequestedRepo == nil {
333333
return nil, fmt.Errorf("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo")
334334
}
@@ -338,7 +338,7 @@ func GetFeeds(opts GetFeedsOptions) (ActionList, error) {
338338
return nil, err
339339
}
340340

341-
e := db.GetEngine(db.DefaultContext)
341+
e := db.GetEngine(ctx)
342342
sess := e.Where(cond)
343343

344344
opts.SetDefaultValues()

models/action_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path"
99
"testing"
1010

11+
"code.gitea.io/gitea/models/db"
1112
repo_model "code.gitea.io/gitea/models/repo"
1213
"code.gitea.io/gitea/models/unittest"
1314
user_model "code.gitea.io/gitea/models/user"
@@ -39,7 +40,7 @@ func TestGetFeeds(t *testing.T) {
3940
assert.NoError(t, unittest.PrepareTestDatabase())
4041
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
4142

42-
actions, err := GetFeeds(GetFeedsOptions{
43+
actions, err := GetFeeds(db.DefaultContext, GetFeedsOptions{
4344
RequestedUser: user,
4445
Actor: user,
4546
IncludePrivate: true,
@@ -52,7 +53,7 @@ func TestGetFeeds(t *testing.T) {
5253
assert.EqualValues(t, user.ID, actions[0].UserID)
5354
}
5455

55-
actions, err = GetFeeds(GetFeedsOptions{
56+
actions, err = GetFeeds(db.DefaultContext, GetFeedsOptions{
5657
RequestedUser: user,
5758
Actor: user,
5859
IncludePrivate: false,
@@ -68,7 +69,7 @@ func TestGetFeeds2(t *testing.T) {
6869
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
6970
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
7071

71-
actions, err := GetFeeds(GetFeedsOptions{
72+
actions, err := GetFeeds(db.DefaultContext, GetFeedsOptions{
7273
RequestedUser: org,
7374
Actor: user,
7475
IncludePrivate: true,
@@ -82,7 +83,7 @@ func TestGetFeeds2(t *testing.T) {
8283
assert.EqualValues(t, org.ID, actions[0].UserID)
8384
}
8485

85-
actions, err = GetFeeds(GetFeedsOptions{
86+
actions, err = GetFeeds(db.DefaultContext, GetFeedsOptions{
8687
RequestedUser: org,
8788
Actor: user,
8889
IncludePrivate: false,

models/user_heatmap_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010
"time"
1111

12+
"code.gitea.io/gitea/models/db"
1213
"code.gitea.io/gitea/models/unittest"
1314
user_model "code.gitea.io/gitea/models/user"
1415
"code.gitea.io/gitea/modules/json"
@@ -72,7 +73,7 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
7273
}
7374

7475
// get the action for comparison
75-
actions, err := GetFeeds(GetFeedsOptions{
76+
actions, err := GetFeeds(db.DefaultContext, GetFeedsOptions{
7677
RequestedUser: user,
7778
Actor: doer,
7879
IncludePrivate: true,

routers/web/feed/profile.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,18 @@ import (
1515
"github.com/gorilla/feeds"
1616
)
1717

18-
// RetrieveFeeds loads feeds for the specified user
19-
func RetrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) models.ActionList {
20-
actions, err := models.GetFeeds(options)
21-
if err != nil {
22-
ctx.ServerError("GetFeeds", err)
23-
return nil
24-
}
25-
26-
return actions
27-
}
28-
2918
// ShowUserFeed show user activity as RSS / Atom feed
3019
func ShowUserFeed(ctx *context.Context, ctxUser *user_model.User, formatType string) {
31-
actions := RetrieveFeeds(ctx, models.GetFeedsOptions{
20+
actions, err := models.GetFeeds(ctx, models.GetFeedsOptions{
3221
RequestedUser: ctxUser,
3322
Actor: ctx.User,
3423
IncludePrivate: false,
3524
OnlyPerformedBy: !ctxUser.IsOrganization(),
3625
IncludeDeleted: false,
3726
Date: ctx.FormString("date"),
3827
})
39-
if ctx.Written() {
28+
if err != nil {
29+
ctx.ServerError("GetFeeds", err)
4030
return
4131
}
4232

@@ -47,7 +37,6 @@ func ShowUserFeed(ctx *context.Context, ctxUser *user_model.User, formatType str
4737
Created: time.Now(),
4838
}
4939

50-
var err error
5140
feed.Items, err = feedActionsToFeedItems(ctx, actions)
5241
if err != nil {
5342
ctx.ServerError("convert feed", err)

routers/web/user/home.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"code.gitea.io/gitea/modules/markup/markdown"
3030
"code.gitea.io/gitea/modules/setting"
3131
"code.gitea.io/gitea/modules/util"
32-
"code.gitea.io/gitea/routers/web/feed"
3332
issue_service "code.gitea.io/gitea/services/issue"
3433
pull_service "code.gitea.io/gitea/services/pull"
3534

@@ -131,7 +130,7 @@ func Dashboard(ctx *context.Context) {
131130
ctx.Data["MirrorCount"] = len(mirrors)
132131
ctx.Data["Mirrors"] = mirrors
133132

134-
ctx.Data["Feeds"] = feed.RetrieveFeeds(ctx, models.GetFeedsOptions{
133+
ctx.Data["Feeds"], err = models.GetFeeds(ctx, models.GetFeedsOptions{
135134
RequestedUser: ctxUser,
136135
RequestedTeam: ctx.Org.Team,
137136
Actor: ctx.User,
@@ -140,8 +139,8 @@ func Dashboard(ctx *context.Context) {
140139
IncludeDeleted: false,
141140
Date: ctx.FormString("date"),
142141
})
143-
144-
if ctx.Written() {
142+
if err != nil {
143+
ctx.ServerError("GetFeeds", err)
145144
return
146145
}
147146

routers/web/user/profile.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,16 @@ func Profile(ctx *context.Context) {
259259

260260
total = ctxUser.NumFollowing
261261
case "activity":
262-
ctx.Data["Feeds"] = feed.RetrieveFeeds(ctx, models.GetFeedsOptions{
262+
ctx.Data["Feeds"], err = models.GetFeeds(ctx, models.GetFeedsOptions{
263263
RequestedUser: ctxUser,
264264
Actor: ctx.User,
265265
IncludePrivate: showPrivate,
266266
OnlyPerformedBy: true,
267267
IncludeDeleted: false,
268268
Date: ctx.FormString("date"),
269269
})
270-
if ctx.Written() {
270+
if err != nil {
271+
ctx.ServerError("GetFeeds", err)
271272
return
272273
}
273274
case "stars":

0 commit comments

Comments
 (0)