mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Page: Commits and fix #249
This commit is contained in:
		@@ -5,6 +5,7 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"container/list"
 | 
			
		||||
	"crypto/sha256"
 | 
			
		||||
	"encoding/hex"
 | 
			
		||||
	"errors"
 | 
			
		||||
@@ -513,6 +514,34 @@ func GetUserIdsByNames(names []string) []int64 {
 | 
			
		||||
	return ids
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UserCommit represtns a commit with validation of user.
 | 
			
		||||
type UserCommit struct {
 | 
			
		||||
	UserName string
 | 
			
		||||
	*git.Commit
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ValidCommitsWithEmails checks if authors' e-mails of commits are correcponding to users.
 | 
			
		||||
func ValidCommitsWithEmails(oldCommits *list.List) *list.List {
 | 
			
		||||
	newCommits := list.New()
 | 
			
		||||
	e := oldCommits.Front()
 | 
			
		||||
	for e != nil {
 | 
			
		||||
		c := e.Value.(*git.Commit)
 | 
			
		||||
 | 
			
		||||
		uname := ""
 | 
			
		||||
		u, err := GetUserByEmail(c.Author.Email)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			uname = u.Name
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		newCommits.PushBack(UserCommit{
 | 
			
		||||
			UserName: uname,
 | 
			
		||||
			Commit:   c,
 | 
			
		||||
		})
 | 
			
		||||
		e = e.Next()
 | 
			
		||||
	}
 | 
			
		||||
	return newCommits
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetUserByEmail returns the user object by given e-mail if exists.
 | 
			
		||||
func GetUserByEmail(email string) (*User, error) {
 | 
			
		||||
	if len(email) == 0 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user