Some improvements for v156 (#13497)

This commit is contained in:
Lunny Xiao 2020-11-10 19:44:45 +08:00 committed by GitHub
parent beab1dd337
commit 542edc22c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -55,6 +55,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
var ( var (
repo *Repository repo *Repository
gitRepo *git.Repository gitRepo *git.Repository
user *User
) )
defer func() { defer func() {
if gitRepo != nil { if gitRepo != nil {
@ -69,7 +70,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
} }
if err := sess.Limit(batchSize, start). if err := sess.Limit(batchSize, start).
Where("publisher_id = 0"). Where("publisher_id = 0 OR publisher_id is null").
Asc("repo_id", "id").Where("is_tag=?", true). Asc("repo_id", "id").Where("is_tag=?", true).
Find(&releases); err != nil { Find(&releases); err != nil {
return err return err
@ -117,17 +118,21 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
return fmt.Errorf("GetTagCommit: %v", err) return fmt.Errorf("GetTagCommit: %v", err)
} }
u := new(User) if user == nil || !strings.EqualFold(user.Email, commit.Author.Email) {
exists, err := sess.Where("email=?", commit.Author.Email).Get(u) user = new(User)
_, err = sess.Where("email=?", commit.Author.Email).Get(user)
if err != nil { if err != nil {
return err return err
} }
if !exists { user.Email = commit.Author.Email
}
if user.ID <= 0 {
continue continue
} }
release.PublisherID = u.ID release.PublisherID = user.ID
if _, err := sess.ID(release.ID).Cols("publisher_id").Update(release); err != nil { if _, err := sess.ID(release.ID).Cols("publisher_id").Update(release); err != nil {
return err return err
} }