Skip to content

Fix #13255 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions models/migrations/v156.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"

"xorm.io/xorm"
Expand All @@ -35,9 +36,10 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
}

type Repository struct {
ID int64
OwnerID int64
Name string
ID int64
OwnerID int64
OwnerName string
Name string
}

type User struct {
Expand All @@ -50,13 +52,10 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
sess := x.NewSession()
defer sess.Close()



var (
gitRepoCache = make(map[int64]*git.Repository)
gitRepo *git.Repository
repoCache = make(map[int64]*Repository)
userCache = make(map[int64]*User)
ok bool
err error
)
Expand Down Expand Up @@ -90,26 +89,32 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
if err != nil {
return err
} else if !has {
return fmt.Errorf("Repository %d is not exist", release.RepoID)
log.Warn("Release[%d] is orphaned and refers to non-existing repository %d", release.ID, release.RepoID)
log.Warn("This release should be deleted")
continue
}

repoCache[release.RepoID] = repo
}
if repo.OwnerName == "" {
// v120.go migration may not have been run correctly - we'll just replicate it here
// because this appears to be a common-ish problem.
if _, err := sess.Exec("UPDATE repository SET owner_name = (SELECT name FROM `user` WHERE `user`.id = repository.owner_id)"); err != nil {
return err
}

user, ok := userCache[repo.OwnerID]
if !ok {
user = new(User)
has, err := sess.ID(repo.OwnerID).Get(user)
if err != nil {
return err
} else if !has {
return fmt.Errorf("User %d is not exist", repo.OwnerID)
if _, err := sess.ID(release.RepoID).Get(repo); err != nil {
return err
}
}

userCache[repo.OwnerID] = user
repoCache[release.RepoID] = repo
}

if repo.OwnerName == "" {
log.Warn("Release[%d] refers to Repo[%d] Name: %s with OwnerID: %d but does not have OwnerName set", release.ID, release.RepoID, repo.Name, repo.OwnerID)
continue
}

gitRepo, err = git.OpenRepository(repoPath(user.Name, repo.Name))
gitRepo, err = git.OpenRepository(repoPath(repo.OwnerName, repo.Name))
if err != nil {
return err
}
Expand Down