summaryrefslogtreecommitdiffstats
path: root/models/update.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-01-10 17:34:21 +0800
committerGitHub <noreply@github.com>2020-01-10 17:34:21 +0800
commit99d869fa63e07780f1a17d1a9599187b9b689d9b (patch)
treeecadeba077cf0ae58d0a21f232d280fec60c779a /models/update.go
parent384c2b342ec01fadb520572666127cb5564e1050 (diff)
downloadgitea-99d869fa63e07780f1a17d1a9599187b9b689d9b.tar.gz
gitea-99d869fa63e07780f1a17d1a9599187b9b689d9b.zip
Move push commits from models to modules/repository (#9370)
* Move push commits from models to modules/repository * fix test * fix test * fix test * fix test * fix test Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/update.go')
-rw-r--r--models/update.go98
1 files changed, 10 insertions, 88 deletions
diff --git a/models/update.go b/models/update.go
index 212f22cfc1..17ee9ad5fa 100644
--- a/models/update.go
+++ b/models/update.go
@@ -5,7 +5,6 @@
package models
import (
- "container/list"
"fmt"
"strings"
"time"
@@ -27,33 +26,6 @@ const (
EnvIsInternal = "GITEA_INTERNAL_PUSH"
)
-// CommitToPushCommit transforms a git.Commit to PushCommit type.
-func CommitToPushCommit(commit *git.Commit) *PushCommit {
- return &PushCommit{
- Sha1: commit.ID.String(),
- Message: commit.Message(),
- AuthorEmail: commit.Author.Email,
- AuthorName: commit.Author.Name,
- CommitterEmail: commit.Committer.Email,
- CommitterName: commit.Committer.Name,
- Timestamp: commit.Author.When,
- }
-}
-
-// ListToPushCommits transforms a list.List to PushCommits type.
-func ListToPushCommits(l *list.List) *PushCommits {
- var commits []*PushCommit
- var actEmail string
- for e := l.Front(); e != nil; e = e.Next() {
- commit := e.Value.(*git.Commit)
- if actEmail == "" {
- actEmail = commit.Committer.Email
- }
- commits = append(commits, CommitToPushCommit(commit))
- }
- return &PushCommits{l.Len(), commits, "", make(map[string]string), make(map[string]*User)}
-}
-
// PushUpdateAddDeleteTags updates a number of added and delete tags
func PushUpdateAddDeleteTags(repo *Repository, gitRepo *git.Repository, addTags, delTags []string) error {
sess := x.NewSession()
@@ -258,75 +230,25 @@ func pushUpdateAddTags(e Engine, repo *Repository, gitRepo *git.Repository, tags
return nil
}
-// PushUpdateAddTag must be called for any push actions to add tag
-func PushUpdateAddTag(repo *Repository, gitRepo *git.Repository, tagName string) error {
- rel, err := GetRelease(repo.ID, tagName)
+// SaveOrUpdateTag must be called for any push actions to add tag
+func SaveOrUpdateTag(repo *Repository, newRel *Release) error {
+ rel, err := GetRelease(repo.ID, newRel.TagName)
if err != nil && !IsErrReleaseNotExist(err) {
return fmt.Errorf("GetRelease: %v", err)
}
- tag, err := gitRepo.GetTag(tagName)
- if err != nil {
- return fmt.Errorf("GetTag: %v", err)
- }
- commit, err := tag.Commit()
- if err != nil {
- return fmt.Errorf("Commit: %v", err)
- }
-
- sig := tag.Tagger
- if sig == nil {
- sig = commit.Author
- }
- if sig == nil {
- sig = commit.Committer
- }
-
- var author *User
- var createdAt = time.Unix(1, 0)
-
- if sig != nil {
- author, err = GetUserByEmail(sig.Email)
- if err != nil && !IsErrUserNotExist(err) {
- return fmt.Errorf("GetUserByEmail: %v", err)
- }
- createdAt = sig.When
- }
-
- commitsCount, err := commit.CommitsCount()
- if err != nil {
- return fmt.Errorf("CommitsCount: %v", err)
- }
-
if rel == nil {
- rel = &Release{
- RepoID: repo.ID,
- Title: "",
- TagName: tagName,
- LowerTagName: strings.ToLower(tagName),
- Target: "",
- Sha1: commit.ID.String(),
- NumCommits: commitsCount,
- Note: "",
- IsDraft: false,
- IsPrerelease: false,
- IsTag: true,
- CreatedUnix: timeutil.TimeStamp(createdAt.Unix()),
- }
- if author != nil {
- rel.PublisherID = author.ID
- }
-
- if _, err = x.InsertOne(rel); err != nil {
+ rel = newRel
+ if _, err = x.Insert(rel); err != nil {
return fmt.Errorf("InsertOne: %v", err)
}
} else {
- rel.Sha1 = commit.ID.String()
- rel.CreatedUnix = timeutil.TimeStamp(createdAt.Unix())
- rel.NumCommits = commitsCount
+ rel.Sha1 = newRel.Sha1
+ rel.CreatedUnix = newRel.CreatedUnix
+ rel.NumCommits = newRel.NumCommits
rel.IsDraft = false
- if rel.IsTag && author != nil {
- rel.PublisherID = author.ID
+ if rel.IsTag && newRel.PublisherID > 0 {
+ rel.PublisherID = newRel.PublisherID
}
if _, err = x.ID(rel.ID).AllCols().Update(rel); err != nil {
return fmt.Errorf("Update: %v", err)