diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-12-12 23:48:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-12 23:48:20 +0800 |
commit | 572324049008ac803d3d7c17a7b3a81ef00386fc (patch) | |
tree | a9c3709643a23165d27aa67e76f10f26a89936d5 /models/update.go | |
parent | 0a7e8327a017c5dd43e552bbcd0d0f056bc1671b (diff) | |
download | gitea-572324049008ac803d3d7c17a7b3a81ef00386fc.tar.gz gitea-572324049008ac803d3d7c17a7b3a81ef00386fc.zip |
Some repository refactors (#17950)
* some repository refactors
* remove unnecessary code
* Fix test
* Remove unnecessary banner
Diffstat (limited to 'models/update.go')
-rw-r--r-- | models/update.go | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/models/update.go b/models/update.go deleted file mode 100644 index 14333ed985..0000000000 --- a/models/update.go +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package models - -import ( - "context" - "fmt" - "strings" - - "code.gitea.io/gitea/models/db" - repo_model "code.gitea.io/gitea/models/repo" -) - -// PushUpdateDeleteTagsContext updates a number of delete tags with context -func PushUpdateDeleteTagsContext(ctx context.Context, repo *repo_model.Repository, tags []string) error { - return pushUpdateDeleteTags(db.GetEngine(ctx), repo, tags) -} - -func pushUpdateDeleteTags(e db.Engine, repo *repo_model.Repository, tags []string) error { - if len(tags) == 0 { - return nil - } - lowerTags := make([]string, 0, len(tags)) - for _, tag := range tags { - lowerTags = append(lowerTags, strings.ToLower(tag)) - } - - if _, err := e. - Where("repo_id = ? AND is_tag = ?", repo.ID, true). - In("lower_tag_name", lowerTags). - Delete(new(Release)); err != nil { - return fmt.Errorf("Delete: %v", err) - } - - if _, err := e. - Where("repo_id = ? AND is_tag = ?", repo.ID, false). - In("lower_tag_name", lowerTags). - Cols("is_draft", "num_commits", "sha1"). - Update(&Release{ - IsDraft: true, - }); err != nil { - return fmt.Errorf("Update: %v", err) - } - - return nil -} - -// PushUpdateDeleteTag must be called for any push actions to delete tag -func PushUpdateDeleteTag(repo *repo_model.Repository, tagName string) error { - rel, err := GetRelease(repo.ID, tagName) - if err != nil { - if IsErrReleaseNotExist(err) { - return nil - } - return fmt.Errorf("GetRelease: %v", err) - } - if rel.IsTag { - if _, err = db.GetEngine(db.DefaultContext).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 = db.GetEngine(db.DefaultContext).ID(rel.ID).AllCols().Update(rel); err != nil { - return fmt.Errorf("Update: %v", err) - } - } - - return nil -} - -// SaveOrUpdateTag must be called for any push actions to add tag -func SaveOrUpdateTag(repo *repo_model.Repository, newRel *Release) error { - rel, err := GetRelease(repo.ID, newRel.TagName) - if err != nil && !IsErrReleaseNotExist(err) { - return fmt.Errorf("GetRelease: %v", err) - } - - if rel == nil { - rel = newRel - if _, err = db.GetEngine(db.DefaultContext).Insert(rel); err != nil { - return fmt.Errorf("InsertOne: %v", err) - } - } else { - rel.Sha1 = newRel.Sha1 - rel.CreatedUnix = newRel.CreatedUnix - rel.NumCommits = newRel.NumCommits - rel.IsDraft = false - if rel.IsTag && newRel.PublisherID > 0 { - rel.PublisherID = newRel.PublisherID - } - if _, err = db.GetEngine(db.DefaultContext).ID(rel.ID).AllCols().Update(rel); err != nil { - return fmt.Errorf("Update: %v", err) - } - } - return nil -} |