mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.3 KiB
90 lines
2.3 KiB
5 years ago
|
// Copyright 2019 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 repository
|
||
|
|
||
|
import (
|
||
3 years ago
|
"context"
|
||
|
|
||
5 years ago
|
"code.gitea.io/gitea/models"
|
||
3 years ago
|
"code.gitea.io/gitea/models/db"
|
||
3 years ago
|
repo_model "code.gitea.io/gitea/models/repo"
|
||
3 years ago
|
user_model "code.gitea.io/gitea/models/user"
|
||
5 years ago
|
"code.gitea.io/gitea/modules/log"
|
||
|
"code.gitea.io/gitea/modules/notification"
|
||
5 years ago
|
repo_module "code.gitea.io/gitea/modules/repository"
|
||
5 years ago
|
)
|
||
|
|
||
|
// GenerateRepository generates a repository from a template
|
||
3 years ago
|
func GenerateRepository(doer, owner *user_model.User, templateRepo *repo_model.Repository, opts models.GenerateRepoOptions) (_ *repo_model.Repository, err error) {
|
||
4 years ago
|
if !doer.IsAdmin && !owner.CanCreateRepo() {
|
||
3 years ago
|
return nil, repo_model.ErrReachLimitOfRepo{
|
||
4 years ago
|
Limit: owner.MaxRepoCreation,
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
var generateRepo *repo_model.Repository
|
||
3 years ago
|
if err = db.WithTx(func(ctx context.Context) error {
|
||
5 years ago
|
generateRepo, err = repo_module.GenerateRepository(ctx, doer, owner, templateRepo, opts)
|
||
5 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// Git Content
|
||
|
if opts.GitContent && !templateRepo.IsEmpty {
|
||
5 years ago
|
if err = repo_module.GenerateGitContent(ctx, templateRepo, generateRepo); err != nil {
|
||
5 years ago
|
return err
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Topics
|
||
|
if opts.Topics {
|
||
3 years ago
|
if err = repo_model.GenerateTopics(ctx, templateRepo, generateRepo); err != nil {
|
||
5 years ago
|
return err
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Git Hooks
|
||
|
if opts.GitHooks {
|
||
3 years ago
|
if err = GenerateGitHooks(ctx, templateRepo, generateRepo); err != nil {
|
||
5 years ago
|
return err
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Webhooks
|
||
|
if opts.Webhooks {
|
||
|
if err = models.GenerateWebhooks(ctx, templateRepo, generateRepo); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
// Avatar
|
||
|
if opts.Avatar && len(templateRepo.Avatar) > 0 {
|
||
3 years ago
|
if err = generateAvatar(ctx, templateRepo, generateRepo); err != nil {
|
||
5 years ago
|
return err
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Issue Labels
|
||
|
if opts.IssueLabels {
|
||
|
if err = models.GenerateIssueLabels(ctx, templateRepo, generateRepo); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
return nil
|
||
|
}); err != nil {
|
||
4 years ago
|
if generateRepo != nil && generateRepo.ID > 0 {
|
||
5 years ago
|
if errDelete := models.DeleteRepository(doer, owner.ID, generateRepo.ID); errDelete != nil {
|
||
|
log.Error("Rollback deleteRepository: %v", errDelete)
|
||
|
}
|
||
|
}
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
notification.NotifyCreateRepository(doer, owner, generateRepo)
|
||
|
|
||
|
return generateRepo, nil
|
||
|
}
|