Skip to content

Commit

Permalink
Some improvements for v156 (#13497)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Nov 10, 2020
1 parent beab1dd commit 542edc2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions models/migrations/v156.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
var (
repo *Repository
gitRepo *git.Repository
user *User
)
defer func() {
if gitRepo != nil {
Expand All @@ -69,7 +70,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
}

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).
Find(&releases); err != nil {
return err
Expand Down Expand Up @@ -117,17 +118,21 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
return fmt.Errorf("GetTagCommit: %v", err)
}

u := new(User)
exists, err := sess.Where("email=?", commit.Author.Email).Get(u)
if err != nil {
return err
if user == nil || !strings.EqualFold(user.Email, commit.Author.Email) {
user = new(User)
_, err = sess.Where("email=?", commit.Author.Email).Get(user)
if err != nil {
return err
}

user.Email = commit.Author.Email
}

if !exists {
if user.ID <= 0 {
continue
}

release.PublisherID = u.ID
release.PublisherID = user.ID
if _, err := sess.ID(release.ID).Cols("publisher_id").Update(release); err != nil {
return err
}
Expand Down

0 comments on commit 542edc2

Please sign in to comment.