Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context * remove some unnecessary wrap functions
This commit is contained in:
parent
d81e31ad78
commit
fd7d83ace6
232 changed files with 1463 additions and 2108 deletions
|
@ -310,7 +310,7 @@ Loop:
|
|||
return false, "", nil, &ErrWontSign{twofa}
|
||||
}
|
||||
case approved:
|
||||
protectedBranch, err := models.GetProtectedBranchBy(repo.ID, pr.BaseBranch)
|
||||
protectedBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, pr.BaseBranch)
|
||||
if err != nil {
|
||||
return false, "", nil, err
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ func DeletePublicKey(doer *user_model.User, id int64) (err error) {
|
|||
committer.Close()
|
||||
|
||||
if key.Type == asymkey_model.KeyTypePrincipal {
|
||||
return asymkey_model.RewriteAllPrincipalKeys()
|
||||
return asymkey_model.RewriteAllPrincipalKeys(db.DefaultContext)
|
||||
}
|
||||
|
||||
return asymkey_model.RewriteAllPublicKeys()
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
|
@ -39,7 +40,7 @@ func TestUploadAttachment(t *testing.T) {
|
|||
}, f)
|
||||
assert.NoError(t, err)
|
||||
|
||||
attachment, err := repo_model.GetAttachmentByUUID(attach.UUID)
|
||||
attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, attach.UUID)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, user.ID, attachment.UploaderID)
|
||||
assert.Equal(t, int64(0), attachment.DownloadCount)
|
||||
|
|
|
@ -38,7 +38,7 @@ func CheckOAuthAccessToken(accessToken string) int64 {
|
|||
return 0
|
||||
}
|
||||
var grant *auth.OAuth2Grant
|
||||
if grant, err = auth.GetOAuth2GrantByID(token.GrantID); err != nil || grant == nil {
|
||||
if grant, err = auth.GetOAuth2GrantByID(db.DefaultContext, token.GrantID); err != nil || grant == nil {
|
||||
return 0
|
||||
}
|
||||
if token.Type != oauth2.TypeAccessToken {
|
||||
|
|
|
@ -63,7 +63,7 @@ func (r *ReverseProxy) Verify(req *http.Request, w http.ResponseWriter, store Da
|
|||
}
|
||||
log.Trace("ReverseProxy Authorization: Found username: %s", username)
|
||||
|
||||
user, err := user_model.GetUserByName(username)
|
||||
user, err := user_model.GetUserByName(req.Context(), username)
|
||||
if err != nil {
|
||||
if !user_model.IsErrUserNotExist(err) || !r.isAutoRegisterAllowed() {
|
||||
log.Error("GetUserByName: %v", err)
|
||||
|
|
|
@ -34,11 +34,11 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str
|
|||
isAttributeSSHPublicKeySet := len(strings.TrimSpace(source.AttributeSSHPublicKey)) > 0
|
||||
|
||||
// Update User admin flag if exist
|
||||
if isExist, err := user_model.IsUserExist(0, sr.Username); err != nil {
|
||||
if isExist, err := user_model.IsUserExist(db.DefaultContext, 0, sr.Username); err != nil {
|
||||
return nil, err
|
||||
} else if isExist {
|
||||
if user == nil {
|
||||
user, err = user_model.GetUserByName(sr.Username)
|
||||
user, err = user_model.GetUserByName(db.DefaultContext, sr.Username)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -118,7 +118,6 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
|
|||
}
|
||||
|
||||
err = user_model.CreateUser(usr, overwriteDefault)
|
||||
|
||||
if err != nil {
|
||||
log.Error("SyncExternalUsers[%s]: Error creating user %s: %v", source.authSource.Name, su.Username, err)
|
||||
}
|
||||
|
@ -161,7 +160,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
|
|||
}
|
||||
usr.IsActive = true
|
||||
|
||||
err = user_model.UpdateUser(usr, emailChanged, "full_name", "email", "is_admin", "is_restricted", "is_active")
|
||||
err = user_model.UpdateUser(ctx, usr, emailChanged, "full_name", "email", "is_admin", "is_restricted", "is_active")
|
||||
if err != nil {
|
||||
log.Error("SyncExternalUsers[%s]: Error updating user %s: %v", source.authSource.Name, usr.Name, err)
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ func (s *SSPI) Verify(req *http.Request, w http.ResponseWriter, store DataStore,
|
|||
}
|
||||
log.Info("Authenticated as %s\n", username)
|
||||
|
||||
user, err := user_model.GetUserByName(username)
|
||||
user, err := user_model.GetUserByName(req.Context(), username)
|
||||
if err != nil {
|
||||
if !user_model.IsErrUserNotExist(err) {
|
||||
log.Error("GetUserByName: %v", err)
|
||||
|
|
|
@ -145,7 +145,7 @@ func getPullRequestsByHeadSHA(ctx context.Context, sha string, repo *repo_model.
|
|||
continue
|
||||
}
|
||||
|
||||
p, err := models.GetPullRequestByIndexCtx(ctx, repo.ID, prIndex)
|
||||
p, err := models.GetPullRequestByIndex(ctx, repo.ID, prIndex)
|
||||
if err != nil {
|
||||
// If there is no pull request for this branch, we don't try to merge it.
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
|
|
|
@ -48,7 +48,7 @@ func UpdateComment(c *models.Comment, doer *user_model.User, oldContent string)
|
|||
return err
|
||||
}
|
||||
if !hasContentHistory {
|
||||
if err = issues.SaveIssueContentHistory(db.GetEngine(db.DefaultContext), c.PosterID, c.IssueID, c.ID,
|
||||
if err = issues.SaveIssueContentHistory(db.DefaultContext, c.PosterID, c.IssueID, c.ID,
|
||||
c.CreatedUnix, oldContent, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func UpdateComment(c *models.Comment, doer *user_model.User, oldContent string)
|
|||
}
|
||||
|
||||
if needsContentHistory {
|
||||
err := issues.SaveIssueContentHistory(db.GetEngine(db.DefaultContext), doer.ID, c.IssueID, c.ID, timeutil.TimeStampNow(), c.Content, false)
|
||||
err := issues.SaveIssueContentHistory(db.DefaultContext, doer.ID, c.IssueID, c.ID, timeutil.TimeStampNow(), c.Content, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func userAssignment(ctx *context.Context, errCb func(int, string, interface{}))
|
|||
ctx.ContextUser = ctx.Doer
|
||||
} else {
|
||||
var err error
|
||||
ctx.ContextUser, err = user_model.GetUserByName(username)
|
||||
ctx.ContextUser, err = user_model.GetUserByName(ctx, username)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
if redirectUserID, err := user_model.LookupUserRedirect(username); err == nil {
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/admin"
|
||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/updatechecker"
|
||||
|
@ -79,7 +80,7 @@ func registerRewriteAllPrincipalKeys() {
|
|||
RunAtStart: false,
|
||||
Schedule: "@every 72h",
|
||||
}, func(_ context.Context, _ *user_model.User, _ Config) error {
|
||||
return asymkey_model.RewriteAllPrincipalKeys()
|
||||
return asymkey_model.RewriteAllPrincipalKeys(db.DefaultContext)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,10 @@ import (
|
|||
// DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array
|
||||
func DeleteNotPassedAssignee(issue *models.Issue, doer *user_model.User, assignees []*user_model.User) (err error) {
|
||||
var found bool
|
||||
oriAssignes := make([]*user_model.User, len(issue.Assignees))
|
||||
_ = copy(oriAssignes, issue.Assignees)
|
||||
|
||||
for _, assignee := range issue.Assignees {
|
||||
|
||||
for _, assignee := range oriAssignes {
|
||||
found = false
|
||||
for _, alreadyAssignee := range assignees {
|
||||
if assignee.ID == alreadyAssignee.ID {
|
||||
|
@ -110,7 +111,7 @@ func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User,
|
|||
}
|
||||
}
|
||||
|
||||
lastreview, err := models.GetReviewByIssueIDAndUserID(issue.ID, reviewer.ID)
|
||||
lastreview, err := models.GetReviewByIssueIDAndUserID(ctx, issue.ID, reviewer.ID)
|
||||
if err != nil && !models.IsErrReviewNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
@ -132,7 +133,7 @@ func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User,
|
|||
|
||||
pemResult = permDoer.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests)
|
||||
if !pemResult {
|
||||
pemResult, err = models.IsOfficialReviewer(issue, doer)
|
||||
pemResult, err = models.IsOfficialReviewer(ctx, issue, doer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -201,7 +202,7 @@ func IsValidTeamReviewRequest(ctx context.Context, reviewer *organization.Team,
|
|||
|
||||
doerCanWrite := permission.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests)
|
||||
if !doerCanWrite {
|
||||
official, err := models.IsOfficialReviewer(issue, doer)
|
||||
official, err := models.IsOfficialReviewer(ctx, issue, doer)
|
||||
if err != nil {
|
||||
log.Error("Unable to Check if IsOfficialReviewer for %-v in %-v#%d", doer, issue.Repo, issue.Index)
|
||||
return err
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
|
||||
|
@ -20,21 +21,23 @@ func TestDeleteNotPassedAssignee(t *testing.T) {
|
|||
// Fake issue with assignees
|
||||
issue, err := models.GetIssueWithAttrsByID(1)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(issue.Assignees))
|
||||
|
||||
user1, err := user_model.GetUserByID(1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Check if he got removed
|
||||
isAssigned, err := models.IsUserAssignedToIssue(issue, user1)
|
||||
isAssigned, err := models.IsUserAssignedToIssue(db.DefaultContext, issue, user1)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, isAssigned)
|
||||
|
||||
// Clean everyone
|
||||
err = DeleteNotPassedAssignee(issue, user1, []*user_model.User{})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 0, len(issue.Assignees))
|
||||
|
||||
// Check they're gone
|
||||
assignees, err := models.GetAssigneesByIssue(issue)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, assignees)
|
||||
assert.NoError(t, issue.LoadAssignees(db.DefaultContext))
|
||||
assert.EqualValues(t, 0, len(issue.Assignees))
|
||||
assert.Empty(t, issue.Assignee)
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees
|
|||
|
||||
// Loop through all assignees to add them
|
||||
for _, assigneeName := range multipleAssignees {
|
||||
assignee, err := user_model.GetUserByName(assigneeName)
|
||||
assignee, err := user_model.GetUserByName(db.DefaultContext, assigneeName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ func AddAssigneeIfNotAssigned(issue *models.Issue, doer *user_model.User, assign
|
|||
}
|
||||
|
||||
// Check if the user is already assigned
|
||||
isAssigned, err := models.IsUserAssignedToIssue(issue, assignee)
|
||||
isAssigned, err := models.IsUserAssignedToIssue(db.DefaultContext, issue, assignee)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ func RemoveLabel(issue *models.Issue, doer *user_model.User, label *models.Label
|
|||
|
||||
// ReplaceLabels removes all current labels and add new labels to the issue.
|
||||
func ReplaceLabels(issue *models.Issue, doer *user_model.User, labels []*models.Label) error {
|
||||
old, err := models.GetLabelsByIssueID(issue.ID)
|
||||
old, err := models.GetLabelsByIssueID(db.DefaultContext, issue.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
|
|||
unfiltered = append(unfiltered, ids...)
|
||||
|
||||
// =========== Issue watchers ===========
|
||||
ids, err = models.GetIssueWatchersIDs(ctx.Issue.ID, true)
|
||||
ids, err = models.GetIssueWatchersIDs(ctx, ctx.Issue.ID, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err)
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
|
|||
}
|
||||
|
||||
// Avoid mailing explicit unwatched
|
||||
ids, err = models.GetIssueWatchersIDs(ctx.Issue.ID, false)
|
||||
ids, err = models.GetIssueWatchersIDs(ctx, ctx.Issue.ID, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err)
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ func (g *GiteaLocalUploader) MaxBatchInsertSize(tp string) int {
|
|||
|
||||
// CreateRepo creates a repository
|
||||
func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.MigrateOptions) error {
|
||||
owner, err := user_model.GetUserByName(g.repoOwner)
|
||||
owner, err := user_model.GetUserByName(g.ctx, g.repoOwner)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -826,7 +826,7 @@ func (g *GiteaLocalUploader) Finish() error {
|
|||
}
|
||||
|
||||
g.repo.Status = repo_model.RepositoryReady
|
||||
return repo_model.UpdateRepositoryCols(g.repo, "status")
|
||||
return repo_model.UpdateRepositoryCols(g.ctx, g.repo, "status")
|
||||
}
|
||||
|
||||
func (g *GiteaLocalUploader) remapUser(source user_model.ExternalUserMigrated, target user_model.ExternalUserRemappable) error {
|
||||
|
|
|
@ -40,7 +40,8 @@ func TestGiteaUploadRepo(t *testing.T) {
|
|||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
||||
|
||||
var (
|
||||
downloader = NewGithubDownloaderV3(context.Background(), "https://github.com", "", "", "", "go-xorm", "builder")
|
||||
ctx = context.Background()
|
||||
downloader = NewGithubDownloaderV3(ctx, "https://github.com", "", "", "", "go-xorm", "builder")
|
||||
repoName = "builder-" + time.Now().Format("2006-01-02-15-04-05")
|
||||
uploader = NewGiteaLocalUploader(graceful.GetManager().HammerContext(), user, user.Name, repoName)
|
||||
)
|
||||
|
@ -80,7 +81,7 @@ func TestGiteaUploadRepo(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Empty(t, milestones)
|
||||
|
||||
labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
|
||||
labels, err := models.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, labels, 12)
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
admin_model "code.gitea.io/gitea/models/admin"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/cache"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
|
@ -71,7 +72,7 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
|
|||
}
|
||||
|
||||
m.Repo.OriginalURL = addr
|
||||
return repo_model.UpdateRepositoryCols(m.Repo, "original_url")
|
||||
return repo_model.UpdateRepositoryCols(ctx, m.Repo, "original_url")
|
||||
}
|
||||
|
||||
// mirrorSyncResult contains information of a updated reference.
|
||||
|
@ -395,11 +396,12 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
|||
log.Error("PANIC whilst SyncMirrors[repo_id: %d] Panic: %v\nStacktrace: %s", repoID, err, log.Stack(2))
|
||||
}()
|
||||
|
||||
m, err := repo_model.GetMirrorByRepoID(repoID)
|
||||
m, err := repo_model.GetMirrorByRepoID(ctx, repoID)
|
||||
if err != nil {
|
||||
log.Error("SyncMirrors [repo_id: %v]: unable to GetMirrorByRepoID: %v", repoID, err)
|
||||
return false
|
||||
}
|
||||
_ = m.GetRepository() // force load repository of mirror
|
||||
|
||||
ctx, _, finished := process.GetManager().AddContext(ctx, fmt.Sprintf("Syncing Mirror %s/%s", m.Repo.OwnerName, m.Repo.Name))
|
||||
defer finished()
|
||||
|
@ -415,7 +417,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
|||
|
||||
log.Trace("SyncMirrors [repo: %-v]: Scheduling next update", m.Repo)
|
||||
m.ScheduleNextUpdate()
|
||||
if err = repo_model.UpdateMirror(m); err != nil {
|
||||
if err = repo_model.UpdateMirror(ctx, m); err != nil {
|
||||
log.Error("SyncMirrors [repo: %-v]: failed to UpdateMirror with next update date: %v", m.Repo, err)
|
||||
return false
|
||||
}
|
||||
|
@ -574,7 +576,7 @@ func checkAndUpdateEmptyRepository(m *repo_model.Mirror, gitRepo *git.Repository
|
|||
}
|
||||
m.Repo.IsEmpty = false
|
||||
// Update the is empty and default_branch columns
|
||||
if err := repo_model.UpdateRepositoryCols(m.Repo, "default_branch", "is_empty"); err != nil {
|
||||
if err := repo_model.UpdateRepositoryCols(db.DefaultContext, m.Repo, "default_branch", "is_empty"); err != nil {
|
||||
log.Error("Failed to update default branch of repository %-v. Error: %v", m.Repo, err)
|
||||
desc := fmt.Sprintf("Failed to uupdate default branch of repository '%s': %v", m.Repo.RepoPath(), err)
|
||||
if err = admin_model.CreateRepositoryNotice(desc); err != nil {
|
||||
|
|
|
@ -66,6 +66,7 @@ func AddPushMirrorRemote(ctx context.Context, m *repo_model.PushMirror, addr str
|
|||
// RemovePushMirrorRemote removes the push mirror remote.
|
||||
func RemovePushMirrorRemote(ctx context.Context, m *repo_model.PushMirror) error {
|
||||
cmd := git.NewCommand(ctx, "remote", "rm", m.RemoteName)
|
||||
_ = m.GetRepository()
|
||||
|
||||
if _, _, err := cmd.RunStdString(&git.RunOpts{Dir: m.Repo.RepoPath()}); err != nil {
|
||||
return err
|
||||
|
@ -99,6 +100,8 @@ func SyncPushMirror(ctx context.Context, mirrorID int64) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
_ = m.GetRepository()
|
||||
|
||||
m.LastError = ""
|
||||
|
||||
ctx, _, finished := process.GetManager().AddContext(ctx, fmt.Sprintf("Syncing PushMirror %s/%s to %s", m.Repo.OwnerName, m.Repo.Name, m.RemoteName))
|
||||
|
|
|
@ -26,7 +26,7 @@ func DeleteOrganization(org *organization.Organization) error {
|
|||
defer commiter.Close()
|
||||
|
||||
// Check ownership of repository.
|
||||
count, err := repo_model.GetRepositoryCount(ctx, org.ID)
|
||||
count, err := repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{OwnerID: org.ID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryCount: %v", err)
|
||||
} else if count > 0 {
|
||||
|
|
|
@ -99,7 +99,7 @@ func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *acce
|
|||
if err := CheckPullBranchProtections(ctx, pr, false); err != nil {
|
||||
if models.IsErrDisallowedToMerge(err) {
|
||||
if force {
|
||||
if isRepoAdmin, err2 := access_model.IsUserRepoAdminCtx(ctx, pr.BaseRepo, doer); err2 != nil {
|
||||
if isRepoAdmin, err2 := access_model.IsUserRepoAdmin(ctx, pr.BaseRepo, doer); err2 != nil {
|
||||
return err2
|
||||
} else if !isRepoAdmin {
|
||||
return err
|
||||
|
|
|
@ -132,7 +132,7 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *models.PullRequest
|
|||
return "", errors.Wrap(err, "LoadBaseRepo")
|
||||
}
|
||||
|
||||
commitStatuses, _, err := models.GetLatestCommitStatusCtx(ctx, pr.BaseRepo.ID, sha, db.ListOptions{})
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(ctx, pr.BaseRepo.ID, sha, db.ListOptions{})
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "GetLatestCommitStatus")
|
||||
}
|
||||
|
|
|
@ -290,7 +290,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
|||
if err != nil {
|
||||
log.Error("GetDiverging: %v", err)
|
||||
} else {
|
||||
err = pr.UpdateCommitDivergence(divergence.Ahead, divergence.Behind)
|
||||
err = pr.UpdateCommitDivergence(ctx, divergence.Ahead, divergence.Behind)
|
||||
if err != nil {
|
||||
log.Error("UpdateCommitDivergence: %v", err)
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
|||
log.Error("GetDiverging: %v", err)
|
||||
}
|
||||
} else {
|
||||
err = pr.UpdateCommitDivergence(divergence.Ahead, divergence.Behind)
|
||||
err = pr.UpdateCommitDivergence(ctx, divergence.Ahead, divergence.Behind)
|
||||
if err != nil {
|
||||
log.Error("UpdateCommitDivergence: %v", err)
|
||||
}
|
||||
|
@ -793,7 +793,7 @@ func getAllCommitStatus(gitRepo *git.Repository, pr *models.PullRequest) (status
|
|||
return nil, nil, shaErr
|
||||
}
|
||||
|
||||
statuses, _, err = models.GetLatestCommitStatus(pr.BaseRepo.ID, sha, db.ListOptions{})
|
||||
statuses, _, err = models.GetLatestCommitStatus(db.DefaultContext, pr.BaseRepo.ID, sha, db.ListOptions{})
|
||||
lastStatus = models.CalcCommitStatus(statuses)
|
||||
return statuses, lastStatus, err
|
||||
}
|
||||
|
|
|
@ -71,13 +71,13 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
|
|||
return comment, nil
|
||||
}
|
||||
|
||||
review, err := models.GetCurrentReview(doer, issue)
|
||||
review, err := models.GetCurrentReview(ctx, doer, issue)
|
||||
if err != nil {
|
||||
if !models.IsErrReviewNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if review, err = models.CreateReview(models.CreateReviewOptions{
|
||||
if review, err = models.CreateReview(ctx, models.CreateReviewOptions{
|
||||
Type: models.ReviewTypePending,
|
||||
Reviewer: doer,
|
||||
Issue: issue,
|
||||
|
@ -135,7 +135,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
|
|||
head := pr.GetGitRefName()
|
||||
if line > 0 {
|
||||
if reviewID != 0 {
|
||||
first, err := models.FindComments(&models.FindCommentsOptions{
|
||||
first, err := models.FindComments(ctx, &models.FindCommentsOptions{
|
||||
ReviewID: reviewID,
|
||||
Line: line,
|
||||
TreePath: treePath,
|
||||
|
@ -152,7 +152,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
|
|||
} else if err != nil && !models.IsErrCommentNotExist(err) {
|
||||
return nil, fmt.Errorf("Find first comment for %d line %d path %s. Error: %v", reviewID, line, treePath, err)
|
||||
} else {
|
||||
review, err := models.GetReviewByID(reviewID)
|
||||
review, err := models.GetReviewByID(ctx, reviewID)
|
||||
if err == nil && len(review.CommitID) > 0 {
|
||||
head = review.CommitID
|
||||
} else if err != nil && !models.IsErrReviewNotExist(err) {
|
||||
|
@ -272,7 +272,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
|
|||
|
||||
// DismissReview dismissing stale review by repo admin
|
||||
func DismissReview(ctx context.Context, reviewID int64, message string, doer *user_model.User, isDismiss bool) (comment *models.Comment, err error) {
|
||||
review, err := models.GetReviewByID(reviewID)
|
||||
review, err := models.GetReviewByID(ctx, reviewID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
|
@ -248,7 +249,7 @@ func TestRelease_Update(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, UpdateRelease(user, gitRepo, release, []string{attach.UUID}, nil, nil))
|
||||
assert.NoError(t, models.GetReleaseAttachments(release))
|
||||
assert.NoError(t, models.GetReleaseAttachments(db.DefaultContext, release))
|
||||
assert.Len(t, release.Attachments, 1)
|
||||
assert.EqualValues(t, attach.UUID, release.Attachments[0].UUID)
|
||||
assert.EqualValues(t, release.ID, release.Attachments[0].ReleaseID)
|
||||
|
@ -259,7 +260,7 @@ func TestRelease_Update(t *testing.T) {
|
|||
attach.UUID: "test2.txt",
|
||||
}))
|
||||
release.Attachments = nil
|
||||
assert.NoError(t, models.GetReleaseAttachments(release))
|
||||
assert.NoError(t, models.GetReleaseAttachments(db.DefaultContext, release))
|
||||
assert.Len(t, release.Attachments, 1)
|
||||
assert.EqualValues(t, attach.UUID, release.Attachments[0].UUID)
|
||||
assert.EqualValues(t, release.ID, release.Attachments[0].ReleaseID)
|
||||
|
@ -268,7 +269,7 @@ func TestRelease_Update(t *testing.T) {
|
|||
// delete the attachment
|
||||
assert.NoError(t, UpdateRelease(user, gitRepo, release, nil, []string{attach.UUID}, nil))
|
||||
release.Attachments = nil
|
||||
assert.NoError(t, models.GetReleaseAttachments(release))
|
||||
assert.NoError(t, models.GetReleaseAttachments(db.DefaultContext, release))
|
||||
assert.Empty(t, release.Attachments)
|
||||
}
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ func DeleteUnadoptedRepository(doer, u *user_model.User, repoName string) error
|
|||
}
|
||||
}
|
||||
|
||||
if exist, err := repo_model.IsRepositoryExist(u, repoName); err != nil {
|
||||
if exist, err := repo_model.IsRepositoryExist(db.DefaultContext, u, repoName); err != nil {
|
||||
return err
|
||||
} else if exist {
|
||||
return repo_model.ErrRepoAlreadyExist{
|
||||
|
@ -238,7 +238,7 @@ func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unad
|
|||
if len(repoNamesToCheck) == 0 {
|
||||
return nil
|
||||
}
|
||||
ctxUser, err := user_model.GetUserByName(userName)
|
||||
ctxUser, err := user_model.GetUserByName(db.DefaultContext, userName)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
log.Debug("Missing user: %s", userName)
|
||||
|
|
|
@ -44,7 +44,7 @@ func UploadAvatar(repo *repo_model.Repository, data []byte) error {
|
|||
// Users can upload the same image to other repo - prefix it with ID
|
||||
// Then repo will be removed - only it avatar file will be removed
|
||||
repo.Avatar = newAvatar
|
||||
if err := repo_model.UpdateRepositoryColsCtx(ctx, repo, "avatar"); err != nil {
|
||||
if err := repo_model.UpdateRepositoryCols(ctx, repo, "avatar"); err != nil {
|
||||
return fmt.Errorf("UploadAvatar: Update repository avatar: %v", err)
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ func DeleteAvatar(repo *repo_model.Repository) error {
|
|||
defer committer.Close()
|
||||
|
||||
repo.Avatar = ""
|
||||
if err := repo_model.UpdateRepositoryColsCtx(ctx, repo, "avatar"); err != nil {
|
||||
if err := repo_model.UpdateRepositoryCols(ctx, repo, "avatar"); err != nil {
|
||||
return fmt.Errorf("DeleteAvatar: Update repository avatar: %v", err)
|
||||
}
|
||||
|
||||
|
@ -117,5 +117,5 @@ func generateAvatar(ctx context.Context, templateRepo, generateRepo *repo_model.
|
|||
return err
|
||||
}
|
||||
|
||||
return repo_model.UpdateRepositoryColsCtx(ctx, generateRepo, "avatar")
|
||||
return repo_model.UpdateRepositoryCols(ctx, generateRepo, "avatar")
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ func (opts *ApplyDiffPatchOptions) Validate(ctx context.Context, repo *repo_mode
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
protectedBranch, err := models.GetProtectedBranchBy(repo.ID, opts.OldBranch)
|
||||
protectedBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, opts.OldBranch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -462,7 +462,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do
|
|||
|
||||
// VerifyBranchProtection verify the branch protection for modifying the given treePath on the given branch
|
||||
func VerifyBranchProtection(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, branchName, treePath string) error {
|
||||
protectedBranch, err := models.GetProtectedBranchBy(repo.ID, branchName)
|
||||
protectedBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, branchName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
|||
}
|
||||
}
|
||||
// Update the is empty and default_branch columns
|
||||
if err := repo_model.UpdateRepositoryCols(repo, "default_branch", "is_empty"); err != nil {
|
||||
if err := repo_model.UpdateRepositoryCols(db.DefaultContext, repo, "default_branch", "is_empty"); err != nil {
|
||||
return fmt.Errorf("UpdateRepositoryCols: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
|||
}
|
||||
|
||||
// Even if user delete a branch on a repository which he didn't watch, he will be watch that.
|
||||
if err = repo_model.WatchIfAuto(opts.PusherID, repo.ID, true); err != nil {
|
||||
if err = repo_model.WatchIfAuto(db.DefaultContext, opts.PusherID, repo.ID, true); err != nil {
|
||||
log.Warn("Fail to perform auto watch on user %v for repo %v: %v", opts.PusherID, repo.ID, err)
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -44,7 +44,7 @@ func DeleteUser(u *user_model.User) error {
|
|||
// cannot perform delete operation.
|
||||
|
||||
// Check ownership of repository.
|
||||
count, err := repo_model.GetRepositoryCount(ctx, u.ID)
|
||||
count, err := repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{OwnerID: u.ID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryCount: %v", err)
|
||||
} else if count > 0 {
|
||||
|
@ -78,7 +78,7 @@ func DeleteUser(u *user_model.User) error {
|
|||
if err = asymkey_model.RewriteAllPublicKeys(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = asymkey_model.RewriteAllPrincipalKeys(); err != nil {
|
||||
if err = asymkey_model.RewriteAllPrincipalKeys(db.DefaultContext); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
package webhook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
|
@ -218,15 +220,15 @@ func prepareWebhook(w *webhook_model.Webhook, repo *repo_model.Repository, event
|
|||
|
||||
// PrepareWebhooks adds new webhooks to task queue for given payload.
|
||||
func PrepareWebhooks(repo *repo_model.Repository, event webhook_model.HookEventType, p api.Payloader) error {
|
||||
if err := prepareWebhooks(repo, event, p); err != nil {
|
||||
if err := prepareWebhooks(db.DefaultContext, repo, event, p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return addToTask(repo.ID)
|
||||
}
|
||||
|
||||
func prepareWebhooks(repo *repo_model.Repository, event webhook_model.HookEventType, p api.Payloader) error {
|
||||
ws, err := webhook_model.ListWebhooksByOpts(&webhook_model.ListWebhookOptions{
|
||||
func prepareWebhooks(ctx context.Context, repo *repo_model.Repository, event webhook_model.HookEventType, p api.Payloader) error {
|
||||
ws, err := webhook_model.ListWebhooksByOpts(ctx, &webhook_model.ListWebhookOptions{
|
||||
RepoID: repo.ID,
|
||||
IsActive: util.OptionalBoolTrue,
|
||||
})
|
||||
|
@ -237,7 +239,7 @@ func prepareWebhooks(repo *repo_model.Repository, event webhook_model.HookEventT
|
|||
// check if repo belongs to org and append additional webhooks
|
||||
if repo.MustOwner().IsOrganization() {
|
||||
// get hooks for org
|
||||
orgHooks, err := webhook_model.ListWebhooksByOpts(&webhook_model.ListWebhookOptions{
|
||||
orgHooks, err := webhook_model.ListWebhooksByOpts(ctx, &webhook_model.ListWebhookOptions{
|
||||
OrgID: repo.OwnerID,
|
||||
IsActive: util.OptionalBoolTrue,
|
||||
})
|
||||
|
@ -248,7 +250,7 @@ func prepareWebhooks(repo *repo_model.Repository, event webhook_model.HookEventT
|
|||
}
|
||||
|
||||
// Add any admin-defined system webhooks
|
||||
systemHooks, err := webhook_model.GetSystemWebhooks(util.OptionalBoolTrue)
|
||||
systemHooks, err := webhook_model.GetSystemWebhooks(ctx, util.OptionalBoolTrue)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetSystemWebhooks: %v", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue