]> source.dussan.org Git - gitea.git/commitdiff
Add checks for commits with missing author and time (#2771)
authorLauris BH <lauris@nix.lv>
Thu, 26 Oct 2017 07:45:14 +0000 (10:45 +0300)
committerLunny Xiao <xiaolunwen@gmail.com>
Thu, 26 Oct 2017 07:45:14 +0000 (15:45 +0800)
* Add checks for commits with missing author and time

* Fix validate commits with emails if it has no Author

models/update.go
models/user.go
templates/repo/view_list.tmpl

index 82369bf6367602951fe93fbb7136c6bca4db44cf..f3bd6cce13fe06353ca051767b8f68bdac9f0472 100644 (file)
@@ -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 {
index 337c39efe49e0d92d1204fd549703d4e75ffdc48..4dd2ad8d897ea2127d32b45b6466ef75f88afb44 100644 (file)
@@ -1193,6 +1193,9 @@ type UserCommit struct {
 
 // ValidateCommitWithEmail check if author's e-mail of commit is corresponding to a user.
 func ValidateCommitWithEmail(c *git.Commit) *User {
+       if c.Author == nil {
+               return nil
+       }
        u, err := GetUserByEmail(c.Author.Email)
        if err != nil {
                return nil
@@ -1211,11 +1214,15 @@ func ValidateCommitsWithEmails(oldCommits *list.List) *list.List {
        for e != nil {
                c := e.Value.(*git.Commit)
 
-               if v, ok := emails[c.Author.Email]; !ok {
-                       u, _ = GetUserByEmail(c.Author.Email)
-                       emails[c.Author.Email] = u
+               if c.Author != nil {
+                       if v, ok := emails[c.Author.Email]; !ok {
+                               u, _ = GetUserByEmail(c.Author.Email)
+                               emails[c.Author.Email] = u
+                       } else {
+                               u = v
+                       }
                } else {
-                       u = v
+                       u = nil
                }
 
                newCommits.PushBack(UserCommit{
index 67164753e9fa57891069798903abd8025c3e8523..7be2183fa80db8f80548394050fad65cf187268b 100644 (file)
@@ -4,14 +4,16 @@
                        <th class="four wide">
                                {{if .LatestCommitUser}}
                                        <img class="ui avatar image img-12" src="{{.LatestCommitUser.RelAvatarLink}}" />
-                                 {{if .LatestCommitUser.FullName}}
-                                         <a href="{{AppSubUrl}}/{{.LatestCommitUser.Name}}"><strong>{{.LatestCommitUser.FullName}}</strong></a>
-                                 {{else}}
-                                   <a href="{{AppSubUrl}}/{{.LatestCommitUser.Name}}"><strong>{{.LatestCommit.Author.Name}}</strong></a>
-                                 {{end}}
+                                       {{if .LatestCommitUser.FullName}}
+                                               <a href="{{AppSubUrl}}/{{.LatestCommitUser.Name}}"><strong>{{.LatestCommitUser.FullName}}</strong></a>
+                                       {{else}}
+                                               <a href="{{AppSubUrl}}/{{.LatestCommitUser.Name}}"><strong>{{if .LatestCommit.Author}}{{.LatestCommit.Author.Name}}{{else}}{{.LatestCommitUser.Name}}{{end}}</strong></a>
+                                       {{end}}
                                {{else}}
-                                       <img class="ui avatar image img-12" src="{{AvatarLink .LatestCommit.Author.Email}}" />
-                                       <strong>{{.LatestCommit.Author.Name}}</strong>
+                                       {{if .LatestCommit.Author}}
+                                               <img class="ui avatar image img-12" src="{{AvatarLink .LatestCommit.Author.Email}}" />
+                                               <strong>{{.LatestCommit.Author.Name}}</strong>
+                                       {{end}}
                                {{end}}
                                <a rel="nofollow" class="ui sha label {{if .LatestCommit.Signature}} isSigned {{if .LatestCommitVerification.Verified }} isVerified {{end}}{{end}}" href="{{.RepoLink}}/commit/{{.LatestCommit.ID}}">
                                                {{ShortSha .LatestCommit.ID.String}}
@@ -30,7 +32,7 @@
                        </th>
                        <th class="nine wide">
                        </th>
-                       <th class="three wide text grey right age">{{TimeSince .LatestCommit.Author.When $.Lang}}</th>
+                       <th class="three wide text grey right age">{{if .LatestCommit.Author}}{{TimeSince .LatestCommit.Author.When $.Lang}}{{end}}</th>
                </tr>
        </thead>
        <tbody>