Fix wrong original git service type on a migrated repository (#9693)
This commit is contained in:
parent
3143bb10da
commit
7a3a90aca3
7 changed files with 76 additions and 44 deletions
|
@ -292,6 +292,8 @@ var migrations = []Migration{
|
||||||
NewMigration("Add block on rejected reviews branch protection", addBlockOnRejectedReviews),
|
NewMigration("Add block on rejected reviews branch protection", addBlockOnRejectedReviews),
|
||||||
// v118 -> v119
|
// v118 -> v119
|
||||||
NewMigration("Add commit id and stale to reviews", addReviewCommitAndStale),
|
NewMigration("Add commit id and stale to reviews", addReviewCommitAndStale),
|
||||||
|
// v119 -> v120
|
||||||
|
NewMigration("Fix migrated repositories' git service type", fixMigratedRepositoryServiceType),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate database to current version
|
// Migrate database to current version
|
||||||
|
|
16
models/migrations/v119.go
Normal file
16
models/migrations/v119.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/gitea/modules/structs"
|
||||||
|
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func fixMigratedRepositoryServiceType(x *xorm.Engine) error {
|
||||||
|
_, err := x.Exec("UPDATE repository SET original_service_type = ? WHERE original_url LIKE 'https://github.com/%'", structs.GithubService)
|
||||||
|
return err
|
||||||
|
}
|
|
@ -1071,17 +1071,18 @@ func initRepoCommit(tmpPath string, repo *Repository, u *User) (err error) {
|
||||||
|
|
||||||
// CreateRepoOptions contains the create repository options
|
// CreateRepoOptions contains the create repository options
|
||||||
type CreateRepoOptions struct {
|
type CreateRepoOptions struct {
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
OriginalURL string
|
OriginalURL string
|
||||||
Gitignores string
|
GitServiceType structs.GitServiceType
|
||||||
IssueLabels string
|
Gitignores string
|
||||||
License string
|
IssueLabels string
|
||||||
Readme string
|
License string
|
||||||
IsPrivate bool
|
Readme string
|
||||||
IsMirror bool
|
IsPrivate bool
|
||||||
AutoInit bool
|
IsMirror bool
|
||||||
Status RepositoryStatus
|
AutoInit bool
|
||||||
|
Status RepositoryStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRepoInitFile(tp, name string) ([]byte, error) {
|
func getRepoInitFile(tp, name string) ([]byte, error) {
|
||||||
|
@ -1369,6 +1370,7 @@ func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err
|
||||||
LowerName: strings.ToLower(opts.Name),
|
LowerName: strings.ToLower(opts.Name),
|
||||||
Description: opts.Description,
|
Description: opts.Description,
|
||||||
OriginalURL: opts.OriginalURL,
|
OriginalURL: opts.OriginalURL,
|
||||||
|
OriginalServiceType: opts.GitServiceType,
|
||||||
IsPrivate: opts.IsPrivate,
|
IsPrivate: opts.IsPrivate,
|
||||||
IsFsckEnabled: !opts.IsMirror,
|
IsFsckEnabled: !opts.IsMirror,
|
||||||
CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch,
|
CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch,
|
||||||
|
|
|
@ -194,12 +194,13 @@ func CreateMigrateTask(doer, u *User, opts base.MigrateOptions) (*Task, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := CreateRepository(doer, u, CreateRepoOptions{
|
repo, err := CreateRepository(doer, u, CreateRepoOptions{
|
||||||
Name: opts.RepoName,
|
Name: opts.RepoName,
|
||||||
Description: opts.Description,
|
Description: opts.Description,
|
||||||
OriginalURL: opts.OriginalURL,
|
OriginalURL: opts.OriginalURL,
|
||||||
IsPrivate: opts.Private,
|
GitServiceType: opts.GitServiceType,
|
||||||
IsMirror: opts.Mirror,
|
IsPrivate: opts.Private,
|
||||||
Status: RepositoryBeingMigrated,
|
IsMirror: opts.Mirror,
|
||||||
|
Status: RepositoryBeingMigrated,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
task.EndTime = timeutil.TimeStampNow()
|
task.EndTime = timeutil.TimeStampNow()
|
||||||
|
|
|
@ -101,12 +101,13 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
|
||||||
var r *models.Repository
|
var r *models.Repository
|
||||||
if opts.MigrateToRepoID <= 0 {
|
if opts.MigrateToRepoID <= 0 {
|
||||||
r, err = models.CreateRepository(g.doer, owner, models.CreateRepoOptions{
|
r, err = models.CreateRepository(g.doer, owner, models.CreateRepoOptions{
|
||||||
Name: g.repoName,
|
Name: g.repoName,
|
||||||
Description: repo.Description,
|
Description: repo.Description,
|
||||||
OriginalURL: repo.OriginalURL,
|
OriginalURL: repo.OriginalURL,
|
||||||
IsPrivate: opts.Private,
|
GitServiceType: opts.GitServiceType,
|
||||||
IsMirror: opts.Mirror,
|
IsPrivate: opts.Private,
|
||||||
Status: models.RepositoryBeingMigrated,
|
IsMirror: opts.Mirror,
|
||||||
|
Status: models.RepositoryBeingMigrated,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
r, err = models.GetRepositoryByID(opts.MigrateToRepoID)
|
r, err = models.GetRepositoryByID(opts.MigrateToRepoID)
|
||||||
|
|
|
@ -485,12 +485,13 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := models.CreateRepository(ctx.User, ctxUser, models.CreateRepoOptions{
|
repo, err := models.CreateRepository(ctx.User, ctxUser, models.CreateRepoOptions{
|
||||||
Name: opts.RepoName,
|
Name: opts.RepoName,
|
||||||
Description: opts.Description,
|
Description: opts.Description,
|
||||||
OriginalURL: form.CloneAddr,
|
OriginalURL: form.CloneAddr,
|
||||||
IsPrivate: opts.Private,
|
GitServiceType: gitServiceType,
|
||||||
IsMirror: opts.Mirror,
|
IsPrivate: opts.Private,
|
||||||
Status: models.RepositoryBeingMigrated,
|
IsMirror: opts.Mirror,
|
||||||
|
Status: models.RepositoryBeingMigrated,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleMigrateError(ctx, ctxUser, remoteAddr, err)
|
handleMigrateError(ctx, ctxUser, remoteAddr, err)
|
||||||
|
|
|
@ -6,6 +6,7 @@ package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -18,6 +19,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/migrations"
|
"code.gitea.io/gitea/modules/migrations"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/task"
|
"code.gitea.io/gitea/modules/task"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
|
@ -330,22 +332,29 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var gitServiceType = structs.PlainGitService
|
||||||
|
u, err := url.Parse(form.CloneAddr)
|
||||||
|
if err == nil && strings.EqualFold(u.Host, "github.com") {
|
||||||
|
gitServiceType = structs.GithubService
|
||||||
|
}
|
||||||
|
|
||||||
var opts = migrations.MigrateOptions{
|
var opts = migrations.MigrateOptions{
|
||||||
OriginalURL: form.CloneAddr,
|
OriginalURL: form.CloneAddr,
|
||||||
CloneAddr: remoteAddr,
|
GitServiceType: gitServiceType,
|
||||||
RepoName: form.RepoName,
|
CloneAddr: remoteAddr,
|
||||||
Description: form.Description,
|
RepoName: form.RepoName,
|
||||||
Private: form.Private || setting.Repository.ForcePrivate,
|
Description: form.Description,
|
||||||
Mirror: form.Mirror,
|
Private: form.Private || setting.Repository.ForcePrivate,
|
||||||
AuthUsername: form.AuthUsername,
|
Mirror: form.Mirror,
|
||||||
AuthPassword: form.AuthPassword,
|
AuthUsername: form.AuthUsername,
|
||||||
Wiki: form.Wiki,
|
AuthPassword: form.AuthPassword,
|
||||||
Issues: form.Issues,
|
Wiki: form.Wiki,
|
||||||
Milestones: form.Milestones,
|
Issues: form.Issues,
|
||||||
Labels: form.Labels,
|
Milestones: form.Milestones,
|
||||||
Comments: true,
|
Labels: form.Labels,
|
||||||
PullRequests: form.PullRequests,
|
Comments: true,
|
||||||
Releases: form.Releases,
|
PullRequests: form.PullRequests,
|
||||||
|
Releases: form.Releases,
|
||||||
}
|
}
|
||||||
if opts.Mirror {
|
if opts.Mirror {
|
||||||
opts.Issues = false
|
opts.Issues = false
|
||||||
|
|
Loading…
Reference in a new issue