summaryrefslogtreecommitdiffstats
path: root/modules/repository
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-01-18 21:00:50 +0100
committerGitHub <noreply@github.com>2021-01-18 21:00:50 +0100
commit2686e6bbbe0e2cbb58292732b740a6944ce09c8a (patch)
treebd7aa1b2cad2184676b7d31ab018b41c6a971559 /modules/repository
parent127907c5e66d671b139a8d2bd8912911c7e58347 (diff)
downloadgitea-2686e6bbbe0e2cbb58292732b740a6944ce09c8a.tar.gz
gitea-2686e6bbbe0e2cbb58292732b740a6944ce09c8a.zip
Check if label template exist first (#14384)
* add check * refactor * rollback repo on error after session closed
Diffstat (limited to 'modules/repository')
-rw-r--r--modules/repository/create.go29
1 files changed, 21 insertions, 8 deletions
diff --git a/modules/repository/create.go b/modules/repository/create.go
index 1f7145ee2a..5eac03836e 100644
--- a/modules/repository/create.go
+++ b/modules/repository/create.go
@@ -27,6 +27,13 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
opts.DefaultBranch = setting.Repository.DefaultBranch
}
+ // Check if label template exist
+ if len(opts.IssueLabels) > 0 {
+ if _, err := models.GetLabelTemplateFile(opts.IssueLabels); err != nil {
+ return nil, err
+ }
+ }
+
repo := &models.Repository{
OwnerID: u.ID,
Owner: u,
@@ -45,6 +52,8 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
TrustModel: opts.TrustModel,
}
+ var rollbackRepo *models.Repository
+
if err := models.WithTx(func(ctx models.DBContext) error {
if err := models.CreateRepository(ctx, doer, u, repo, false); err != nil {
return err
@@ -76,7 +85,7 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
}
}
- if err := initRepository(ctx, repoPath, doer, repo, opts); err != nil {
+ if err = initRepository(ctx, repoPath, doer, repo, opts); err != nil {
if err2 := util.RemoveAll(repoPath); err2 != nil {
log.Error("initRepository: %v", err)
return fmt.Errorf(
@@ -87,10 +96,9 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
// Initialize Issue Labels if selected
if len(opts.IssueLabels) > 0 {
- if err := models.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
- if errDelete := models.DeleteRepository(doer, u.ID, repo.ID); errDelete != nil {
- log.Error("Rollback deleteRepository: %v", errDelete)
- }
+ if err = models.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
+ rollbackRepo = repo
+ rollbackRepo.OwnerID = u.ID
return fmt.Errorf("InitializeLabels: %v", err)
}
}
@@ -99,13 +107,18 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
SetDescription(fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath)).
RunInDir(repoPath); err != nil {
log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
- if errDelete := models.DeleteRepository(doer, u.ID, repo.ID); errDelete != nil {
- log.Error("Rollback deleteRepository: %v", errDelete)
- }
+ rollbackRepo = repo
+ rollbackRepo.OwnerID = u.ID
return fmt.Errorf("CreateRepository(git update-server-info): %v", err)
}
return nil
}); err != nil {
+ if rollbackRepo != nil {
+ if errDelete := models.DeleteRepository(doer, rollbackRepo.OwnerID, rollbackRepo.ID); errDelete != nil {
+ log.Error("Rollback deleteRepository: %v", errDelete)
+ }
+ }
+
return nil, err
}