Final round of db.DefaultContext refactor (#27587)

Last part of #27065
This commit is contained in:
JakobDev 2023-10-14 10:37:24 +02:00 committed by GitHub
parent ae419fa494
commit 76a85a4ce9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 250 additions and 242 deletions

View file

@ -50,10 +50,10 @@ func init() {
}
// LookupRedirect look up if a repository has a redirect name
func LookupRedirect(ownerID int64, repoName string) (int64, error) {
func LookupRedirect(ctx context.Context, ownerID int64, repoName string) (int64, error) {
repoName = strings.ToLower(repoName)
redirect := &Redirect{OwnerID: ownerID, LowerName: repoName}
if has, err := db.GetEngine(db.DefaultContext).Get(redirect); err != nil {
if has, err := db.GetEngine(ctx).Get(redirect); err != nil {
return 0, err
} else if !has {
return 0, ErrRedirectNotExist{OwnerID: ownerID, RepoName: repoName}

View file

@ -16,11 +16,11 @@ import (
func TestLookupRedirect(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repoID, err := repo_model.LookupRedirect(2, "oldrepo1")
repoID, err := repo_model.LookupRedirect(db.DefaultContext, 2, "oldrepo1")
assert.NoError(t, err)
assert.EqualValues(t, 1, repoID)
_, err = repo_model.LookupRedirect(unittest.NonexistentID, "doesnotexist")
_, err = repo_model.LookupRedirect(db.DefaultContext, unittest.NonexistentID, "doesnotexist")
assert.True(t, repo_model.IsErrRedirectNotExist(err))
}