diff options
author | Lauris BH <lauris@nix.lv> | 2017-10-26 10:45:14 +0300 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-10-26 15:45:14 +0800 |
commit | 6a107e57f6ded230b9e9f6861ac2101a34f260b1 (patch) | |
tree | 5536ed9ec4b0a847f3a0caa8a906c19cc9f7c983 /models/update.go | |
parent | bc8411098979da5599d314e982da2985e0bb29c2 (diff) | |
download | gitea-6a107e57f6ded230b9e9f6861ac2101a34f260b1.tar.gz gitea-6a107e57f6ded230b9e9f6861ac2101a34f260b1.zip |
Add checks for commits with missing author and time (#2771)
* Add checks for commits with missing author and time
* Fix validate commits with emails if it has no Author
Diffstat (limited to 'models/update.go')
-rw-r--r-- | models/update.go | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/models/update.go b/models/update.go index 82369bf636..f3bd6cce13 100644 --- a/models/update.go +++ b/models/update.go @@ -9,6 +9,7 @@ import ( "fmt" "os/exec" "strings" + "time" "code.gitea.io/git" "code.gitea.io/gitea/modules/cache" @@ -119,11 +120,24 @@ func pushUpdateAddTag(repo *Repository, gitRepo *git.Repository, tagName string) if err != nil { return fmt.Errorf("Commit: %v", err) } - tagCreatedUnix := commit.Author.When.Unix() - author, err := GetUserByEmail(commit.Author.Email) - if err != nil && !IsErrUserNotExist(err) { - return fmt.Errorf("GetUserByEmail: %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() @@ -144,7 +158,8 @@ func pushUpdateAddTag(repo *Repository, gitRepo *git.Repository, tagName string) IsDraft: false, IsPrerelease: false, IsTag: true, - CreatedUnix: tagCreatedUnix, + Created: createdAt, + CreatedUnix: createdAt.Unix(), } if author != nil { rel.PublisherID = author.ID @@ -155,7 +170,8 @@ func pushUpdateAddTag(repo *Repository, gitRepo *git.Repository, tagName string) } } else { rel.Sha1 = commit.ID.String() - rel.CreatedUnix = tagCreatedUnix + rel.Created = createdAt + rel.CreatedUnix = createdAt.Unix() rel.NumCommits = commitsCount rel.IsDraft = false if rel.IsTag && author != nil { |