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
Next Next commit
Fix DBContext
  • Loading branch information
lunny committed Jan 12, 2020
commit e344dc9d32563a25547812b82099f6caad470ad7
30 changes: 29 additions & 1 deletion models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,32 @@ 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 similiar 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 @@ -691,7 +714,12 @@ func (repo *Repository) RelLink() string {

// Link returns the repository link
func (repo *Repository) Link() string {
return setting.AppSubURL + "/" + repo.FullName()
return repo.LinkCtx(DefaultDBContext())
}

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

// ComposeCompareURL returns the repository comparison URL
Expand Down
8 changes: 4 additions & 4 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(src string, templateRepo, generateRepo *models.Repository) string {
func generateExpansion(ctx models.DBContext, 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(src string, templateRepo, generateRepo *models.Repository
case "TEMPLATE_OWNER":
return templateRepo.OwnerName
case "REPO_LINK":
return generateRepo.Link()
return generateRepo.LinkCtx(ctx)
case "TEMPLATE_LINK":
return templateRepo.Link()
return templateRepo.LinkCtx(ctx)
case "REPO_HTTPS_URL":
return generateRepo.CloneLink().HTTPS
case "TEMPLATE_HTTPS_URL":
Expand Down Expand Up @@ -129,7 +129,7 @@ func generateRepoCommit(ctx models.DBContext, repo, templateRepo, generateRepo *
}

if err := ioutil.WriteFile(path,
[]byte(generateExpansion(string(content), templateRepo, generateRepo)),
[]byte(generateExpansion(ctx, string(content), templateRepo, generateRepo)),
0644); err != nil {
return err
}
Expand Down