diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-09-19 19:49:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-19 19:49:59 +0800 |
commit | a4bfef265d9e512830350635a0489c2cdcd6508f (patch) | |
tree | 1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /models/update.go | |
parent | 462306e263db5a809dbe2cdf62e99307aeff28de (diff) | |
download | gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.tar.gz gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.zip |
Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db
* Fix lint
* Fix lint
* Fix test
* Fix lint
* Fix lint
* revert unnecessary change
* Fix test
* Fix wrong replace string
* Use *Context
* Correct committer spelling and fix wrong replaced words
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/update.go')
-rw-r--r-- | models/update.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/models/update.go b/models/update.go index 421c44bb40..0fb73ac891 100644 --- a/models/update.go +++ b/models/update.go @@ -7,14 +7,16 @@ package models import ( "fmt" "strings" + + "code.gitea.io/gitea/models/db" ) // PushUpdateDeleteTagsContext updates a number of delete tags with context -func PushUpdateDeleteTagsContext(ctx DBContext, repo *Repository, tags []string) error { - return pushUpdateDeleteTags(ctx.e, repo, tags) +func PushUpdateDeleteTagsContext(ctx *db.Context, repo *Repository, tags []string) error { + return pushUpdateDeleteTags(ctx.Engine(), repo, tags) } -func pushUpdateDeleteTags(e Engine, repo *Repository, tags []string) error { +func pushUpdateDeleteTags(e db.Engine, repo *Repository, tags []string) error { if len(tags) == 0 { return nil } @@ -53,14 +55,14 @@ func PushUpdateDeleteTag(repo *Repository, tagName string) error { return fmt.Errorf("GetRelease: %v", err) } if rel.IsTag { - if _, err = x.ID(rel.ID).Delete(new(Release)); err != nil { + if _, err = db.DefaultContext().Engine().ID(rel.ID).Delete(new(Release)); err != nil { return fmt.Errorf("Delete: %v", err) } } else { rel.IsDraft = true rel.NumCommits = 0 rel.Sha1 = "" - if _, err = x.ID(rel.ID).AllCols().Update(rel); err != nil { + if _, err = db.DefaultContext().Engine().ID(rel.ID).AllCols().Update(rel); err != nil { return fmt.Errorf("Update: %v", err) } } @@ -77,7 +79,7 @@ func SaveOrUpdateTag(repo *Repository, newRel *Release) error { if rel == nil { rel = newRel - if _, err = x.Insert(rel); err != nil { + if _, err = db.DefaultContext().Engine().Insert(rel); err != nil { return fmt.Errorf("InsertOne: %v", err) } } else { @@ -88,7 +90,7 @@ func SaveOrUpdateTag(repo *Repository, newRel *Release) error { if rel.IsTag && newRel.PublisherID > 0 { rel.PublisherID = newRel.PublisherID } - if _, err = x.ID(rel.ID).AllCols().Update(rel); err != nil { + if _, err = db.DefaultContext().Engine().ID(rel.ID).AllCols().Update(rel); err != nil { return fmt.Errorf("Update: %v", err) } } |