aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-10-15 23:46:06 +0800
committerGitHub <noreply@github.com>2023-10-15 17:46:06 +0200
commitcddf245c12223c783c856c87c21cc796ac425439 (patch)
tree21edf50797c62c3e70dbada95edc20d7ddfd53b8 /models/repo
parent7480aacdad9470458fa0142beab54b8011bbac25 (diff)
downloadgitea-cddf245c12223c783c856c87c21cc796ac425439.tar.gz
gitea-cddf245c12223c783c856c87c21cc796ac425439.zip
Replace more db.DefaultContext (#27628)
Target #27065
Diffstat (limited to 'models/repo')
-rw-r--r--models/repo/repo_list.go4
-rw-r--r--models/repo/watch.go6
-rw-r--r--models/repo/watch_test.go8
3 files changed, 9 insertions, 9 deletions
diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go
index 4a703dc584..1668c23c77 100644
--- a/models/repo/repo_list.go
+++ b/models/repo/repo_list.go
@@ -716,7 +716,7 @@ func FindUserCodeAccessibleOwnerRepoIDs(ctx context.Context, ownerID int64, user
}
// GetUserRepositories returns a list of repositories of given user.
-func GetUserRepositories(opts *SearchRepoOptions) (RepositoryList, int64, error) {
+func GetUserRepositories(ctx context.Context, opts *SearchRepoOptions) (RepositoryList, int64, error) {
if len(opts.OrderBy) == 0 {
opts.OrderBy = "updated_unix DESC"
}
@@ -734,7 +734,7 @@ func GetUserRepositories(opts *SearchRepoOptions) (RepositoryList, int64, error)
cond = cond.And(builder.In("lower_name", opts.LowerNames))
}
- sess := db.GetEngine(db.DefaultContext)
+ sess := db.GetEngine(ctx)
count, err := sess.Where(cond).Count(new(Repository))
if err != nil {
diff --git a/models/repo/watch.go b/models/repo/watch.go
index 02a94ecac0..fba66d6dcb 100644
--- a/models/repo/watch.go
+++ b/models/repo/watch.go
@@ -107,12 +107,12 @@ func watchRepoMode(ctx context.Context, watch Watch, mode WatchMode) (err error)
}
// WatchRepoMode watch repository in specific mode.
-func WatchRepoMode(userID, repoID int64, mode WatchMode) (err error) {
+func WatchRepoMode(ctx context.Context, userID, repoID int64, mode WatchMode) (err error) {
var watch Watch
- if watch, err = GetWatch(db.DefaultContext, userID, repoID); err != nil {
+ if watch, err = GetWatch(ctx, userID, repoID); err != nil {
return err
}
- return watchRepoMode(db.DefaultContext, watch, mode)
+ return watchRepoMode(ctx, watch, mode)
}
// WatchRepo watch or unwatch repository.
diff --git a/models/repo/watch_test.go b/models/repo/watch_test.go
index 1384d1e157..7aa899291c 100644
--- a/models/repo/watch_test.go
+++ b/models/repo/watch_test.go
@@ -122,18 +122,18 @@ func TestWatchRepoMode(t *testing.T) {
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 0)
- assert.NoError(t, repo_model.WatchRepoMode(12, 1, repo_model.WatchModeAuto))
+ assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeAuto))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1, Mode: repo_model.WatchModeAuto}, 1)
- assert.NoError(t, repo_model.WatchRepoMode(12, 1, repo_model.WatchModeNormal))
+ assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeNormal))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1, Mode: repo_model.WatchModeNormal}, 1)
- assert.NoError(t, repo_model.WatchRepoMode(12, 1, repo_model.WatchModeDont))
+ assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeDont))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1, Mode: repo_model.WatchModeDont}, 1)
- assert.NoError(t, repo_model.WatchRepoMode(12, 1, repo_model.WatchModeNone))
+ assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeNone))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 0)
}