|
|
|
@ -29,6 +29,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, |
|
|
|
@ -47,6 +54,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 |
|
|
|
@ -85,9 +94,8 @@ 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) |
|
|
|
|
} |
|
|
|
|
rollbackRepo = repo |
|
|
|
|
rollbackRepo.OwnerID = u.ID |
|
|
|
|
return fmt.Errorf("InitializeLabels: %v", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -96,13 +104,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 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|