Skip to content
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

Move create/fork repository from models to modules/repository #9489

Merged
merged 9 commits into from
Jan 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix conflicts
  • Loading branch information
lunny committed Jan 12, 2020
commit 21eefa84287598521781189091849758daf0007a
30 changes: 1 addition & 29 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,32 +250,9 @@ func (repo *Repository) MustOwner() *User {
return repo.mustOwner(x)
}

<<<<<<< HEAD
// FullName returns the repository full name
func (repo *Repository) FullName() string {
return repo.OwnerName + "/" + repo.Name
=======
// MustOwnerName always returns valid owner name to avoid
// conceptually impossible error handling.
// It returns "error" and logs error details when error
// occurs.
func (repo *Repository) MustOwnerName() string {
return repo.mustOwnerName(x)
}

// MustOwnerNameCtx is similar MustOwnerName but with a database context
func (repo *Repository) MustOwnerNameCtx(ctx DBContext) string {
return repo.mustOwnerName(ctx.e)
}

// FullName returns the repository full name
func (repo *Repository) FullName() string {
return repo.fullName(x)
}

func (repo *Repository) fullName(e Engine) string {
return repo.mustOwnerName(e) + "/" + repo.Name
>>>>>>> Fix DBContext
}

// HTMLURL returns the repository HTML URL
Expand Down Expand Up @@ -714,12 +691,7 @@ func (repo *Repository) RelLink() string {

// Link returns the repository link
func (repo *Repository) Link() string {
return repo.LinkCtx(DefaultDBContext())
}

// LinkCtx is similar with Link but with database context
func (repo *Repository) LinkCtx(ctx DBContext) string {
return setting.AppSubURL + "/" + repo.fullName(ctx.e)
return setting.AppSubURL + "/" + repo.FullName()
}

// ComposeCompareURL returns the repository comparison URL
Expand Down
12 changes: 6 additions & 6 deletions modules/repository/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"code.gitea.io/gitea/modules/log"
)

func generateExpansion(ctx models.DBContext, src string, templateRepo, generateRepo *models.Repository) string {
func generateExpansion(src string, templateRepo, generateRepo *models.Repository) string {
return os.Expand(src, func(key string) string {
switch key {
case "REPO_NAME":
Expand All @@ -34,9 +34,9 @@ func generateExpansion(ctx models.DBContext, src string, templateRepo, generateR
case "TEMPLATE_OWNER":
return templateRepo.OwnerName
case "REPO_LINK":
return generateRepo.LinkCtx(ctx)
return generateRepo.Link()
case "TEMPLATE_LINK":
return templateRepo.LinkCtx(ctx)
return templateRepo.Link()
case "REPO_HTTPS_URL":
return generateRepo.CloneLink().HTTPS
case "TEMPLATE_HTTPS_URL":
Expand Down Expand Up @@ -72,7 +72,7 @@ func checkGiteaTemplate(tmpDir string) (*models.GiteaTemplate, error) {
return gt, nil
}

func generateRepoCommit(ctx models.DBContext, repo, templateRepo, generateRepo *models.Repository, tmpDir string) error {
func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmpDir string) error {
commitTimeStr := time.Now().Format(time.RFC3339)
authorSig := repo.Owner.NewGitSig()

Expand Down Expand Up @@ -129,7 +129,7 @@ func generateRepoCommit(ctx models.DBContext, repo, templateRepo, generateRepo *
}

if err := ioutil.WriteFile(path,
[]byte(generateExpansion(ctx, string(content), templateRepo, generateRepo)),
[]byte(generateExpansion(string(content), templateRepo, generateRepo)),
0644); err != nil {
return err
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func generateGitContent(ctx models.DBContext, repo, templateRepo, generateRepo *
}
}()

if err = generateRepoCommit(ctx, repo, templateRepo, generateRepo, tmpDir); err != nil {
if err = generateRepoCommit(repo, templateRepo, generateRepo, tmpDir); err != nil {
return fmt.Errorf("generateRepoCommit: %v", err)
}

Expand Down