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
This commit is contained in:
parent
bc84110989
commit
6a107e57f6
3 changed files with 43 additions and 18 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/modules/cache"
|
"code.gitea.io/gitea/modules/cache"
|
||||||
|
@ -119,12 +120,25 @@ func pushUpdateAddTag(repo *Repository, gitRepo *git.Repository, tagName string)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Commit: %v", err)
|
return fmt.Errorf("Commit: %v", err)
|
||||||
}
|
}
|
||||||
tagCreatedUnix := commit.Author.When.Unix()
|
|
||||||
|
|
||||||
author, err := GetUserByEmail(commit.Author.Email)
|
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) {
|
if err != nil && !IsErrUserNotExist(err) {
|
||||||
return fmt.Errorf("GetUserByEmail: %v", err)
|
return fmt.Errorf("GetUserByEmail: %v", err)
|
||||||
}
|
}
|
||||||
|
createdAt = sig.When
|
||||||
|
}
|
||||||
|
|
||||||
commitsCount, err := commit.CommitsCount()
|
commitsCount, err := commit.CommitsCount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -144,7 +158,8 @@ func pushUpdateAddTag(repo *Repository, gitRepo *git.Repository, tagName string)
|
||||||
IsDraft: false,
|
IsDraft: false,
|
||||||
IsPrerelease: false,
|
IsPrerelease: false,
|
||||||
IsTag: true,
|
IsTag: true,
|
||||||
CreatedUnix: tagCreatedUnix,
|
Created: createdAt,
|
||||||
|
CreatedUnix: createdAt.Unix(),
|
||||||
}
|
}
|
||||||
if author != nil {
|
if author != nil {
|
||||||
rel.PublisherID = author.ID
|
rel.PublisherID = author.ID
|
||||||
|
@ -155,7 +170,8 @@ func pushUpdateAddTag(repo *Repository, gitRepo *git.Repository, tagName string)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rel.Sha1 = commit.ID.String()
|
rel.Sha1 = commit.ID.String()
|
||||||
rel.CreatedUnix = tagCreatedUnix
|
rel.Created = createdAt
|
||||||
|
rel.CreatedUnix = createdAt.Unix()
|
||||||
rel.NumCommits = commitsCount
|
rel.NumCommits = commitsCount
|
||||||
rel.IsDraft = false
|
rel.IsDraft = false
|
||||||
if rel.IsTag && author != nil {
|
if rel.IsTag && author != nil {
|
||||||
|
|
|
@ -1193,6 +1193,9 @@ type UserCommit struct {
|
||||||
|
|
||||||
// ValidateCommitWithEmail check if author's e-mail of commit is corresponding to a user.
|
// ValidateCommitWithEmail check if author's e-mail of commit is corresponding to a user.
|
||||||
func ValidateCommitWithEmail(c *git.Commit) *User {
|
func ValidateCommitWithEmail(c *git.Commit) *User {
|
||||||
|
if c.Author == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
u, err := GetUserByEmail(c.Author.Email)
|
u, err := GetUserByEmail(c.Author.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -1211,12 +1214,16 @@ func ValidateCommitsWithEmails(oldCommits *list.List) *list.List {
|
||||||
for e != nil {
|
for e != nil {
|
||||||
c := e.Value.(*git.Commit)
|
c := e.Value.(*git.Commit)
|
||||||
|
|
||||||
|
if c.Author != nil {
|
||||||
if v, ok := emails[c.Author.Email]; !ok {
|
if v, ok := emails[c.Author.Email]; !ok {
|
||||||
u, _ = GetUserByEmail(c.Author.Email)
|
u, _ = GetUserByEmail(c.Author.Email)
|
||||||
emails[c.Author.Email] = u
|
emails[c.Author.Email] = u
|
||||||
} else {
|
} else {
|
||||||
u = v
|
u = v
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
u = nil
|
||||||
|
}
|
||||||
|
|
||||||
newCommits.PushBack(UserCommit{
|
newCommits.PushBack(UserCommit{
|
||||||
User: u,
|
User: u,
|
||||||
|
|
|
@ -7,12 +7,14 @@
|
||||||
{{if .LatestCommitUser.FullName}}
|
{{if .LatestCommitUser.FullName}}
|
||||||
<a href="{{AppSubUrl}}/{{.LatestCommitUser.Name}}"><strong>{{.LatestCommitUser.FullName}}</strong></a>
|
<a href="{{AppSubUrl}}/{{.LatestCommitUser.Name}}"><strong>{{.LatestCommitUser.FullName}}</strong></a>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a href="{{AppSubUrl}}/{{.LatestCommitUser.Name}}"><strong>{{.LatestCommit.Author.Name}}</strong></a>
|
<a href="{{AppSubUrl}}/{{.LatestCommitUser.Name}}"><strong>{{if .LatestCommit.Author}}{{.LatestCommit.Author.Name}}{{else}}{{.LatestCommitUser.Name}}{{end}}</strong></a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{else}}
|
{{else}}
|
||||||
|
{{if .LatestCommit.Author}}
|
||||||
<img class="ui avatar image img-12" src="{{AvatarLink .LatestCommit.Author.Email}}" />
|
<img class="ui avatar image img-12" src="{{AvatarLink .LatestCommit.Author.Email}}" />
|
||||||
<strong>{{.LatestCommit.Author.Name}}</strong>
|
<strong>{{.LatestCommit.Author.Name}}</strong>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{end}}
|
||||||
<a rel="nofollow" class="ui sha label {{if .LatestCommit.Signature}} isSigned {{if .LatestCommitVerification.Verified }} isVerified {{end}}{{end}}" href="{{.RepoLink}}/commit/{{.LatestCommit.ID}}">
|
<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}}
|
{{ShortSha .LatestCommit.ID.String}}
|
||||||
{{if .LatestCommit.Signature}}
|
{{if .LatestCommit.Signature}}
|
||||||
|
@ -30,7 +32,7 @@
|
||||||
</th>
|
</th>
|
||||||
<th class="nine wide">
|
<th class="nine wide">
|
||||||
</th>
|
</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>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
Loading…
Reference in a new issue